Log In  

String to number conversion produces incorrect values (at least for -1!!)

-- prints false :/

-- prints 0xFFFF.0001
P#56241 2018-09-05 16:54 ( Edited 2018-11-01 16:23)

Looks like you don't have to use the tonum() function. It even fails on Lua's internal auto-conversion of strings to numbers in expressions:

> ?tostr(0+"-1",true)

Also, it seems to do it for all negative numbers for both styles, all the way down to the nadir value of -32768:

> ?tostr(tonum("-32768"),true)

> ?tostr(0+"-32768",true)

So it's probably the built-in converter that's at fault. In fact, I wouldn't be surprised if tonum() looks like this internally:

function tonum(s)
  return 0+s

Good catch, surprised no one else ran into it before... or maybe they did and neither of us did a search of the forum. ;) But either way, it needs fixing.


P#56246 2018-09-05 21:32 ( Edited 2018-09-06 02:47)

Maybe I ran into that bug cause I am using my json parser left and right ;)

P#56258 2018-09-06 04:44 ( Edited 2018-09-06 11:42)

This tripped me up again recently. >.< I could've sworn I saw this posted already, but I guess it's not fixed yet...

P#58622 2018-11-01 12:23 ( Edited 2018-11-01 16:23)


Is this fixed in 0.1.12?

P#59552 2018-12-02 00:42

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2022-12-05 14:13:54 | 0.006s | Q:16