lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 20 Sep 2010, at 08:29, David Kastrup <> wrote:
> And you did not realize that in all the presented code, there was _no_
> way that would _ever_ generate -0 unless there was a processing error
> involved.

It can happen if the rounding mode is towards negative infinity. IEEE 754 says:

6.3. The Sign Bit

This standard does not interpret the sign of an NaN. Otherwise, the sign of a product or quotient is the exclusive or of the operands' signs; the sign of a sum, or of a difference x–y regarded as a sum x+ (–y), differs from at most one of the addends' signs, and the sign of the result of the round floating-point number to integral value operation is the sign of the operand. These rules shall apply even when operands or results are zero or infinite.

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.

Except that sqrt(–0) shall be –0, every valid square root shall have a positive sign.

f.anthony.n.finch  <>