On Tuesday, October 9, 2012 2:27:43 PM UTC-7, Aaron Cohen wrote:
>
> On Tue, Oct 9, 2012 at 5:20 PM, David Nolen 
> <[email protected]<javascript:>> 
> wrote: 
> > On Tue, Oct 9, 2012 at 4:38 PM, Brian Craft 
> > <[email protected]<javascript:>> 
> wrote: 
> >> Can someone explain the last result here? 
> >> 
> >>> [1 2 3 Float/NaN] 
> >> [1 2 3 NaN] 
> >>> (= Float/NaN Float/NaN) 
> >> false 
>
> This is a primitive comparison and follows IEEE floating point 
> semantics. NaN must not equal NaN. 
>
> >> ; all is good so far, but... 
> >> (filter #(= % %) [1 2 3 Float/NaN 4]) 
> >> (1 2 3 NaN 4) 
>
> This is an Object comparison, and in Java this follows the contract 
> for equals and hashCode. Thus, an object must be equal to itself (for 
> HashMap to work). 
>
> See: 
> http://stackoverflow.com/questions/1408569/why-does-double-nan-equal-itself-when-wrapped-in-a-double-instance
>  
>
> and in particular: 
>
> http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#equals(java.lang.Object)
>  
>


Thanks for the explanation. I notice by experimentation that == behaves as 
I would expect. I haven't actually found == in the docs. Only =. 

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

Reply via email to