Re:One does not simply calculate the absolute value
by sp332 on Sunday August 22, 2021 @03:41PM
(#28268808)
The question is whether that last technique, of just flipping the sign bit, handles NaNs and infinities.
[ Parent
| on HN ]
Re:One does not simply calculate the absolute value
by pm215 on Sunday August 22, 2021 @04:09PM
(#28269105)
It's the required semantics of the IEEE floating point spec's absolute-value operation. This does mean that abs() doesn't behave like eg addition in that it won't set fp exception flags for signaling NaNs, or canonicalize NaNs, or set a flag to note that this was a denormal number. But at the language level "follows IEEE semantics" is probably overall less surprising.
chs() ("flip the sign bit") is the other operation that's defined as effectively just an operation on the representation rather than a "do a real floating point computation".
Re:One does not simply calculate the absolute value
by MontyCarloHall on Sunday August 22, 2021 @03:59PM
(#28269011)
Yes.
The sign bit is totally independent of the value being encoded, whether that’s a number, q/sNaN, or infinity.
Nitpick: we are not flipping the sign bit, but rather setting it to 0.