News for hackers. Stuff that matters.
Re:The secret life of NaN by baybal2 on Thursday April 05, 2018 @11:51AM (#16766007)
My first encounter with Javascript: Not a Number is a Number.

In my youth, I spent days wondering how in the world numbers in animation scripts are not "NaN" strings the moment something causes zero division, but are still numbers called NaN.

Re:The secret life of NaN by scrupulusalbion on Thursday April 05, 2018 @04:57PM (#16768724)
Can arithmetic be applyied to NaN a la i? (e.g. 5 + 2 * NaN = 5 + 2NaN)
Re:The secret life of NaN by mort96 on Thursday April 05, 2018 @06:29PM (#16769354)
NaN is sort of viral. Any math operator (afaik) returns NaN if any of the operands is NaN. That means `5 + (2 * NaN)` becomes `5 + NaN`, which just becomes `NaN`.

Still, `5 + 2 * NaN == 5 + 2 * NaN` would return false, because it becomes `NaN == NaN`, and NaN is not equal to NaN.

Re:The secret life of NaN by logicallee on Thursday April 05, 2018 @08:28PM (#16770032)
what about 0 * instead of 2 * ? On one hand by the viral property it would seem to also be unequal? On the other hand having zero NaN is something every equation already has :D it seems fair to silently remove a 0 * NaN term.
Re:The secret life of NaN by mturmon on Thursday April 05, 2018 @08:53PM (#16770109)
It's not fair to remove 0 * NaN.

NaN will come up when doing

  Inf - Inf
But clearly:

  0 * (Inf - Inf)
cannot be said to be zero.

NaN really is not a number.

Re:The secret life of NaN by hermitdev on Thursday April 05, 2018 @09:07PM (#16770170)
IIRC, but I don't have the IEEE spec in front of me, any operation, binary or unary, that has an operand of NaN shall have the result of NaN.
Re:The secret life of NaN by Retra on Thursday April 05, 2018 @08:45PM (#16770080)
"0 * NaN" makes as much sense as "0 * Blue". It's NaN because you're trying to do something that is fundamentally not multiplication.
Re:The secret life of NaN by logicallee on Friday April 06, 2018 @07:24AM (#16772380)
thanks - makes sense and is a clear explanation.