lua-users home
lua-l archive

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


> this is a test for IEEEtrick, used at Lua5.2.2 and before, and removed from
> Lua5.3.0-work1,
> 
> My CPU is Intel i5-2410M, but IEEEtrick still much faster than direct
> convert.

As said several times before, we expect this conversion to be rare. No
one writes 0.0 for integer computations (although many people write 0
for doubles); except for an occasional division (usually used together
with math.floor), it seems very uncommon for a floating value to
"escape" into an integer computation.

Another reason we removed the trick was to give a sound behavior for
this conversion. Now, the conversion always gives you the floor of the
number, plus an error if the number does not fit in an integer.

Anyway, can you adapt it to convert from double to 64-bit integers?

> return (2.0^53) // 1
9007199254740992
> return (2.0^53 - 1) // 1
9007199254740991
> return (2.0^53 + 1) // 1
9007199254740992              --<< (correct)
> return (2.0^64) // 1
stdin:1: attempt to convert an out of range float to an integer

-- Roberto