From ce9c345ef7cb1ded723daa5bb2764b8d2933abfd Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Tue, 26 Mar 2013 19:48:08 +0000 Subject: [PATCH] Replaced mask constant by explicit local constants. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1461283 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/commons/math3/util/FastMath.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/util/FastMath.java b/src/main/java/org/apache/commons/math3/util/FastMath.java index 7b7b5b386..b4bcfbdbe 100644 --- a/src/main/java/org/apache/commons/math3/util/FastMath.java +++ b/src/main/java/org/apache/commons/math3/util/FastMath.java @@ -307,6 +307,12 @@ public class FastMath { /** Mask used to clear low order 30 bits */ private static final long MASK_30BITS = -1L - (HEX_40000000 -1); // 0xFFFFFFFFC0000000L; + /** Mask used to clear the non-sign part of an int. */ + private static final int MASK_NON_SIGN_INT = 0x7fffffff; + + /** Mask used to clear the non-sign part of a long. */ + private static final long MASK_NON_SIGN_LONG = 0x7fffffffffffffffl; + /** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite */ private static final double TWO_POWER_52 = 4503599627370496.0; /** 2^53 - double numbers this large must be even. */ @@ -3011,7 +3017,7 @@ public class FastMath { * @return abs(x) */ public static float abs(final float x) { - return Float.intBitsToFloat(Integer.MAX_VALUE & Float.floatToRawIntBits(x)); + return Float.intBitsToFloat(MASK_NON_SIGN_INT & Float.floatToRawIntBits(x)); } /** @@ -3020,7 +3026,7 @@ public class FastMath { * @return abs(x) */ public static double abs(double x) { - return Double.longBitsToDouble(Long.MAX_VALUE & Double.doubleToRawLongBits(x)); + return Double.longBitsToDouble(MASK_NON_SIGN_LONG & Double.doubleToRawLongBits(x)); } /**