Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding error passing large integers #229

Closed
jneb opened this issue Dec 26, 2022 · 3 comments
Closed

Rounding error passing large integers #229

jneb opened this issue Dec 26, 2022 · 3 comments

Comments

@jneb
Copy link

jneb commented Dec 26, 2022

If you have a integer number of more than 53 bits (and less than 64 obviously) it will be rounded to float when passed from lua to python:

>>> lua.lua_version
(5, 4)
>>> lua.eval("1000000000*1000000000-1")
1000000000000000000
>>> lua.eval("1000000000*1000000000-1 .. ''")
'999999999999999999'

Here you can see that the calculation didn't overflow, proving that a 64 bit integer was produced by lua, but the number got lost in translation to python.
This is probably not noticed but many, but pretty annoying when you encounter it!

In the code I found the function py_from_lua that apparently is supposed to do this correctly for versions >= 5.3, but it doesn't work for me (on pydroid 3).

@jneb
Copy link
Author

jneb commented Dec 26, 2022

After trying to figure out what the code does, I guess the error is near line 1320 of _lupa.pyx
After having checked for the right version of lua and python, it does:
integer = lua.lua_tointeger(L, n)
This function tointeger is part of lua itself and doesn't do anything for integers, so I guess something else was intended here.

@scoder
Copy link
Owner

scoder commented Dec 27, 2022

Which Lupa version are you using? Lupa 2.0 is still unreleased.

https://github.com/scoder/lupa/blob/master/CHANGES.rst

@jneb
Copy link
Author

jneb commented Dec 27, 2022

That's 1.14.1: the version pipy provided. Considering it is fixed, that means that the actual issue is that the pipy version needs updating:-)

@jneb jneb closed this as completed Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants