[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: tonumber on large values
- From: Alexander Gladysh <agladysh@...>
- Date: Sat, 26 Nov 2011 04:40:43 +0400
Hi, list.
Here is a Lua pitfall I hadn't come across yet:
$ lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> s="3ef1e50af"
> =tonumber(s, 16)
4294967295
> return ("0x"..s) + 0
16896643247
Same with LuaJIT 2. Haven't tried 5.2.
I understand that the reason here is that tonumber() uses strtoul().
But I would say that expected behaviour for tonumber() with base 16 is
to behave identically to the equivalent coersion, provided by the
language. Otherwise, what's the point of using it?
Alexander.