4 ms·
Floats still have an issue for this particular piece of code though! abs(-0) would return -0
by unholiness 5y ago
Floats still have an issue for this particular piece of code though! abs(-0) would return -0
- kps 5y agoIEEE754 specifies that abs(−0) is 0 (positive). (If your machine doesn't use IEEE754, I'd love to hear more about your project.)
- jsrcout 5y agoSome coworkers had to deal with MIL-STD-1750A [0] floating point recently. None of us had ever heard of it. They were talking to some pretty old HW. [0] https://en.wikipedia.org/wiki/MIL-STD-1750A https://en.wikipedia.org/wiki/MIL-STD-1750A
- hoseja 5y agoWow, lot of famous spacecraft using that.
- Sniffnoy 5y agoThe commenter above you isn't talking about IEEE754's abs() function, but rather the code from the OP, except applied to floats rather than ints.
- LinAGKar 5y agoThat code also has the same problem for one's complement and sign+magnitude, which are allowed encodings in C.
- ameliaquining 5y agoThis is going away in the next version of the C standard. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf
- Sniffnoy 5y agoOh, nice!