lua-users home
lua-l archive

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

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.)