22 minutes ago · Tech · hide

I like floats. On modern CPUs, invalid floating-point calculations normally don’t trigger hardware exceptions. Instead, if the result can’t be represented by the data type, the operation will return a special value of +/- Infinity or NaN.Because NaN represents multiple numerically-incompatible solutions to an underlying equation, this special value is never equal to itself:> 0 * 1e350 == 0 * 1e350 falseIn contrast, because Infinity represents multiple numerically-incompatible solutions to an underlying equation, this special value is always equal to itself:> 1e350 == 1e350000 trueBecause it’s not a number, NaN taints the result of any arithmetic operation in which it shows up as an operand:> NaN * 0 NaNThe above is always true, except when it isn’t:> NaN ** 1e-350 1In C, Boolean expressions are numbers. Because NaN is not a number, it is always true:if (0/.0) puts(”It’s C.”);JavaScript inherits the syntax of Boolean expressions from C. Because of this, in JavaScript, NaN is always…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town