patternMinor
Why floating point representation uses a sign bit instead of 2's complement to indicate negative numbers
Viewed 0 times
whybitpointfloatingindicatesignnumbersusesinsteadcomplement
Problem
Consider a fixed point representation which can be regarded as a degenerate case of a floating number. It is entirely possible to use 2's complement for negative numbers. But why is a sign bit necessary for floating point numbers, shouldn't mantissa bits be using 2's complements?
Also why do the exponent bits use a bias instead of a signed-magnitude representation (similar to the mantissa bits) or 2's complement representation?
Update: Sorry if I didn't make it clear. I was looking for the reason of how floating point representation is shaped. If there is no strong implementation trade-off between the alternatives, then could someone explain the historical aspects of the floating point representation?
Also why do the exponent bits use a bias instead of a signed-magnitude representation (similar to the mantissa bits) or 2's complement representation?
Update: Sorry if I didn't make it clear. I was looking for the reason of how floating point representation is shaped. If there is no strong implementation trade-off between the alternatives, then could someone explain the historical aspects of the floating point representation?
Solution
Two's complement makes sense when the two entities in question have the same "units" and the same "width". By width I mean that, say, if you're adding an N bit number and an M bit number, where N and M are different, then you better not use two's complement. For floating point numbers, we have the problem of units: if the exponents are different, then we are mentally shifting one of the mantissas, and now we're at the same problem as before (with the width).
As for the exponent bits, by using a bias instead of sign+magnitude we gain one more value (otherwise we'd have +0 and -0). Here two's-complement makes sense when multiplying or dividing numbers (since then we're adding or subtracting the exponents), but not as much sense when adding or subtracting.
Edit: A commenter remarked that you can add two's complement integers of different lengths using sign extension. There is also some problem with detecting overflow, but that's also fixable. In summary, you could probably use two's complement, if you're careful enough. (You also need to handle multiplication and division.)
As for the exponent bits, by using a bias instead of sign+magnitude we gain one more value (otherwise we'd have +0 and -0). Here two's-complement makes sense when multiplying or dividing numbers (since then we're adding or subtracting the exponents), but not as much sense when adding or subtracting.
Edit: A commenter remarked that you can add two's complement integers of different lengths using sign extension. There is also some problem with detecting overflow, but that's also fixable. In summary, you could probably use two's complement, if you're careful enough. (You also need to handle multiplication and division.)
Context
StackExchange Computer Science Q#6048, answer score: 7
Revisions (0)
No revisions yet.