Hacker News new | ask | show | jobs
by gnramires 1893 days ago
> Can you guarantee that your code is free of such overflows?

Well, according to the manual, you can by appending '+0.0' (or '.0'?) to numbers, converting it to float (tested on Lua 5.4 even hex '0xf...f' can be written as '0xf...f.0').

I don't quite understand the change in terms of language design -- if integer was necessary surely an integer library would be sufficient? I find it a little "too smart for its own good" (in the sense of being unreliable in practice). Perhaps they could have gone for a more separate integer type? For my use cases however, I don't expect to run into any problems (9.2e18 is a very large number).

> Mike Pall does share some of my criticisms to Lua as well [1].

Yes, it makes me sad they broke compatibility so much. I mean, 4 different versions in use is a lot. Hopefully 5.4 is stable now.

1 comments

> Well, according to the manual, you can by appending '+0.0' (or '.0'?) to numbers, converting it to float.

In addition to making extensive changes to the code, this is not complete because there are plenty of functions that would return integer instead of numbers (e.g. tonumber).

> Perhaps they could have gone for a more separate integer type?

I too think JS did the right thing: it introduced a new type for integers, and took it as a chance to make it arbitrary precision.