0.000000000000004 showing up when small values are added up

when adding small values(0.1/0.25/0.3) to a normal value(1/2/3) a few times, 0.000000000000004 is added to the value

i think this could be some issue with gdevelop converting from the drag drop code to their native code java, but i am entirely unsure

its fairly easy to recreate: new blank project, add a sprite and a text object
give sprite a variable(value) of 1, in the editor, every three seconds add 0.1 to the sprite’s variable, have the text display the value of the variable constantly

i am un aware as to how to upload a project here, so im using drop box to upload the raw project here

after a little testing: adding 0.1 appears to start the bug after the first two additions, 0.3 after the 4th addition- also fixes itself after the sixth an breaks again after the 8th, 0.25 seems to break randomly with no clear pattern, those are just the values i messed with, there are probably others like 1.1, or 0.7

im almost certain that it is a bug, because why would adding an additional 0.000000000000004 randomly not be

0.1 is not really 0.1 in binary floating point notation. So when you add it several times, you also add a rounding error.
https://www.h-schmidt.net/FloatConverter/IEEE754.html

2 Likes

Но в констракт 3 и других движках нормально все вычисляется. Я делал игру кубики кушающие фрукты а, съев получают вес 0.2! Вес отображается и вдруг - тадададам!!! БЫЛО 127.6 СТАЛО 127.8009646308! ЭТО ВЕРОЯТНО ОШИБКА КОДА ДВИЖКА!!!

But in construct 3 and other engines, everything is calculated normally. I was making a game in which cubes eat fruits and after that their weight increases by 0.2! The weight is displayed, and suddenly — bang! IT WAS 127.6 AND BECAME 127.8009646308! THIS IS PROBABLY AN ERROR IN THE ENGINE CODE!!!

Davy is one of the main engine devs so I’d trust his info.

Also coding rounding errors are exceptionally well known. GDevelop doesn’t do the cleanup that some other engines do because people may need the fractional details, but you can read about Round-off errors here: Round-off error - Wikipedia