4 ms·
Fun fact, JSON's number type isn't floating point. It may map to it, but the limits on the numbers that are representible are defined by the encoder and decode
by beached_whale 6y ago
Fun fact, JSON's number type isn't floating point. It may map to it, but the limits on the numbers that are representible are defined by the encoder and decoder.
- deleted 6y ago[deleted]
- cbsmith 6y agoWhich creates this lovely reality where you effectively have numbers that can be accurately represented in IEEE float but can't be represented accurately in decimal notation, and numbers that can be represented accurately in decimal notation but not in IEEE float. All of those cases are dicey with JSON.
- beached_whale 6y agoCurious, 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?