[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: parse hex numerals [PATCH]
- From: Mike Pall <mikelu-0602@...>
- Date: Thu, 9 Feb 2006 17:19:38 +0100
Hi,
Roberto Ierusalimschy wrote:
> What about this?
>
> + if (*endptr == 'x') *result = strtoul(s, &endptr, 16);
Cute. :-) Improvement:
if (*endptr == 'x' || *endptr == 'X')
*result = cast_num(strtoul(s, &endptr, 16));
Tested with original MSVCRT DLLs and works fine. Alas, tonumber()
converts negative hex numbers to large positive doubles. :-/
But the approach in the lexer works. So -0xff == -255, but
tonumber"-0xff" == 4294967041 with lua_Number = double.
Everything's ok for lua_Number = int due to wrap-around.
Let's just pretend signed hex numbers are not too relevant for
tonumber().
Bye,
Mike