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


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

Fwd: Re: double == double

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Fwd: Re: double == double
Date 2016-10-19 17:10 -0400
Organization A noiseless patient Spider
Message-ID <nu8nek$mbu$2@dont-email.me> (permalink)
References <md5:/ly77XHCxjkwLJNg81+qIg==>

Show all headers | View raw


(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

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

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

csiph-web