From dev-return-37541-apmail-harmony-dev-archive=harmony.apache.org@harmony.apache.org Wed Jun 24 10:08:55 2009 Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 6865 invoked from network); 24 Jun 2009 10:08:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Jun 2009 10:08:55 -0000 Received: (qmail 3522 invoked by uid 500); 24 Jun 2009 10:09:06 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 3437 invoked by uid 500); 24 Jun 2009 10:09:05 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 3426 invoked by uid 99); 24 Jun 2009 10:09:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jun 2009 10:09:05 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rogers.email@gmail.com designates 209.85.218.217 as permitted sender) Received: from [209.85.218.217] (HELO mail-bw0-f217.google.com) (209.85.218.217) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jun 2009 10:08:56 +0000 Received: by bwz17 with SMTP id 17so625757bwz.36 for ; Wed, 24 Jun 2009 03:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type:content-transfer-encoding; bh=G/oMnCOQuqtS3MUWEUOBLvf1FBH7H35Z9fRbH0D/zlc=; b=iodW/P157MoAADFzl9lb72bUeWLd4jpOn7ihC6mymBJ/wloipCZ60ooP+xHAclIB3I w5VgjNOZp6804lnq3/SCSjyoTygjzpeRzgo3Uk9+no0fhDmEUhiBr5NGdBLLUJHt2eZp xkygMY0wmi69mIgaZSydunz69eOaOFmlT52f8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=SXcjRQel8j/hW7eSVN5wRrjpruS0EKvVk/xCD1PmQiXcP80pnUdhrxQXfA4GdjOmp/ 3lX6bvoRVnuUDotoFWkKMKtd6h7qH5u+CIt/KRL/vzEg/GzQzjBBAyse6C+EZDb6cnRe SSybF4Jl06kRcCzQ7X4hqvYsThFHNKwOOsg80= MIME-Version: 1.0 Sender: rogers.email@gmail.com Received: by 10.204.31.82 with SMTP id x18mr1139914bkc.5.1245838115348; Wed, 24 Jun 2009 03:08:35 -0700 (PDT) In-Reply-To: <4A41F8A0.3070305@gmail.com> References: <1171234563.1245831787326.JavaMail.jira@brutus> <4A41F8A0.3070305@gmail.com> Date: Wed, 24 Jun 2009 11:08:35 +0100 X-Google-Sender-Auth: 107844bb6f1169fa Message-ID: Subject: Re: [luni] Math.max(double, double) gives wrong answer when Math.max(-0.0d, 0.0d) (HARMONY-6242) From: Ian Rogers To: dev@harmony.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 2009/6/24 Tim Ellison : > I love these ;-) > > Ian Rogers (JIRA) wrote: >> Math.max(double, double) gives wrong answer when Math.max(-0.0d, 0.0d) >> ---------------------------------------------------------------------- >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Key: HARMONY-6242 >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0URL: https://issues.apache.org/jira/b= rowse/HARMONY-6242 >> =A0 =A0 =A0 =A0 =A0 =A0 =A0Project: Harmony >> =A0 =A0 =A0 =A0 =A0 Issue Type: Bug >> =A0 =A0 =A0 =A0 =A0 Components: Classlib >> =A0 =A0 Affects Versions: 5.0M10 >> =A0 =A0 =A0 =A0 =A0Environment: Any, my test environment is x64 Linux wi= th MRP (http://mrp.codehaus.org/) >> =A0 =A0 =A0 =A0 =A0 =A0 Reporter: Ian Rogers >> =A0 =A0 =A0 =A0 =A0 =A0 =A0Fix For: 5.0M11 >> >> >> In the code: >> >> public static double max(double d1, double d2) { >> =A0 if (d1 > d2) >> =A0 =A0 return d1; >> =A0 if (d1 < d2) >> =A0 =A0 return d2; >> =A0 /* if either arg is NaN, return NaN */ >> =A0 if (d1 !=3D d2) >> =A0 =A0 return Double.NaN; >> =A0 /* max( +0.0,-0.0) =3D=3D +0.0 */ >> =A0 if (d1 =3D=3D 0.0 && (d1 !=3D -0.0d || d2 !=3D -0.0d)) >> =A0 =A0 return 0.0; >> =A0 return d1; >> } >> >> This test is never true: >> >> =A0 if (d1 =3D=3D 0.0 && (d1 !=3D -0.0d || d2 !=3D -0.0d)) >> >> as 0.0 =3D=3D -0.0 and d2 must be 0.0 or -0.0. This means that in the ca= se of two 0.0 parameters d1 is returned, which is the incorrect behaviour i= f d2 is 0.0 and d1 -0.0. >> >> A simple test: >> >> =A0 =A0 =A0 System.out.println(Math.max(-0.0d, 0.0d)); >> >> prints -0.0 with Harmony and 0.0 with a non-Harmony classlib. >> > > So is the answer to replace the last test with: > > =A0if (Double.doubleToRawLongBits(d1) =3D=3D Double.doubleToRawLongBits(-= 0.0d)) { > =A0 =A0 =A0return d2; > =A0} > =A0return d1; I think there are plenty of ways to write it, you could compare against the raw long bits of d2. In your code you could just return 0.0d rather than d1 at the end which may expose some constant propagation. I was wondering if for Intel SSE there'd be some way to optimize this to use the MAXSS/MAXSD instructions. Regards, Ian > Regards, > Tim >