6 ms·
The most beautiful way around this I've seen is the Posit number system. It's a floating point system that contains a single NaN which is the opposite of zero.
by GolDDranks 5y ago
The most beautiful way around this I've seen is the Posit number system. It's a floating point system that contains a single NaN which is the opposite of zero. https://posithub.org/ https://posithub.org/
- addaon 5y agoI'm a huge fan of this system, but it's worth pointing out that it doesn't have a single NaN, it has a single infinity with an undefined sign, modeling the projectively extended real numbers. NaN is a bit of an abomination; projective infinity is an uncommon beast, but one that can be worked with consistently. And yes, by pairing zero with infinity on opposite sides of the number ring, you get a symmetric system with no undefined or redundant encodings.
- Aardwolf 5y agoSigned infinity is useful for limits, and also for initial values of some algorithms, so missing them seems like a disadvantage. Also, it still has no total order, so keeps another messy part of IEEE floats
- GolDDranks 5y agoThere's an easy alternative: just use the MAX and MIN values. That's what you would do with integers anyway, in case of initial values. As for limits, if you need to express limits in a datatype for expressing a small subset of rational numbers, you've got the wrong tool for the job.
- GolDDranks 5y ago> Also, it still has no total order This is not true. It is defined to have the exact same ordering, bitwise, as two's complement integers. That means it has total order: the NaN is the most negative, then comes the negative numbers, then zero, and then positive numbers.
- eurasiantiger 5y agoNaN is a feature of dynamically typed languages; otherwise they would not be able to represent all outcomes of implicit coercion.
- spc476 5y agoAnd here I thought NaN was a definition from IEEE-754.
- forty 5y agoYes, I'm not sure what parent means. Even java double has NaN.
- wongarsu 5y agoNaN is a feature of IEEE floats to ensure that all arithmetic operations can always create a correct result. For example 0/0 has to evaluate to NaN, no other result would be mathematically correct. If there was no NaN the CPU would have to trigger a fault or return an incorrect result, both are undesirable.
- eurasiantiger 5y agoSo, today I learned something: the JavaScript critics are wrong at yet another thing.
- LinAGKar 5y agoIt crops up more in JavaScript since it doesn't have integers, and if you try to convert non-numeric string to a number you get a NaN
- GolDDranks 5y agoThey used to call it "infinity with an undefined sign", then "NaR" for "Not a Real" but in the latest papers I've seen they just call it NaN. But that's just a name, it's the projective infinity as you say. I agree that the IEEE NaN is an abomination.
- gbrown_ 5y agoIt still seems to be NaR here https://posithub.org/posit_standard4.12.pdf https://posithub.org/posit_standard4.12.pdf
- nwatson 5y agoLooks like there's no negative zero in posit, which is useful in some contexts .... https://en.wikipedia.org/wiki/Signed_zero https://en.wikipedia.org/wiki/Signed_zero
- GolDDranks 5y agoYes, that's a feature. I regard negative zero as a misfeature in most contexts. There might be some, where it's useful, but a general purpose datatype shouldn't be optimized for niche use cases. There is no a real number called "negative zero". For extremely small-magnitude negative values, posits have more to offer than IEEE floats without the abomination that is known as denormal numbers. And for limits approaching zero, using a datatype that is supposed to represent a subset of rational numbers is the wrong tool for the job.