robert bristow-johnson
robert bristow-johnson

Reputation: 260

what *should* you get when you add minus-zero to plus-zero?

this Wikipedia article did not address this contingency and i am having trouble finding a definitive IEEE-754 document that addresses this.

Upvotes: 1

Views: 180

Answers (1)

John Bollinger
John Bollinger

Reputation: 181459

According to one purported copy of the IEEE 754 (1985) standard,

When the sum of two operands with opposite signs (or the difference of two operands with like signs) is exactly zero, the sign of that sum (or difference) shall be + in all rounding modes except round toward –INFINITY, in which mode that sign shall be –. However, x+x = x–(–x) retains the same sign as x even when x is zero.

(section 6.3)

That applies to the (+0) + (-0) case, requiring the result to be +0 in most rounding modes, but -0 in round toward -INFINITY mode.

Upvotes: 3

Related Questions