I was just about to post this result, which I don't understand. Why should

0.0 == -0.0

but bar(0.0) != bar(-0.0) when bar is immutable? (yes, you can override == 
for this to be ==(x::bar, y::bar) = x.a == y.a, but that seems as if it 
should be unnecessary.)


On Monday, December 7, 2015 at 5:14:28 PM UTC-8, Yichao Yu wrote:
>
> On Mon, Dec 7, 2015 at 7:01 PM, Davide Lasagna <[email protected] 
> <javascript:>> wrote: 
> > Cool! Thanks 
>
> Also note that since your type is mutable, the default `==` is object 
> identity and your `a` and `b` won't equal even if their content are 
> the same by default. An `immutable` type will compare the content by 
> default (although `-0.0` and `0.0` have different bit pattern and 
> won't equal as a field by default as you pointed out). 
>
> ``` 
> julia> type foo 
>            a::Float64 
>        end 
>
> julia> b = foo(0) 
> foo(0.0) 
>
> julia> a = foo(0) 
> foo(0.0) 
>
> julia> a == b 
> false 
>
> julia> immutable bar 
>            a::Float64 
>        end 
>
> julia> b = bar(0) 
> bar(0.0) 
>
> julia> a = bar(0) 
> bar(0.0) 
>
> julia> a == b 
> true 
>
> julia> bar(0.0) == bar(-0.0) 
> false 
> ``` 
>

Reply via email to