Re: [julia-users] Re: Rounding to zero from positive or negative numbers results in positive or negative zero.

2016-04-20 Thread Andrew Gibb
On Wednesday, 20 April 2016 15:18:06 UTC+1, Stefan Karpinski wrote:
>
> IEEE has not made the programming language designer's life easy here.
>

Perhaps it's a subtle attempt to incentivise more designers of mathematical 
programming languages into IEEE standards committees?!

 

>
> On Wed, Apr 20, 2016 at 5:51 AM, Milan Bouchet-Valat  > wrote:
>
>> Le mardi 19 avril 2016 à 22:10 -0700, Jeffrey Sarnoff a écrit :
>> > Hi,
>> >
>> > You have discovered that IEEE standard floating point numbers have
>> > two distinct zeros: 0.0 and -0.0.  They compare `==` even though they
>> > are not `===`.  If you want to consider +0.0 and -0.0 to be the same,
>> > use `==` or `!=` not `===`  or `!==` when testing floating point
>> > values (the other comparisons <=, <, >=, > treat the two zeros as a
>> > single value).
>> There's actually an open issue about what to do with -0.0 and NaN in
>> Dicts: https://github.com/JuliaLang/julia/issues/9381
>>
>> It turns out it's very hard to find a good solution.
>>
>>
>> Regards
>>
>> > > Hello everyone!
>> > > I was wondering if the following behavior of round() has an special
>> > > purpouse:
>> > >
>> > > a = round(0.1)
>> > > 0.0
>> > >
>> > > b = round(-0.1)
>> > > -0.0
>> > >
>> > > a == b
>> > > true
>> > >
>> > > a === b
>> > > false
>> > >
>> > > bits(a)
>> > > ""
>> > >
>> > >
>> > > bits(b)
>> > > "1000"
>> > >
>> > > So the sign stays around...
>> > >
>> > > I am using this rounded numbers as keys in a dictionary and julia
>> > > can tell the difference. 
>> > >
>> > > For example, I expected something like this:
>> > > dict = [i => exp(i) for i in [a,b]]
>> > > Dict{Any,Any} with 1 entry:
>> > >  0.0 => 1.0
>> > >
>> > > but got this:
>> > > dict = [i => exp(i) for i in [a,b]]
>> > > Dict{Any,Any} with 2 entries:
>> > >   0.0  => 1.0
>> > >   -0.0 => 1.0
>> > >
>> > > It is not a big problem really but I would like to know where can
>> > > this behaviour come handy.
>> > >
>> > > Cheers!
>> > >
>>
>
>

Re: [julia-users] Re: Rounding to zero from positive or negative numbers results in positive or negative zero.

2016-04-20 Thread Stefan Karpinski
IEEE has not made the programming language designer's life easy here.

On Wed, Apr 20, 2016 at 5:51 AM, Milan Bouchet-Valat 
wrote:

> Le mardi 19 avril 2016 à 22:10 -0700, Jeffrey Sarnoff a écrit :
> > Hi,
> >
> > You have discovered that IEEE standard floating point numbers have
> > two distinct zeros: 0.0 and -0.0.  They compare `==` even though they
> > are not `===`.  If you want to consider +0.0 and -0.0 to be the same,
> > use `==` or `!=` not `===`  or `!==` when testing floating point
> > values (the other comparisons <=, <, >=, > treat the two zeros as a
> > single value).
> There's actually an open issue about what to do with -0.0 and NaN in
> Dicts: https://github.com/JuliaLang/julia/issues/9381
>
> It turns out it's very hard to find a good solution.
>
>
> Regards
>
> > > Hello everyone!
> > > I was wondering if the following behavior of round() has an special
> > > purpouse:
> > >
> > > a = round(0.1)
> > > 0.0
> > >
> > > b = round(-0.1)
> > > -0.0
> > >
> > > a == b
> > > true
> > >
> > > a === b
> > > false
> > >
> > > bits(a)
> > > ""
> > >
> > >
> > > bits(b)
> > > "1000"
> > >
> > > So the sign stays around...
> > >
> > > I am using this rounded numbers as keys in a dictionary and julia
> > > can tell the difference.
> > >
> > > For example, I expected something like this:
> > > dict = [i => exp(i) for i in [a,b]]
> > > Dict{Any,Any} with 1 entry:
> > >  0.0 => 1.0
> > >
> > > but got this:
> > > dict = [i => exp(i) for i in [a,b]]
> > > Dict{Any,Any} with 2 entries:
> > >   0.0  => 1.0
> > >   -0.0 => 1.0
> > >
> > > It is not a big problem really but I would like to know where can
> > > this behaviour come handy.
> > >
> > > Cheers!
> > >
>


