There are some very well known problems with floating-point numbers and
arithmetics due to the fact most decimal fractions cannot be represented by a
floating-point binary and most operations are not exact, but operate on
approximations. Those issues are not specific to Elixir, they are a property of
floating point representation itself.
For example, the numbers 0.1 and 0.01 are two of them, what means the result of
squaring 0.1 does not give 0.01 neither the closest representable. Here is what
happens in this case:
• The closest representable number to 0.1 is 0.1000000014
• The closest representable number to 0.01 is 0.0099999997
• Doing 0.1 * 0.1 should return 0.01, but because 0.1 is actually
0.1000000014, the result is 0.010000000000000002, and because this is not
the closest representable number to 0.01, you’ll get the wrong result for
this operation
There are also other known problems like flooring or rounding numbers. See
round/2 and floor/2 for more details about them.
To learn more about floating-point arithmetic visit: