I'd also like to make sure people are aware of this oddity.  I discovered 
this after reading an article about the bad design of PHP.  I read that in 
PHP, "== is not transitive."  I thought "Ha ha ha, that ridiculous PHP!"

Then I checked c.c/== ;  Imagine my reaction when I learned that Clojure 
had something in common with PHP.  o_O,  :'[
Other emoticons also washed over me.

In summary, beware when comparing different numeric types, and don't throw 
stones even if your house is made of bricks, because the windows are still 
glass.

On Friday, September 2, 2011 12:50:45 PM UTC-7, Patrick Houk wrote:
>
> Greetings, 
>
> I think that I've encountered a bug in ==. 
>
> user=> (and (== 1 1.0) (== 1.0 1.0M) (not (== 1 1.0M))) 
> true 
>
> This happens with 1.2.1 and 1.3-beta2.  I think it has to do with the 
> precision of the BigDecimal. 
>
> user=> (== 1 1.0M) 
> false 
> user=> (== 1 1M) 
> true 
>
> I think a solution would be to use BigDecimal#compareTo (or maybe 
> BigDecimal#stripTrailingZeros) in ==, so that (== 1M 1.0M) becomes 
> true.  (I would expect (= 1M 1.0M) to remain false, though.) 
>
> Thanks, 
> - Pat 
>

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