4 ms·
NaN is property of the floating point specification. https://en.wikipedia.org/wiki/NaN https://en.wikipedia.org/wiki/NaN The purpose of silent propagation is
by crimsonalucard 8y ago
NaN is property of the floating point specification.
https://en.wikipedia.org/wiki/NaN https://en.wikipedia.org/wiki/NaN
The purpose of silent propagation is for the expression to be checked at the end of the overall expression rather then have every operation itself be checked. It's a speed optimization. It is by far more user friendly for an invalid operation to throw an error.
For example
for this following operation
(100/2/2/0/2)
without NaNs the system must check 4 operations 100/2, 50/2, 25/2, 12.5/0 for an error. Every arithmetic operation whether it has a division by zero or not will have to have additional checks.
With NaNs the computer just runs through the entire operation with no checks and the user just explicitly does a check for a single NaN at the end. The Maybe Monad operates under the same concept when used as an output type for a division operation.
The same logic applies for javascript "undefined".