4 ms·
> With that logic, you could say making (1 == 1) == true is wrong, because 1 isn't true. 1 == 1 isn't erroneous. Producing a boolean is the type of the operati
by kazinator 11y ago
> With that logic, you could say making (1 == 1) == true is wrong, because 1 isn't true.
1 == 1 isn't erroneous. Producing a boolean is the type of the operation: number x number -> bool.
(bool's domain could be extended with additional "nonbool" values, which are produced if some of the operands to a numeric comparison are not numbers.)
> calculation operation, not comparison operation
What's the difference? It's all computation. The comparison calculates a boolean result.
> As in, result of calculating Nan + 1 is NaN.
No it isn't. Proof:
NaN + 1 == NaN // yields false
As a hacky workaround, have to use some special predicate to test for NaN-ness, because the above doesn't work.
What would make sense would be to allocate a new NaN, so that it is legitimate that NaN + 1 != NaN. Neither side is a number, but the express different, individual ways of not being a number through their different identities. And the "isnan(X)" predicate tests whether X is an element of the set of all NaNs.
If that's not palatable, throw exceptions: don't allow NaN + 1 (why allow addition on "not a number"? Why even allow "not a number" to be stored into a variable of number type, in a static language?)