I'm struggling with understanding why
(= 1 1.0)
evaluates to false
whereas
(== 1 1.0)
evaluates to true
. According to the docs, ==
seems to be only working on numbers but other than that there doesn't seem much difference. So, what am I missing?
==
checks for mathematical equivalence. =
with numbers checks for equivalence in a way that is agnostic to size where applicable, but is strict about representation:
user> (= (float 1.0) (double 1.0))
true
user> (= (int 1) (byte 1))
true
user> (= (int 1) (double 1))
false
user> (= 0.5 (/ 1 2))
false
user> (== 0.5 (/ 1 2))
true
assumedly, the reasoning is that the representation of floating point can lose precision, and should not be treated as equivalent to integral or exact representations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With