# Negative infinity and positive infinity have the same sign

9 messages
Open this post in threaded view
|

## Negative infinity and positive infinity have the same sign

 On 3.3.0, "-0.0 sign = 0.0 sign". On Pharo, "-1 sign = -1", "-0.0 sign = -1", "0.0 sign = 0", and "1 sign = 1". IEEE Standard 754 mandates that negative zero have the same sign bit as a negative number. _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass
Open this post in threaded view
|

## Re: Negative infinity and positive infinity have the same sign

 Thanks Monty, I've submitted internal bug #46646 "Negative infinity and positive infinity have the same sign (IEEE Standard 754)". If you need a patch, the following topaz script should help: method: Float sign | s | s := self _sign . self = 0.0 ifTrue:[ s == 1 ifTrue:[ ^ 0]]. ^ s % Dale On 01/25/2017 12:45 PM, monty via Glass wrote: > On 3.3.0, "-0.0 sign = 0.0 sign". On Pharo, "-1 sign = -1", "-0.0 sign = -1", "0.0 sign = 0", and "1 sign = 1". IEEE Standard 754 mandates that negative zero have the same sign bit as a negative number. > _______________________________________________ > Glass mailing list > [hidden email] > http://lists.gemtalksystems.com/mailman/listinfo/glass_______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass
Open this post in threaded view
|

## Re: Negative infinity and positive infinity have the same sign

 In reply to this post by GLASS mailing list On 01/25/2017 12:45 PM, monty via Glass wrote: > On 3.3.0, "-0.0 sign = 0.0 sign". On Pharo, "-1 sign = -1", "-0.0 sign = -1", "0.0 sign = 0", and "1 sign = 1". IEEE Standard 754 mandates that negative zero have the same sign bit as a negative number. > _______________________________________________ Hi Monty, The ANSI Smalltalk standard says that #sign should answer 0 if "the receiver equals zero". This agrees with ISO/IEC 10967 Portable Numerics standard, which says the same thing. The IEEE 754 spec does not specify a "sign" operation. The closest equivalent I see is the "isSignMinus" operation. We don't currently have that message in GemStone, but we might add it. In GemStone, you can distinguish positive and negative zero by sending #_sign. Pharo's implementation seems very odd. It looks like it's been that way a long time (John Maloney in 1998?) but the comment contradicts itself. It says "Answer 1 if the receiver is greater than 0, -1 if less than 0, else 0.     Handle IEEE-754 negative-zero by reporting a sign of -1" But negative zero *is* equal to 0, so it claims to be answering both 0 and -1 for -0.0. Leaving that aside, it's disturbingly asymmetric to answer 0 for 0.0 but -1 for -0.0. Regards, -Martin _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass
Open this post in threaded view
|

## Re: Negative infinity and positive infinity have the same sign

 Looks like you're correct; Pharo has the bug, not GS. All I really wanted was to distinguish +/- 0, so your fix will do. But be aware that ANSI Smalltalk also defines #negated in terms of ISO 10967's 'neg', which returns -0.0 for 0.0 and 0.0 for -1.0, so #sign or other such disparities between +/- 0 are not obviously wrong. > Sent: Thursday, January 26, 2017 at 3:10 PM > From: "Martin McClure" <[hidden email]> > To: monty <[hidden email]>, [hidden email] > Subject: Re: [Glass] Negative infinity and positive infinity have the same sign > > On 01/25/2017 12:45 PM, monty via Glass wrote: > > On 3.3.0, "-0.0 sign = 0.0 sign". On Pharo, "-1 sign = -1", "-0.0 sign = -1", "0.0 sign = 0", and "1 sign = 1". IEEE Standard 754 mandates that negative zero have the same sign bit as a negative number. > > _______________________________________________ > Hi Monty, > > The ANSI Smalltalk standard says that #sign should answer 0 if "the > receiver equals zero". This agrees with ISO/IEC 10967 Portable Numerics > standard, which says the same thing. The IEEE 754 spec does not specify > a "sign" operation. The closest equivalent I see is the "isSignMinus" > operation. We don't currently have that message in GemStone, but we > might add it. In GemStone, you can distinguish positive and negative > zero by sending #_sign. > > Pharo's implementation seems very odd. It looks like it's been that way > a long time (John Maloney in 1998?) but the comment contradicts itself. > It says > "Answer 1 if the receiver is greater than 0, -1 if less than 0, else 0. >     Handle IEEE-754 negative-zero by reporting a sign of -1" > > But negative zero *is* equal to 0, so it claims to be answering both 0 > and -1 for -0.0. Leaving that aside, it's disturbingly asymmetric to > answer 0 for 0.0 but -1 for -0.0. > > Regards, > > -Martin > _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass
Open this post in threaded view
|

## Re: Negative infinity and positive infinity have the same sign

 On 01/26/2017 06:16 PM, monty via Glass wrote: > Looks like you're correct; Pharo has the bug, not GS. All I really wanted was to distinguish +/- 0, so your fix will do. But be aware that ANSI Smalltalk also defines #negated in terms of ISO 10967's 'neg', which returns -0.0 for 0.0 and 0.0 for -1.0, so #sign or other such disparities between +/- 0 are not obviously wrong. > I agree, and we do handle #negated correctly, AFAICT. We welcome reports if you find any place where we do not do things correctly -- we made an effort to clean up the finer points of numerics several years ago, but it's always possible we missed something. Regards, -Martin _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass
Open this post in threaded view
|

## Re: Negative infinity and positive infinity have the same sign

 In reply to this post by GLASS mailing list Apparently there is also #signBit, which works for SmallFloats too, and because SmallDouble is immediate, you can also use #== with -0.0 after sending #asFloat (to convert non-floats, SmallFloats, and DecimalFloats). The only backwards compatible approach I found for Pharo/Squeak is to use #at: on a zero float to test if its first (big-endian) word is non-zero. > Sent: Thursday, January 26, 2017 at 3:10 PM > From: "Martin McClure" <[hidden email]> > To: monty <[hidden email]>, [hidden email] > Subject: Re: [Glass] Negative infinity and positive infinity have the same sign > > On 01/25/2017 12:45 PM, monty via Glass wrote: > > On 3.3.0, "-0.0 sign = 0.0 sign". On Pharo, "-1 sign = -1", "-0.0 sign = -1", "0.0 sign = 0", and "1 sign = 1". IEEE Standard 754 mandates that negative zero have the same sign bit as a negative number. > > _______________________________________________ > Hi Monty, > > The ANSI Smalltalk standard says that #sign should answer 0 if "the > receiver equals zero". This agrees with ISO/IEC 10967 Portable Numerics > standard, which says the same thing. The IEEE 754 spec does not specify > a "sign" operation. The closest equivalent I see is the "isSignMinus" > operation. We don't currently have that message in GemStone, but we > might add it. In GemStone, you can distinguish positive and negative > zero by sending #_sign. > > Pharo's implementation seems very odd. It looks like it's been that way > a long time (John Maloney in 1998?) but the comment contradicts itself. > It says > "Answer 1 if the receiver is greater than 0, -1 if less than 0, else 0. >     Handle IEEE-754 negative-zero by reporting a sign of -1" > > But negative zero *is* equal to 0, so it claims to be answering both 0 > and -1 for -0.0. Leaving that aside, it's disturbingly asymmetric to > answer 0 for 0.0 but -1 for -0.0. > > Regards, > > -Martin > _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass
Open this post in threaded view
|

## Re: Negative infinity and positive infinity have the same sign

 In reply to this post by GLASS mailing list Thanks Dale and Martin for your help. _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass