Welcome to floating point math.

As an alternative, try using arbitrary-precision numerics:
user=> (- 12.305M 12.3049M)
0.0001M
user=> (type *1)
java.math.BigDecimal



On Oct 12, 9:17 am, cej38 <junkerme...@gmail.com> wrote:
> I keep running into this type of problem:
>
> user=> (- 12.305 12.3049)
> 9.999999999976694E-5
>
> The computer (probably the JVM) has just lied to me.  Any fourth grade
> student will know that this does not equal 0.0001.  This would be less
> of a problem is the JVM was consistent; if it were consistent then the
> following equality would be true:
>
> user=> (= 0.0001 (- 12.305 12.3049))
> false
>
> Now it has lied to me again!
>
> I need a method to reliably compare two numbers.  My first choice
> would be to have the JVM compute (- 12.305 12.3049) correctly.
> Barring that, I need a way to, without fail, compute the truthfulness
> of the following: =, <, >, <=, >=.

-- 
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

Reply via email to