summentier
summentier

Reputation: 456

Why does +0.0 > -0.0 not hold for IEEE754 floats?

IEEE754 floating point numbers have the concept of a signed zero, i.e. there are two different bit patterns for -0.0 and +0.0, which can be understood as one-sided limits: ±0 := limδ→0 ±δ. The standard provides these numbers for consistency with the (signed) infinities +Inf and -Inf (1./±0. gives ±Inf), and there is some evidence that it helps reduce roundoff errors.

It is clear from the limit that while they are different entities, they compare to the same value, i.e, +0.0 == -0.0 holds. However, from the limit I would also think that the following thing should hold: +0.0 > -0.0, since it holds for any small δ. This however is not true. Since this property would occasionally be useful (think about distinguishing the two zeros, for example), is there any compelling reason why the standards committee chose not to do that?

Upvotes: 4

Views: 137

Answers (1)

Potatoswatter
Potatoswatter

Reputation: 137770

Mathworld's article on the number system underlying floating-point arithmetic cites David Goldberg's famous paper, which says,

Although distinguishing between +0 and -0 has advantages, it can occasionally be confusing. For example, signed zero destroys the relation x = y ⇔ 1/x = 1/y, which is false when x = +0 and y = -0. However, the IEEE committee decided that the advantages of utilizing the sign of zero outweighed the disadvantages.

The committee has a website which can be searched for such discussion, and it looks like signed zeroes are the source of perpetual controversy.

I can't find anything there about your particular question. But just as a speculation, it's possible that they wanted to simplify the hardware, that comparison only produces a result from the set {less, greater, equal, unordered}. Allowing both –0 < +0 and –0 = +0 would complicate (and potentially slow) some circuitry. It might have been deemed uneconomical.

Upvotes: 2

Related Questions