Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35830 > unrolled thread

Fwd: Re: double == double

Started byEric Sosman <esosman@comcast-dot-net.invalid>
First post2016-10-19 17:10 -0400
Last post2016-10-21 19:53 +0200
Articles 6 — 3 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Fwd: Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-19 17:10 -0400
    Re: Fwd: Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-19 21:30 -0400
      Re: Fwd: Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-20 07:54 -0400
    Re: Fwd: Re: double == double Michael Jung <miju@golem.phantasia.org> - 2016-10-20 20:59 +0200
      Re: Fwd: Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-20 15:37 -0400
        Re: Fwd: Re: double == double Michael Jung <miju@golem.phantasia.org> - 2016-10-21 19:53 +0200

#35830 — Fwd: Re: double == double

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-10-19 17:10 -0400
SubjectFwd: Re: double == double
Message-ID<nu8nek$mbu$2@dont-email.me>
(Re-sending because the first try seems to have gotten lost.
Sorry if this is a duplicate.)

On 10/19/2016 1:39 PM, Michael Jung wrote:
> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>> On 10/19/2016 9:03 AM, Mike Amling wrote:
>>> public static double max(final double a, final double b) {
>>>   return a==0.0 && b==0.0 ? 0.0 : (a>=b ? a : b);
>>> }
> or
>
> public static double max(final double a, final double b) {
>   return a>=b ? a : b;
> }
>
>>     This would return +0.0 for max(-0.0, -0.0).
>
> Why would that be wrong?

     Although Stefan Ram didn't provide a precise specification,
his code was clearly taken from java.lang.Math.max, whose spec
says, in part

	"[...] If the arguments have the same value, the result is that
	same value. [...]"

Perhaps I should not have assumed that Stefan's hand-waving spec was
supposed to be the same as that of the code he cribbed -- but if it
*is* supposed to behave like Math.max then it should return -0 if
both arguments are -0.

     (Another point: Your one-liner doesn't handle NaN the way Math.max
does -- but then again, neither does Stefan's code, because he snipped
that part of the original.)

     (A final point: All this argument over the sign of nothing leaves
me, I confess, a bit perplexed.  However, those with more numerical
sophistication find the distinction between +0 and -0 to be of great
practical importance.  William Kahan is particularly vehement on the
topic; look for his presentation titled "Branch Cuts for Complex
Elementary Functions or Much Ado About Nothing's Sign Bit," and
bring more mathematical prowess to your reading than I can. :)

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [next] | [standalone]


#35836

FromArne Vajhøj <arne@vajhoej.dk>
Date2016-10-19 21:30 -0400
Message-ID<nu96n0$eqr$1@gioia.aioe.org>
In reply to#35830
On 10/19/2016 5:10 PM, Eric Sosman wrote:
>     (A final point: All this argument over the sign of nothing leaves
> me, I confess, a bit perplexed.  However, those with more numerical
> sophistication find the distinction between +0 and -0 to be of great
> practical importance.  William Kahan is particularly vehement on the
> topic; look for his presentation titled "Branch Cuts for Complex
> Elementary Functions or Much Ado About Nothing's Sign Bit," and
> bring more mathematical prowess to your reading than I can. :)

With the specification for operations then I don't think the
existence of -0.0 has much impact on practical programming.

Ones complement with not special handling (like in old CDC Cyber)
is a PITA and resulting in weird code like adding zero to an integer
before comparing to zero to convert -0 to +0.

Arne

[toc] | [prev] | [next] | [standalone]


