print((1 / 10 - 0.1) == 0) -- true
print((1 * 0.1 - 0.1) == 0) -- true
print((3 / 10 - 0.3) == 0) -- true
print((3 * 0.1 - 0.3) == 0) -- false
the last one is false, it means is not the 0.
print((1 / 10 - 0.1) == 0) -- true
print((1 * 0.1 - 0.1) == 0) -- true
print((3 / 10 - 0.3) == 0) -- true
print((3 * 0.1 - 0.3) == 0) -- false
the last one is false, it means is not the 0.
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
> function a(x) return ("%A"):format(x) end
> a(0.1)
0X1.999999999999AP-4
> a(0.3)
0X1.3333333333333P-2
> a(0.1 * 3)
0X1.3333333333334P-2
They are different due to rounding errors.
More details:
0.1 =
0X1.9999999999999999999... * 2^(-4) =
(rounding)
0X1.999999999999A * 2^(-4) =
0X1.999999999999AP-4
0.3 =
0X1.333333333333333333... * 2^(-2) =
(rounding)
0X1.3333333333333 * 2^(-2) =
0X1.3333333333333P-2
0.1 * 3 =
0X1.999999999999AP-4 * 3 =
0X1.999999999999A * 2^(-4) * 3 =
0X4.CCCCCCCCCCCCE * 2^(-4) =
0X1.33333333333338 * 2^(-2) =
(rounding)
0X1.3333333333334 * 2^(-2) =
0X1.3333333333334P-2