2 ms·
Curious, what number is representable in IEEE float but not as a decimal?
by beached_whale 6y ago
Curious, what number is representable in IEEE float but not as a decimal?
- nayuki 6y ago+Infinity, -Infinity, NaN (quiet, signaling, miscellaneous).
- beached_whale 6y agoWell, those are all error conditions and not a number. NaN's explicitly say they aren't, and +-Inf may or may not be infinity, all we know is that it is outside the representable range of IEEE floating point.
- derefr 6y agoIMHO, code should check for floating-point overflow just like it checks for integer overflow. If your inputs are finite and your output is infinite, that's similar to your inputs being positive and your output being negative: you should check for it and emit an error instead. Then infinity (like negative numbers) can have an actual semantic meaning, rather than just being the detritus of an error condition.
- jjgreen 6y agoNaNs have an odd ontology, regardless of what they claim to be. For example, hypot(Inf, NaN) == Inf (C99), which suggests that NaN is "some number but we cannot know what it is".
- cbsmith 6y agoI should have qualified that statement. You can represent them with an infinite length decimal, but that kind of defeats the purpose, right?