Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: double == double Date: Wed, 19 Oct 2016 21:52:18 -0400 Organization: Aioe.org NNTP Server Lines: 62 Message-ID: References: NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:35842 On 10/19/2016 9:47 PM, Jerry Stuckle wrote: > On 10/19/2016 9:16 PM, Arne Vajhøj wrote: >> On 10/19/2016 7:08 PM, Jake Jarvis wrote: >>> Am 19.10.2016 um 22:50 schrieb Jerry Stuckle: >>>> On 10/19/2016 10:36 AM, Jake Jarvis wrote: >>>>> Am 19.10.2016 um 16:26 schrieb Jerry Stuckle: >>>>>> On 10/19/2016 9:32 AM, Eric Sosman wrote: >>>>>>> On 10/19/2016 9:03 AM, Mike Amling wrote: >>>>>>>> If a==0.0 and b==0.0, there's no need to test whether either is >>>>>>>> -0.0. >>>>>>>> The function could be simplified to >>>>>>>> >>>>>>>> public static double max(final double a, final double b) { >>>>>>>> return a==0.0 && b==0.0 ? 0.0 : (a>=b ? a : b); >>>>>>>> } >>>>>>> >>>>>>> This would return +0.0 for max(-0.0, -0.0). >>>>>>> >>>>>> >>>>>> PMJI, but how do you figure? a==0.0 && b==0.0 would be false >>>>> >>>>> No. >>>>> >>>> >>>> And why not? -0.0 != 0.0. >>>> >>> >>> But exactly that is not the case >>> >>> https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.21.1 >>> >>> | 15.21.1. Numerical Equality Operators == and != >>> | [...] >>> | Floating-point equality testing is performed in accordance with the >>> rules of the IEEE 754 standard: >>> | [...] >>> | Positive zero and negative zero are considered equal. >> >> And just for completeness. >> >> IEEE 754 2008 section 5.11 says: >> >> >> Comparisons shall ignore the sign of zero (so +0 = −0). >> > > So, if that's the case, what does it matter if the operation returns > +0.0 or -0.0? Somebody defined the contract for Math.max so that it have to return -0.0 for (-0.0,-0.0). It has to fulfill that contract. I think they could have made the contract different. But somebody at SUN 20 years ago did not agree. Arne