[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Compiler warnings when dealing with huge integers
- From: Mooffie <mooffie@...>
- Date: Sun, 26 Jun 2016 14:12:51 +0300
On 6/26/16, Sean Conner <sean@conman.org> wrote:
>
> First off, a 64-bit integer can store values in two ranges:
>
> -9223372036854775808 .. 9223372036854775807
> 0 .. 18446744073709551615
>
> A double can "safely" store integers in the range:
>
> -9007199254740992 .. 9007199254740992
>
> I say "safely" because past that range, integers start having "gaps"
> between [...]
I'm well aware of the fact that typically only integers less than 2^53
can be "safely" stored in Lua numbers (prior to Lua 5.2), and I'm fine
with this.
>
> The safest course is to check that the result (as a double) fits in the
> "safe" range and if not,
While this was not at all my original concern, you helped me to decide
that I should have a function dedicated to getting huge integers from
the Lua stack. BTW, do you know of a simple way of checking that a
floating number is in the safe integer range? I see that Lua 5.2's
implementation of file:seek does some range checking but it only
detects a number being outside, say, the 64 bits, not out the "safe"
53 bits.