On Oct 12, 12:50 pm, David Sletten <da...@bosatsu.net> wrote: > This discussion may > help:http://www.gettingclojure.com/cookbook:numbers#comparing-floats
I originally tried something like float= described in the link, I give the definition here (defn float= ([x y] (float= x y 0.00001)) ([x y epsilon] (let [scale (if (or (zero? x) (zero? y)) 1 (Math/abs x))] (<= (Math/abs (- x y)) (* scale epsilon)))) ) And the truth-table that was given with the function definition: (float= 0.01 0.0) => false (float= 0.001 0.0) => false (float= 0.0001 0.0) => false (float= 0.00001 0.0) => true And this works for the problem that I discussed before user=> (float= 0.0001 (- 12.305 12.3049)) true But I can come up with a use case where it fails: user=> (float= 12.3049 12.305) true The problem is that the IEEE specification does a great job of comparing floats, but does a crap job of doing simple math on them. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en