What sets Lua to float for integers?

So, one of the coolest things about Lua is that you can use float numbers instead of double numbers for numbers. LUA_NUMBER in luaconf.h. This works very well for me!

But I always wondered how lua handles integers. In js and as3, I know that integers also remain "numbers." This works very well if numbers always double with 53 mantissa characters, because 32-bit people expect integers to be well covered. Now, if someone had to swim with 23 mantissa digits, this no longer works properly. Code often treats integers as 32 bits, for bitwise operations or things like packed 32-bit colors.

So my question is: if I build with "#define LUA_NUMBER float", is this my whole limit of 23 bits? Is the answer more complicated? If so, why and how? I also never used luajit, but how do other lua implementations handle this?

I know that I can just read the code, but I think this is an interesting problem. And I'm lazy :) For my use case, I'm fine with an assumption of 23 bits.

+4
source share
1 answer

Yes, integers are limited by the size of the numbers. So, if you use float, you will get 24 bits for integers (there is a hidden bit in the floating point view).

+2
source

Source: https://habr.com/ru/post/1486746/


All Articles