[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: tonumber on large values
- From: Alexander Gladysh <agladysh@...>
- Date: Sat, 26 Nov 2011 04:40:43 +0400
Here is a Lua pitfall I hadn't come across yet:
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> =tonumber(s, 16)
> return ("0x"..s) + 0
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?