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)

:: tobiasvl

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

[Please log in to post a comment]