Re: [julia-users] Re: Rounding to zero from positive or negative numbers results in positive or negative zero.

2016-04-20 Thread Milan Bouchet-Valat
Le mardi 19 avril 2016 à 22:10 -0700, Jeffrey Sarnoff a écrit :
> Hi,
> 
> You have discovered that IEEE standard floating point numbers have
> two distinct zeros: 0.0 and -0.0.  They compare `==` even though they
> are not `===`.  If you want to consider +0.0 and -0.0 to be the same,
> use `==` or `!=` not `===`  or `!==` when testing floating point
> values (the other comparisons <=, <, >=, > treat the two zeros as a
> single value).
There's actually an open issue about what to do with -0.0 and NaN in
Dicts: https://github.com/JuliaLang/julia/issues/9381

It turns out it's very hard to find a good solution.


Regards

> > Hello everyone!
> > I was wondering if the following behavior of round() has an special
> > purpouse:
> > 
> > a = round(0.1)
> > 0.0
> > 
> > b = round(-0.1)
> > -0.0
> > 
> > a == b
> > true
> > 
> > a === b
> > false
> > 
> > bits(a)
> > ""
> > 
> > 
> > bits(b)
> > "1000"
> > 
> > So the sign stays around...
> > 
> > I am using this rounded numbers as keys in a dictionary and julia
> > can tell the difference. 
> > 
> > For example, I expected something like this:
> > dict = [i => exp(i) for i in [a,b]]
> > Dict{Any,Any} with 1 entry:
> >  0.0 => 1.0
> > 
> > but got this:
> > dict = [i => exp(i) for i in [a,b]]
> > Dict{Any,Any} with 2 entries:
> >   0.0  => 1.0
> >   -0.0 => 1.0
> > 
> > It is not a big problem really but I would like to know where can
> > this behaviour come handy.
> > 
> > Cheers!
> > 


[julia-users] Re: Rounding to zero from positive or negative numbers results in positive or negative zero.

2016-04-19 Thread Jeffrey Sarnoff
Hi,

You have discovered that IEEE standard floating point numbers have two 
distinct zeros: 0.0 and -0.0.  They compare `==` even though they are not 
`===`.  If you want to consider +0.0 and -0.0 to be the same, use `==` or 
`!=` not `===`  or `!==` when testing floating point values (the other 
comparisons <=, <, >=, > treat the two zeros as a single value).

On Wednesday, April 20, 2016 at 12:18:22 AM UTC-4, Ilya Orson wrote:
>
> Hello everyone!
> I was wondering if the following behavior of round() has an special 
> purpouse:
>
> a = round(0.1)
> 0.0
>
> b = round(-0.1)
> -0.0
>
> a == b
> true
>
> a === b
> false
>
> bits(a)
> ""
>
>
>
> bits(b)
> "1000"
>
> So the sign stays around...
>
> I am using this rounded numbers as keys in a dictionary and julia can tell 
> the difference. 
>
> For example, I expected something like this:
> dict = [i => exp(i) for i in [a,b]]
> Dict{Any,Any} with 1 entry:
>  0.0 => 1.0
>
>
> but got this:
>
> dict = [i => exp(i) for i in [a,b]]
>
> Dict{Any,Any} with 2 entries:
>   0.0  => 1.0
>   -0.0 => 1.0
>
>
> It is not a big problem really but I would like to know where can this 
> behaviour come handy.
>
> Cheers!
>
>