I'm observing some unexpected floating point behaviour in Elixir.
4.7 / 0.1 = 47.0 (good!)
4.8 / 0.1 = 47.9999999999 (bad!)
4.9 / 0.1 = 49 (good!)
While I understand the limitations of fp accuracy, in this case, the answer just looks wrong.
Curiously, I tried this in python as well, and got the same result, which is even more mysterious. When I changed the format to 4.8 * (1/0.1)
, I get the right answer (48.0).
What is going on here?
This is actually a normal behavior for IEEE 754 floating point numbers, and unrelated to erlang/elixir. Python or Nodejs would return the same thing.
For more information, you can read this detailed explanation.