Seems to me that BigDecimal, being essentially a BigInteger numerator and a
power-of-ten denominator, could have been accommodated in Category 1 given
that Ratio could.


On Mon, Jan 27, 2014 at 10:26 AM, Andy Fingerhut
<andy.finger...@gmail.com>wrote:

> As Jim already mentioned, you can use == to compare numbers for equality,
> but you must be cautious with equality for floating point numbers, as the
> tiniest bit of roundoff error will cause = and == to be false for such
> comparisons.
>
> For =, there are effectively 3 'categories' of numeric values in Clojure,
> each of which can be = to each other within a category, but between
> categories values are never = to each other.
>
> Category 1. integer values (including Java Byte, Short, Integer, Long,
> BigInteger, and Clojure BigInt types) and ratio values (Clojure's Ratio
> type)
> Category 2. float and double values (Java Float and Double)
> Category 3. BigDecimal
>
> This is better than Java equals(), where Byte and Short are never equals()
> to each other, etc.  Two numeric values must be the same Java class for
> equals() to be true.
>
> Why the 3 categories, you may wonder?  I didn't design it myself, but my
> best guess is that in order to have a hash function (in this case Clojure's
> hash, implemented as a Java method called hasheq()) that is consistent with
> Clojure =, it is difficult to make such a hash function correct and fast if
> there were not these 3 separate categories.
>
> Andy
>
>
> On Mon, Jan 27, 2014 at 5:39 AM, Eric Le Goff <eleg...@gmail.com> wrote:
>
>> Newbie question :
>>
>> user=> (= 42 42)
>> true
>> user=> (= 42 42.0)
>> false
>>
>> I did not expect last result.
>>
>> I understand that underlying classes are not the same
>> i.e
>> user=> (class 42)
>> java.lang.Long
>> user=> (class 42.0)
>> java.lang.Double
>>
>>
>> but anyway I'am surprised
>>
>> Cheers
>>
>>
>> --
>> Eric
>>
>>  --
>> --
>> 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
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to