Re:Signed Integers Are Two’s Complement
by garmaine on Wednesday May 30, 2018 @11:18PM
(#17193708)
In addition to what's mentioned in the already great sibling comments, it's worth noting that IEEE floating point is signed-magnitude.
[ Parent
| on HN ]
Re:Signed Integers Are Two’s Complement
by userbinator on Thursday May 31, 2018 @12:06AM
(#17193867)
Sign-magnitude for the significand, and offset-binary for the exponent. The reason for this odd combination is probably historical.
Re:Signed Integers Are Two’s Complement
by akrasuski1 on Thursday May 31, 2018 @12:36AM
(#17193989)
It's done so that the bits will compare the same way whether treated as float or int. (modulo NaNs and stuff)
That is only true for non-negative floating point numbers. It's still useful though.
Interestingly, posits as originally proposed do have this property (except for infinity).
Would have been nice if IEEE stored the complement sign.
It's also practical for hw implementation and has other nice qualities. E.g. comparisons and sorting are easy. Radix sort works for floating point (with some bit magic). Terms and conditions may apply (oddities w.r.t. INF, Nan, etc).
It doesn't seem odd to me. When describing things in nature, (+x, -x) tend to have more symmetry than (x, 1/x).
Re:Signed Integers Are Two’s Complement
by jovial_cavalier on Wednesday May 30, 2018 @11:49PM
(#17193807)
Is there a good way to represent floating points in order to do complement arithmetic?
Yes, see JavaScript: https://www.w3schools.com/js/js_numbers.asp
JS is IEEE754, not a (one's or two's) complement-based representation.
Ah I misunderstood the question.
Re:Signed Integers Are Two’s Complement
by hamiltonkibbe on Thursday May 31, 2018 @12:38AM
(#17193997)
If you know a bit about the range you need to support you could use a fixed point representation