Log In  

Hi, I have a trouble with floating point arithmetic.

function _draw()
    cls()
    print( 256 / 65536 * 256 )
    print( 256 / (256*256) )
end

This snipet output "-2" and "32768".
Why this snipet dosn't output "1" and "0.00390625" ?

I try same thing on lua demopage.
https://www.lua.org/cgi-bin/demo
It outputs "0.00390625".

Thanks.

P#61679 2019-02-09 06:59 ( Edited 2019-02-09 07:02)

:: Xii

65536 overflows. The largest number PICO-8 can handle is 32767.99999

P#61684 2019-02-09 12:08

PICO-8 doesn't use the same number representation as regular Lua, so the Lua demo page exhibits different behavior.

Lua's numbers are 64-bit floating-point numbers. However, PICO-8's numbers are fixed-point, with 16 bits before the decimal point (-32767 to 32768), and 16 bits after the decimal points.

P#61693 2019-02-09 18:30
:: qnl

@Xii, @tobiasvl Thanks!!

I understood that limitation.

P#61710 2019-02-10 05:45

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-08-19 15:11 | 0.033s | 2097k | Q:21