#Float precision
1 messages · Page 1 of 1 (latest)
<@&987246964494204979> please have a look, thanks.
IK it's partially due to the way it stores it in the IEEE 754 Format but can someone elaborate on this?
not only partly, its the reason
u have to look at how the values are represented internally
therefore, u can use for example https://float.exposed/
Floating point format explorer – binary representations of common floating point formats.
0.1f is stored as
0.2f as
https://i.imgur.com/goGURuO.png
u also notice that its not a clean 0.1 and 0.2
all values in between this and that delta here: https://i.imgur.com/0oRI6d8.png
are considered the same value
so 0.10000000000000000000000123f == 0.10000000000000000000000004f is for example true
now, what happens when u add these two numbers? u get 0.30000000447
and 0.30000000447f == 0.3f is still considered true because its within that delta
but for a double that delta is much smaller, since it has a higher resolution
so when u do the same
0.1 as double: https://i.imgur.com/Zo6GLn6.png
0.2 as double: https://i.imgur.com/rvZS8lQ.png
then u get 0.30000000000000004
and the delta doesnt include 0.3 bc the distance is greater
like, the number 0.3 as double is represented by the range 0.3 plus minus 5.5 * 10^-17
so roughly 2.9999999999999999945 to 0.30000000000000000055
while 0.1+0.2 for double lands beyond that number
and for float within
float.exposed links to the article the author wrote, which has much more in depth information
In depth explanation of floating point format.
There's actually a website dedicated to 0.1 + 0.2: https://0.30000000000000004.com/