Lua integer operations bug

Redox

Warlord
Joined
Jun 15, 2011
Messages
134
This is what I get in LiveTuner:

Code:
> print(2519 * 10000 + 2309)
 InGame: 2519230[COLOR="Red"]8[/COLOR]

The result is obviously wrong, and probably has to do with the fact that Lua has only a single data type, which should be "double" (but can be platform-specific afaik)

But there should be more than enough precision in 64-bit double to handle this operation. Even 32-bit integer could do it. Can anyone tell me what is the reason or if it gives you the same thing? I'm running win7 32-bit.
 
Windows XP SP3

Pretty much foobar

Code:
> (a * 10000) + 1
25190000
> (a * 10000) + 2
25190002
> (a * 10000) + 3
25190004
> (a * 10000) + 4
25190004
> (a * 10000) + 5
25190004
> (a * 10000) + 6
25190006
> (a * 10000) + 7
25190008
> (a * 10000) + 8
25190008
> (a * 10000) + 9
25190008
 
You put it in a more polite way than I did after I spent 30 minutes debugging a seemingly correct code :crazyeye:. So, I'm not alone. Here's what I found:

http://lua-users.org/wiki/FloatingPoint

Here or in some other place it says that an app (civ) can change default number format, so it could become 32-bit float. But even that should perform precise calculations on numbers up to 2^23 (~8.3 mln) if I am correct.

I guess it's time to write some functions which perform numerical operations on numbers stored as text :(
 
Back
Top Bottom