Why does Clojure/REPL treat a a float and integral representation of same number different?
clojure
Solution
They are not if the same type.
Note how java's `equal` also retuns false:
> (.equals 3.0 3)
false
or consider the following java programm:
public static void main(String []args){
Integer i = 1000;
System.out.println(i.equals(1000.0));
System.out.println(i==1000.0);
}
Output:
false true
There's a difference between the `=` and the `==` function
=
Equality. Returns true if x equals y, false if not. Same as Java x.equals(y)...
so if you want to compare the values of the nums, use `==`
==
Returns non-nil if nums all have the equivalent value (type-independent), otherwise false
Problem
In Clojure, I wrote a simple function kept debugging only to realize in the end that. ``` (= 3 3) ``` is `true` BUT ``` (= 3.0 3) ``` is `false` Why? I know that there are problems with floating point arithmetic where one should not directly compare two floating point values. Even in Java, 3.0 and 3 will be equal and probably lot of other languages.