Skip to content

Comment on $400 bounty started for "simple" OSS node.js moduleparent

Comments

Both of you, typeof NaN == number is not a language flaw! It's part of the IEEE 754 floating point specification.

https://secure.wikimedia.org/wikipedia/en/wiki/IEEE_754

Look, a big "system language" like Java also defines NaN, +inf, -inf as values of double (see Field Summary).

http://download.oracle.com/javase/6/docs/api/java/lang/Doubl...

As in

double mathError = Double.NaN;

Any other standards conformant language supports NaN for floating point numerical values. I would even argue an absence of NaN should be perceived as a language flaw.

EDIT: I realize the above might not actually be sufficiently explanatory. "Not a number" is used to specify the class of numbers that cannot be represented in floating point notation. This includes the undefined like 0 / 0 and imaginary numbers (e.g. square root of a negative value). It can also be used for missing values in a large computation.

Any operator with a NaN results in a NaN. So 1 + NaN = NaN. Most NaNs are quiet, as in they do not throw an exception and allow the operation to continue. This allows large batch computations to continue without stopping the entire process for one bad record. Instead there will be a NaN for that record and the rest of the data will be processed correctly. You can see why this might be useful when dealing with large amounts of scientific data and hopefully why the IEEE would introduce such a feature.

Good to know. Thank you.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.