lua-users home
lua-l archive

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


> Going down all the way, the multiplication used in 5.3 to test
> the sign of the result may underflow:
> 
> $ Lua 5.3.2  Copyright (C) 1994-2015 Lua.org, PUC-Rio
>> -2.1^-1000 % 2^-1000
> -5.928787750095e-323
> 
> The result should be non negative, in the range [0,2^-1000).
> 
> -- Roberto

Good catch !

FYI, even with underflow, the sign bit is still there.

double a = -6e-323, b = 0x1p-1000, c = a*b;
printf("c = %g, sign_bit = %#x\n", c, signbit(c));

c = 0, sign_bit = 0x200

However, signbit test is too good, fmod test like this:

if (signbit((m)*(b)) && (m) != 0) (m) += (b);