I'm lost in clojure ratio. I can't understand it. Why do the equality and inequality tests behave this way?
(= 3/2 1.5)
;; false
(>= 3/2 1.5)
;; true
(> 3/2 1.5)
;;false
(not= 3/2 1.5)
;; true
Use ==
for numerical comparisons where you want to know if two numbers represent the same number regardless of types:
user> (= 3/2 1.5)
false
user> (== 3/2 1.5)
true
Though keep in mind that ==
is only for numbers and throws if given something not a number.
user> (== :1 :1)
ClassCastException clojure.lang.Keyword cannot be cast to java.lang.Number clojure.lang.Numbers.equiv (Numbers.java:206)
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