issues with equality with scientific notation
Closed this issue · 2 comments
2100 == 2.1e3
true
MapDiff.diff(%{a: 2100}, %{a: 2.1e3})
%{added: %{a: 2.1e3}, changed: :map_change, removed: %{a: 2100},
value: %{a: %{added: 2.1e3, changed: :primitive_change, removed: 2100}}}
Thank you for posting this issue!
MapDiff is working as expected in this situation: The problem here, is that 2100
is an integer, while 2.1e3
is a floating point number. While they are equal (which you can check for using ==
), they are not identical (which you can check for using ===
).
If you want all numbers to be the same and are using some floating point numbers, I'd suggest you cast all your input numbers to float before running MapDiff on it.
And if you need more precision than provided by floats, you might want to use the decimal library instead.
Feel free to let me know if there are any other questions :-)