#35847

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-10-20 07:54 -0400
Message-ID<nuab8i$s04$1@dont-email.me>
In reply to#35836
On 10/19/2016 9:30 PM, Arne Vajhøj wrote:
> On 10/19/2016 5:10 PM, Eric Sosman wrote:
>>     (A final point: All this argument over the sign of nothing leaves
>> me, I confess, a bit perplexed.  However, those with more numerical
>> sophistication find the distinction between +0 and -0 to be of great
>> practical importance.  William Kahan is particularly vehement on the
>> topic; look for his presentation titled "Branch Cuts for Complex
>> Elementary Functions or Much Ado About Nothing's Sign Bit," and
>> bring more mathematical prowess to your reading than I can. :)
>
> With the specification for operations then I don't think the
> existence of -0.0 has much impact on practical programming.

     Kahan ("the primary architect behind the IEEE 754-1985 standard
for floating-point computation" -- Wikipedia) disagrees.  Since he
knows a whale of a lot more about numerical computation than I ever
will, I'm inclined to take his word for it.

     (He's no fan of Java, by the way.  Look for his presentation
"How JAVA's Floating-Point Hurts Everyone Everywhere."  It starts
out rather calmly but develops into what sounds like a rant -- but
by that time its mathematics is so far above me that rantingness
may just be a figment of my lack of imagination.)

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#35855

FromMichael Jung <miju@golem.phantasia.org>
Date2016-10-20 20:59 +0200
Message-ID<87insmj18o.fsf@golem.phantasia.org>
In reply to#35830
Eric Sosman <esosman@comcast-dot-net.invalid> writes:
> On 10/19/2016 1:39 PM, Michael Jung wrote:
>> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>>> On 10/19/2016 9:03 AM, Mike Amling wrote:
[...]

max has the weird distinction between +0, -0, min doesn't, now that's
weird.

>     (A final point: All this argument over the sign of nothing leaves
> me, I confess, a bit perplexed.  However, those with more numerical
> sophistication find the distinction between +0 and -0 to be of great
> practical importance.  William Kahan is particularly vehement on the
> topic; look for his presentation titled "Branch Cuts for Complex
> Elementary Functions or Much Ado About Nothing's Sign Bit," and
> bring more mathematical prowess to your reading than I can. :)

max is not a complex elementary function. sin would be, but I doubt sin
makes the distinction of +0 and -0 (in fact, it looks like this is OS
dependent).

Michael

[toc] | [prev] | [next] | [standalone]


#35856

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-10-20 15:37 -0400
Message-ID<nub6da$4vd$1@dont-email.me>
In reply to#35855
On 10/20/2016 2:59 PM, Michael Jung wrote:
> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>> On 10/19/2016 1:39 PM, Michael Jung wrote:
>>> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>>>> On 10/19/2016 9:03 AM, Mike Amling wrote:
> [...]
>
> max has the weird distinction between +0, -0, min doesn't, now that's
> weird.

     Hmmm?  Math.min promises to treat -0 as "less than" +0, and says
that min(+0.0, -0.0) will be -0.0.

>>     (A final point: All this argument over the sign of nothing leaves
>> me, I confess, a bit perplexed.  However, those with more numerical
>> sophistication find the distinction between +0 and -0 to be of great
>> practical importance.  William Kahan is particularly vehement on the
>> topic; look for his presentation titled "Branch Cuts for Complex
>> Elementary Functions or Much Ado About Nothing's Sign Bit," and
>> bring more mathematical prowess to your reading than I can. :)
>
> max is not a complex elementary function. sin would be, but I doubt sin
> makes the distinction of +0 and -0 (in fact, it looks like this is OS
> dependent).

     I've already admitted my inability to follow all of Prof. Kahan's
argument, but I think he considers the distinction between -0 and +0
to be essential when one tries to *implement* certain functions.  He's
almost virulent about Fortran's approach to complex quantities, and was
horrified to learn that the Javafolk were thinking about adopting it.
(It seems they dropped the matter; I don't know whether Kahan's
opposition influenced their decision.)

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#35859

FromMichael Jung <miju@golem.phantasia.org>
Date2016-10-21 19:53 +0200
Message-ID<8760ol1tco.fsf@golem.phantasia.org>
In reply to#35856
Eric Sosman <esosman@comcast-dot-net.invalid> writes:
> On 10/20/2016 2:59 PM, Michael Jung wrote:
>> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>>> On 10/19/2016 1:39 PM, Michael Jung wrote:
>>>> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>>>>> On 10/19/2016 9:03 AM, Mike Amling wrote:
>> [...]
>> max has the weird distinction between +0, -0, min doesn't, now that's
>> weird.
>     Hmmm?  Math.min promises to treat -0 as "less than" +0, and says
> that min(+0.0, -0.0) will be -0.0.

You are right. I must have stumbled over the int or long version of min.

Michael

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web