4 ms·
> The result of any operation on a NaN is a NaN. That's not true! maxNum(nan, x) = x.
by UncleMeat 4y ago
> The result of any operation on a NaN is a NaN.
That's not true! maxNum(nan, x) = x.
- ilyt 4y agoIt's complicated. https://754r.ucbtest.org/background/minNum_maxNum_Removal_Demotion_v3.pdf https://754r.ucbtest.org/background/minNum_maxNum_Removal_De...
- UncleMeat 4y agoLooks like maximum and maximumMagnitude have the same relevant property (NaN is not viral).
- a_e_k 4y agoThe standard for comparison with NaNs is to always return false [0]. So that entirely depends on how max() is implemented. A naive implementation of max() might just as easily instead return NaN for that. Or if max(NaN, x) is x, then it may give NaN for max(x, NaN). Note that the fact that comparisons always return false also means that sorting an array of floating point values that contain NaNs can very easily break a comparison-based sorting algorithm!! (I've seen std::sort() in C++, for example, crash because NaNs break the strict weak ordering [1] requirement.) [0] https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN [1] https://en.cppreference.com/w/cpp/named_req/Compare https://en.cppreference.com/w/cpp/named_req/Compare
- UncleMeat 4y agomaxNum is (was - as another poster mentioned it is now deprecated) a specific function defined in the IEEE specification. This isn't a language level comparison function but a specific operation on floating points that has to behave the way I described. It is not a comparison function. maximumMagnitude (and a few similar ones) replace it but behave similarly.