Hacker News new | ask | show | jobs
by AlotOfReading 45 days ago
If you rename +/- Inf, that's what saturating arithmetic is. Very likely your language and hardware already supports it.

NaN is almost always a mistake, and adding it breaks the law of identity. You don't want it.

1 comments

OK, I did not know about [saturation arithmetic](https://en.wikipedia.org/wiki/Saturation_arithmetic). Cool!

But I can't agree with the claim that "nan is almost always a mistake". Certainly if you're doing floating-point computation on large arrays, the last thing you want is e.g. for an error to be thrown in a elementwise division just because two corresponding elements both happen to be zero.

It's true that nan!=nan is one of the more 'controversial' parts of the standard, that possibly would have been decided the other way in a perfect world. But it was also a reasonable pragmatic decision at the time the standard was developed. See here: https://stackoverflow.com/a/1573715/1013442