Log In  


I have a counter that's incremented by 0.05 every update and wanted to perform some work when the the value rounds up to a whole number, e.g. 3. I noticed this code never executed. After some more investigation I discovered that 20 * .05 does not equal 1.0 but rather 0.9998.

Is this a known issue? Here's an example:



EDIT: My bad, @dredds has correct answer.


Pico-8 does not use floating point. Numbers are represented as 32-bit fixed point values, with 16 bits of whole number and 16 fractional bits after the binary point (the equivalent of the decimal point for binary numbers).

0.05 is 1/20 and cannot be exactly represented in this format. In hex, it is 0x0000.0ccccccccccccccccc.... (c recurring).

If you want predictable maths with fractions, use 1 over a power of 2. E.g. 1/2, 1/4, 1/8, 1/16, 1/32, etc.


Thanks for the clarification, much appreciated!



[Please log in to post a comment]