[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 5.1 rc mod giving -0 (never just 0)
- From: Rici Lake <lua@...>
- Date: Sun, 22 Jan 2006 18:32:06 -0500
On 22-Jan-06, at 4:25 PM, Asko Kauppi wrote:
Not sure if this is worth bringing up, but...
Lua 5.1-rc always gives "-0" for zero mod results. Since PIL2 says
"the result always having the same sign as the second argument", this
raises my eyebrowns.
I confirmed this on a similar powerpc.
The problem is that gcc (with -O2) produces a "fused negated multiply
and subtract" opcode for the computation of luai_nummod: b -
floor(b/c)*c. My guess is that fnmsub is implemented in hardware by
simply negating the result of fmsub. The PPC numerics guide does warn
than the four fused multiply/add instructions may violate ieee-754
semantics.
In any event, if you compile lua (or at least lvm.c) with the option
-mno-fused-madd, then you'll get 0 rather -0. (Or you could redefine
luai_nummod in terms of fmod and copysign.)