Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AB27018BBE for ; Thu, 10 Sep 2015 09:13:26 +0000 (UTC) Received: (qmail 91142 invoked by uid 500); 10 Sep 2015 09:13:26 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 91019 invoked by uid 500); 10 Sep 2015 09:13:26 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 90877 invoked by uid 99); 10 Sep 2015 09:13:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2015 09:13:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 06F5EE0231; Thu, 10 Sep 2015 09:13:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: luc@apache.org To: commits@commons.apache.org Date: Thu, 10 Sep 2015 09:13:25 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] [math] Fixed infinite loop in FastMath.pow(double, long) with Long.MIN_VALUE. Repository: commons-math Updated Branches: refs/heads/master 941b13f8e -> d93c95d53 Fixed infinite loop in FastMath.pow(double, long) with Long.MIN_VALUE. JIRA: MATH-1272 Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/26e878ab Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/26e878ab Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/26e878ab Branch: refs/heads/master Commit: 26e878ab3a5b0844e09ce305fa07eb2d0ad93d41 Parents: 941b13f Author: Luc Maisonobe Authored: Thu Sep 10 09:49:05 2015 +0200 Committer: Luc Maisonobe Committed: Thu Sep 10 10:34:08 2015 +0200 ---------------------------------------------------------------------- src/changes/changes.xml | 3 +++ src/main/java/org/apache/commons/math4/util/FastMath.java | 4 ++-- src/test/java/org/apache/commons/math4/util/FastMathTest.java | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/26e878ab/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 91f3b24..443c5ce 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces! + + Fixed infinite loop in FastMath.pow(double, long) with Long.MIN_VALUE. + Fixed split/side inconsistencies in BSP trees. http://git-wip-us.apache.org/repos/asf/commons-math/blob/26e878ab/src/main/java/org/apache/commons/math4/util/FastMath.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math4/util/FastMath.java b/src/main/java/org/apache/commons/math4/util/FastMath.java index a4a9a1b..46c8752 100644 --- a/src/main/java/org/apache/commons/math4/util/FastMath.java +++ b/src/main/java/org/apache/commons/math4/util/FastMath.java @@ -1711,7 +1711,7 @@ public class FastMath { } /** Computes this^e. - * @param e exponent (beware, here it MUST be > 0) + * @param e exponent (beware, here it MUST be > 0; the only exclusion is Long.MIN_VALUE) * @return d^e, split in high and low bits * @since 4.0 */ @@ -1723,7 +1723,7 @@ public class FastMath { // d^(2p) Split d2p = new Split(full, high, low); - for (long p = e; p != 0; p >>= 1) { + for (long p = e; p != 0; p >>>= 1) { if ((p & 0x1) != 0) { // accurate multiplication result = result * d^(2p) using Veltkamp TwoProduct algorithm http://git-wip-us.apache.org/repos/asf/commons-math/blob/26e878ab/src/test/java/org/apache/commons/math4/util/FastMathTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/util/FastMathTest.java b/src/test/java/org/apache/commons/math4/util/FastMathTest.java index b95deba..bccd0e8 100644 --- a/src/test/java/org/apache/commons/math4/util/FastMathTest.java +++ b/src/test/java/org/apache/commons/math4/util/FastMathTest.java @@ -1232,6 +1232,11 @@ public class FastMathTest { Assert.assertTrue(Double.isInfinite(FastMath.pow(FastMath.scalb(1.0, 500), 4))); } + @Test(timeout=5000L) // This test must finish in finite time. + public void testIntPowLongMinValue() { + Assert.assertEquals(1.0, FastMath.pow(1.0, Long.MIN_VALUE), -1.0); + } + @Test public void testIncrementExactInt() { int[] specialValues = new int[] {