4
votes

Can IEEE 754 floating-point numbers represent the exact same value with multiple bit arrangements?

For example:
128 exp 3 == 1024.0
256 exp 2 == 1024.0
1024 exp 0 == 1024.0

Does the IEEE 754 standard consider differing bit arrangements to be equal in value when compared, as long as the net value ultimately appears to be the same?

I'm working on some custom compression algorithms, and it'd be very useful to know if there are multiple ways to represent the same value (for purposes of enhancing compression).

1
How do you regard 0 and -0? They both represent zero, and so in one sense have the same value, but they have different sign bits.Patricia Shanahan
@PatriciaShanahan That's another good example of multiple bit arrangements for the same value. Thanks for pointing that out. Looks like I need to watch out for NaN's and zeros for binary floating point numbers, as well as other redundancies for decimal floating point numbers.Giffyguy
Note that 1/+0 is positive infinity while 1/-0 is negative infinity. Replacing one with the other is detectable via "ordinary" arithmetic and comparisons.tmyklebu
In the context of compression, you should probably treat -0 and 0 as different values, because they can have different behavior.Patricia Shanahan
@tmyklebu and PatriciaShanahan: Thanks for the distinction. That's very good to know. My major concern was for nonzero finite numbers with multiple possible representations, so treating 0 and -0 as different values (as well as infinities and NaNs with different behaviors) should be fine. After all, the question is about different bit arrangements for the EXACT same value, and it sounds like 0 and -0 are not exactly the same value since they react differently to standard operations.Giffyguy

1 Answers

4
votes

The usual binary IEEE 754 floating-point types do not have the kind of redundancy you are referring to. Numbers are always normalized so that the significand is between 1.0 and 2.0 (or between 1.0 and 10.0 in binary). They do have stuff like positive zero and negative zero, and many NaN that have different internal representations.

However, the newer decimal IEEE 754 floating-point types do have this redundancy: A number like 3.14 can be represented as 314 with exponent 2; 3140 with exponent 3; 31400 with exponent 4; and so on.