Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

To clarify, in Javascript 1/0 is Infinity, not NaN.


You are correct. But it really should be NaN, since 1/ε is positive infinity, whereas 1/-ε is negative infinity.

Oh well :)


JS just assumes the limit direction for you, so 1/0 is Infinity, but -1/0 is -Infinity. 0/0 at least is correctly NaN. (Edit: And I just verified against my memory, Matlab (or at least Octave) does the same thing. While Matlab might get characterized as being for the ivory tower, at least it's had a long history of being used for practical math applications within the tower. Edit2: And anyway this is the defined behavior for IEEE floats. Men of industry use industrial standards. :))


Moreover, 1/-0 is -Infinity. IEEE float has two zeros, positive and negative.


Nope, I'd disagree. Zero isn't an approximation of some epsilon, it's really just zero. It makes sense for the output sign to match the input sign.


What is the sign of 0?

It's 0.


Parent was talking about the sign of the numerator. But... zero in IEEE 754 representation has a meaningful sign bit. 1/-0 = -inf.


Or as IEEE 754 sees it (you can try this in your JavaScript REPL).

  >> 1 / 0
  Infinity
  >> 1 / -0
  -Infinity


e is nearly 0, -e is nearly -0.

So 1/0 is infinity, and 1/-0 is -infinity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: