From 5ac0307deb0acdf6ea41c72ad127a95b0c8bae3c Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Sat, 22 Jan 2011 20:26:34 +0000 Subject: [PATCH] Simplify code by using doubleHighPart git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1062258 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math/util/FastMath.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/apache/commons/math/util/FastMath.java b/src/main/java/org/apache/commons/math/util/FastMath.java index 6310608af..5da97fc87 100644 --- a/src/main/java/org/apache/commons/math/util/FastMath.java +++ b/src/main/java/org/apache/commons/math/util/FastMath.java @@ -3205,13 +3205,7 @@ public class FastMath { return Math.PI/2; // so return the appropriate value } - if (abs(r) < Double.MAX_VALUE/HEX_40000000){ // is it safe to split r ? - temp = r * HEX_40000000; - } else { - temp = 0.0; - } - - double ra = r + temp - temp; + double ra = doubleHighPart(r); double rb = r - ra; rb += (y - ra*xa - ra*xb - rb*xa - rb*xb) / x; // Correct for rounding in division @@ -3323,11 +3317,7 @@ public class FastMath { final double facta = 0.01745329052209854; final double factb = 1.997844754509471E-9; - double temp = 0; - if (abs(x) < Double.MAX_VALUE/HEX_40000000) { // prevent overflow to infinity - temp = x * HEX_40000000; - } - double xa = x + temp - temp; + double xa = doubleHighPart(x); double xb = x - xa; double result = xb * factb + xb * facta + xa * factb + xa * facta; @@ -3352,11 +3342,7 @@ public class FastMath { final double facta = 57.2957763671875; final double factb = 3.145894820876798E-6; - double temp = 0; - if (abs(x) < Double.MAX_VALUE/HEX_40000000) { // prevent overflow to infinity - temp = x * HEX_40000000; - } - double xa = x + temp - temp; + double xa = doubleHighPart(x); double xb = x - xa; return xb * factb + xb * facta + xa * factb + xa * facta;