[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Integers-related trap in Lua 5.3
- From: "Soni L." <fakedme@...>
- Date: Mon, 16 May 2016 23:35:10 -0300
On 16/05/16 07:09 PM, Sean Conner wrote:
math.tointeger(9223372036854775807.0) ~= 9223372036854775807 so it can't
just always return a double. But it would be nice if it was smart about it.
It was thus said that the Great Egor Skriptunoff once stated:
It appears that in Lua 5.3 usual call to tonumber() is not enough
to correctly parse numbers entered by user from file or keyboard.
local googol = tonumber("1"..("0"):rep(100))
gives zero (instead of 1e+100 as in previous Lua versions).
I've read the other messages in this thread, and my question is: why was
the behavior of tonumber() even changed for Lua 5.3? Have it always return
a double because math.tointeger() exists to parse integers. You want a
number, use tonumber(). You want to ensure you parse an integer, use
math.tointeger(). That would at least prevent problems like this from
happening in the first place.
*One more syntax-related wish*:
Please let us use single quote as separator in float and integer literals:
local million = 1'000'000
local micro = 0.000'001
local mask32 = 0xFFFF'FFFF
Personally, I would prefer to use '_' instead.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.