In practice, in most languages, it's uncertain to test for equality between floating point values. This is mainly a side effect of internal representations.
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm It's probably safer to keep things that way. Ints (or longs) are not floating point values. The same issues could arise if we allow cross type equality tests, especially with computed values, giving a false impression of a defined behavior. If you have nearly equal values between an int (or long) and a floating point value, where do round up ? Is it fine to round up the decimals or dropping them because they are "not significant" ? For whom ? How often does a floating point value end up with no decimals following a computation ? The above is a can of worms especially in heavy computation algorithms. If Clojure stays on the most accepted side of the fence, then all the semantic issues that do not respect this must change. I would rather see something like this in the code: (= 3 (long 3.8)) or even better (= 3 (trunc 3.8)) Which clearly states what we want to test. Luc P. On Sun, 2 Oct 2011 14:03:47 -0700 (PDT) Chris Perkins <[email protected]> wrote: > Ok, I follow you now. That makes sense. Sort-of :) > > On the other hand, it's only inconsistent if you consider clojure's = > to map to java's .equals method, but it does not: > > user=> (clojure-version) > "1.2.1" > user=> (= 3 3.0) > true > user=> (.equals 3 3.0) > false > > So it doesn't really violate the contract for java's Map, which tells > us that if a.equals(b), then they must have the same hash, and so a > and b cannot both be keys. If you think of clojure's = as a looser > sort of equivalence, then it's not a problem. I think. > > In any case, the 1.3 behavior does feel weird in sometimes: > > user> (def i 3) > #'user/i > user> (def j 3.0) > #'user/j > user> (< i j) > false > user> (> i j) > false > user> (= i j) > false > > OK, that kind-of freaks me out... :) > > - Chris > > -- Luc P. ================ The rabid Muppet -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
