lua-users home
lua-l archive

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


Hello,
I'm using Lua 5.2 as the foundation of my own language (Killa).
Killa has a _javascript_ like syntax and hence supports:

     alert(9.9 | 0); // Alerts 9. (x|0) is used a lot in JS to floor x.

the code in Lua:

     print(bit32.bor(9.9, 0)) -- prints 10, not 9

The problem I suspect is that the code under the MS_ASMTRICK is not correct (llimits.h:204):
this block:
    __asm {__asm fld n   __asm fistp i}

that is used in:
    #define lua_number2unsigned(i,n)  \
         {__int64 l; __asm {__asm fld n   __asm fistp l} i = (unsigned int)l;}

it's not guaranteed to floor a number, it depends on the FPU rounding mode.
as explained here: http://stereopsis.com/FPU.html

I suspect this is a bug because the slow alternative is not giving me the same result, but I can be missing something.

I have implemented bitwise operators for Killa but I was using this macro for the conversion, just disabling this macro gives me correct results on my test:
https://love2d.org/forums/viewtopic.php?f=3&t=9069

Any comments?

Best regards
Laurens


--
<DESIGN... don't DEBUG!!>