Returns non-nil if nums all have the equivalent value (type-independent), otherwise false
;; true: (== 1) (== 1 1) (== 1/1, 2/2, 3/3, 4/4) (== 1, 1.0, 1/1) (== :foo) ;; false: (== 1 2) ;; ClassCastException (== 1 \1) (== 1 "1")
;; Just what you would expect (== 2.0 1.9999999) ;;=> false ;; a suprising result (== 2.0 2 6/3 1.9999999999999999) ;;=> true ??!? ;; Yes, there is some rounding off going on. ;; if you take off just one of the repeating 9 (on my machine) these compare.
;; When floating point numbers are far enough from each other (== 2.0 1.9999999) ;;=> false (- 100.0 100.00000000000001) ;13(Thirteen) 0s after floating point in the last number ;;=> -1.4210854715202004E-14 ;; When two floating point numbers are too close some basic algebraic properties don't strictly hold. (== 2.0 1.9999999999999999) ;;=> true (* 100 (- 1.0 1.0000000000000001)) ;15(fifteen) 0s after floating point in the last number ;;=> 0.0 ;; They are still different types (= 2 1.9999999999999999) ;;=> false ;; see more from https://wikibooks.cn/wiki/Floating_Point/Epsilon ;; I found above example was distracting by putting 6/3 and 2 in the equality check that is why I decided to write up a similar but new example.
;; See the Clojure Equality guide for more details: ;; https://clojure.org/guides/equality ;; == returns false whenever comparing the special "not a number" value to any ;; number, including itself. user=> (== 1 ##NaN) false ;; this result you probably expect user=> (== ##NaN ##NaN) false ;; this one may surprise you
Equality. Returns true if x equals y, false if not. Same as Java x.equals(y) except it also works ...
Comparator. Returns a negative number, zero, or a positive number when x is logically 'less than',...
There is a difference between "=" and "==". For primitives you definitely want to use "==" as "=" will result in a cast to the wrapped types for it's arguments.
This may not be the case come Clojure 1.3 (see [1])
[1] http://github.com/clojure/clojure/commit/df8c65a286e90e93972bb69392bc106128427dde