lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


That is not just a "scripter" problem, I think it is very common that programmers don't understand all the peculiarities of floating point. I don't know whether having integer data types makes this worse or not.

Robert

On 18 November 2014 12:09, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> Mostly because of this:
>
> i = 1<<62
> a = 2^62
> print(i, a)
> i = i * 4
> a = a * 4
> print(i,a)
>
> Now, I know what is going on, and you know what is going on. But does the average scripter know? I totally agree that string.sub(“foo”, 2) and string.sub(“foo”, 2.0) should return the same result, and that string.sub(“foo”, 2.5) should give an error. Then overflows come along and I would expect a user to go “er .. what???”. And of course the trouble with overflow type errors is they frequently slip through testing (how many times have you seen a dialog box with a negative “time remaining” value?).

A very common question from beginners (and most "average scripters")
runs like this:

> a = 1/3 - 1
> print((a + 1) * 3 == 1)
   --> false                ??????????????????????????

We have had this happening since the very first version of Lua. Scripters
do not know what is going on. They ask, they learn. Good for them.

-- Roberto