3 ms·
> The source I had in my head as I was replying was https://posithub.org/docs/Posits4.pdf https://posithub.org/docs/Posits4.pdf pages 31/32 which implies that t
by jcranmer 4y ago
> The source I had in my head as I was replying was https://posithub.org/docs/Posits4.pdf https://posithub.org/docs/Posits4.pdf pages 31/32 which implies that the sign bit is responsible for signalling-ness.
Citing the person who came up with posits for anything related to IEEE 754 is a pretty poor decision, he is prone to a lot of misunderstanding here. There's a lot of decent explanations of IEEE 754 (including Wikipedia), so you shouldn't need to resort the explanations of someone whose major shtick is telling people IEEE 754 sucks.
> How is the sign bit used in NaNs? Would they really waste that bit?
Sign bits have no meaning for NaNs, although some C libraries (e.g., glibc) will distinguish between a NaN with the sign bit set and not set when printing floating-point numbers, which gives the illusion that it matters more than any other bit. Using the sign bit for qNaN-versus-sNaN is a bad idea from a design perspective, since there are a few FP operations explicitly specified to modify only the sign bit (fneg, fabs), and this would mean that you get regular operations that could generate sNaNs, which defeats the design goal of sNaN.
- stephencanon 4y agoSign bits of NaN is one of the dumbest parts of the 754 standard. 6.3 specifies that "the standard does not interpret the sign bit of a NaN" and then the very next sentence lists four cases where the sign bit of NaN has semantic meaning.
- adgjlsfhk1 4y agoreally all of the NaN behavior is really dumb. "we gave you enough different NaNs to uniquely represent every grain of sand on the planet uniquely" how does math work on them? "we have no idea" how do we tell what type of nan we have? "we have no idea" what should these bajillion values represent? "I don't know, probably something" the fact that they didn't just make there be a single NaN and make it equal to itself (and while you're at it make it so the real numbers have a total ordering)
- kryptiskt 4y agoBut in the end we found a great use case for all those NaN values because NaN-boxing is awesome.
- adgjlsfhk1 4y agoexcept that it breaks on processors that propagate nan bits differently (e.g. m1)
- jcranmer 4y ago> how does math work on them? For almost all operations, if any input is a NaN, the result is a NaN. It's pretty well-specified by IEEE 754, the only thing that isn't is what the payload is, but there's no general expectation that the payload is preserved through computation. > how do we tell what type of nan we have? `getpayload()` > what should these bajillion values represent? Diagnostic information that tells you which operation caused the NaN in the first place. (This is Kahan's standard argument for why having many NaNs can be useful.) > the fact that they didn't just make there be a single NaN What's the alternative? You'd either have to have lots of illegal floating point values, or you'd have to make the number of finite floating-point numbers with the highest exponent value slightly smaller than for all other exponent values, which complicates a good deal of numerical analysis. > make it equal to itself Yeah, this is the big, nasty mistake of IEEE 754. > and while you're at it make it so the real numbers have a total ordering There is a totalOrder predicate specified by IEEE 754. Representing floating-point comparisons as a partial order is arguably better than giving it a total order, but the lack of reflexivity of equals makes the existing predicates not a partial order.