Search code examples
floating-pointdoubletwos-complement

Why is there no better representation for floating points than sign and magnitude?


We have 2's complement for integers that allows us to perform operations without worrying about the sign. That is a big help at the implementation level.

Similarly we have so many floating point operations and yet we rely on sign and magnitude. What is the reason?

Why can't a 2's complement like system work for floats?


Solution

  • For addition of floats there is a lot more to do than in the integer case - you need to shift one value to make the exponents match. Any additional cost for doing sign+magnitude addition is insignificant by comparison.

    Also note that the separate sign bit is much better for multiplication - you just need a single unsigned multiplier which handles all cases with the sign bits being taken care of separately. Compare this with two's complement multiplication, where you either have to normalise the signs or have support for signed/unsigned multiplies.