Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  93] [ 6]  / answers: 1 / hits: 38241  / 11 Years ago, mon, september 16, 2013, 12:00:00

It seems to me that the code



console.log(1 / 0)


should return NaN, but instead it returns Infinity. However this code:



console.log(0 / 0)


does return NaN. Can someone help me to understand the reasoning for this functionality? Not only does it seem to be inconsistent, it also seems to be wrong, in the case of x / 0 where x !== 0


More From » math

 Answers
87

Because that's how floating-point is defined (more generally than just Javascript). See for example:





Crudely speaking, you could think of 1/0 as the limit of 1/x as x tends to zero (from the right). And 0/0 has no reasonable interpretation at all, hence NaN.


[#75660] Saturday, September 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yosefleod

Total Points: 113
Total Questions: 100
Total Answers: 115

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;