--- a/jdk/src/share/classes/java/lang/Double.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/java/lang/Double.java Sun Sep 18 18:14:07 2011 -0700
@@ -283,7 +283,7 @@
// Initialized to maximum size of output.
StringBuffer answer = new StringBuffer(24);
- if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
+ if (Math.copySign(1.0, d) == -1.0) // value is negative,
answer.append("-"); // so append sign info
answer.append("0x");
@@ -322,7 +322,7 @@
// E_min -1).
answer.append("p" + (subnormal ?
DoubleConsts.MIN_EXPONENT:
- FpUtils.getExponent(d) ));
+ Math.getExponent(d) ));
}
return answer.toString();
}
--- a/jdk/src/share/classes/java/lang/Float.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/java/lang/Float.java Sun Sep 18 18:14:07 2011 -0700
@@ -26,7 +26,6 @@
package java.lang;
import sun.misc.FloatingDecimal;
-import sun.misc.FpUtils;
import sun.misc.FloatConsts;
import sun.misc.DoubleConsts;
@@ -279,10 +278,10 @@
// Adjust exponent to create subnormal double, then
// replace subnormal double exponent with subnormal float
// exponent
- String s = Double.toHexString(FpUtils.scalb((double)f,
- /* -1022+126 */
- DoubleConsts.MIN_EXPONENT-
- FloatConsts.MIN_EXPONENT));
+ String s = Double.toHexString(Math.scalb((double)f,
+ /* -1022+126 */
+ DoubleConsts.MIN_EXPONENT-
+ FloatConsts.MIN_EXPONENT));
return s.replaceFirst("p-1022$", "p-126");
}
else // double string will be the same as float string
--- a/jdk/src/share/classes/java/lang/Math.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/java/lang/Math.java Sun Sep 18 18:14:07 2011 -0700
@@ -26,6 +26,8 @@
package java.lang;
import java.util.Random;
+import sun.misc.FloatConsts;
+import sun.misc.DoubleConsts;
/**
* The class {@code Math} contains methods for performing basic
@@ -963,7 +965,31 @@
* @since 1.5
*/
public static double ulp(double d) {
- return sun.misc.FpUtils.ulp(d);
+ int exp = getExponent(d);
+
+ switch(exp) {
+ case DoubleConsts.MAX_EXPONENT+1: // NaN or infinity
+ return Math.abs(d);
+
+ case DoubleConsts.MIN_EXPONENT-1: // zero or subnormal
+ return Double.MIN_VALUE;
+
+ default:
+ assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT;
+
+ // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
+ exp = exp - (DoubleConsts.SIGNIFICAND_WIDTH-1);
+ if (exp >= DoubleConsts.MIN_EXPONENT) {
+ return powerOfTwoD(exp);
+ }
+ else {
+ // return a subnormal result; left shift integer
+ // representation of Double.MIN_VALUE appropriate
+ // number of positions
+ return Double.longBitsToDouble(1L <<
+ (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) ));
+ }
+ }
}
/**
@@ -990,7 +1016,31 @@
* @since 1.5
*/
public static float ulp(float f) {
- return sun.misc.FpUtils.ulp(f);
+ int exp = getExponent(f);
+
+ switch(exp) {
+ case FloatConsts.MAX_EXPONENT+1: // NaN or infinity
+ return Math.abs(f);
+
+ case FloatConsts.MIN_EXPONENT-1: // zero or subnormal
+ return FloatConsts.MIN_VALUE;
+
+ default:
+ assert exp <= FloatConsts.MAX_EXPONENT && exp >= FloatConsts.MIN_EXPONENT;
+
+ // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
+ exp = exp - (FloatConsts.SIGNIFICAND_WIDTH-1);
+ if (exp >= FloatConsts.MIN_EXPONENT) {
+ return powerOfTwoF(exp);
+ }
+ else {
+ // return a subnormal result; left shift integer
+ // representation of FloatConsts.MIN_VALUE appropriate
+ // number of positions
+ return Float.intBitsToFloat(1 <<
+ (exp - (FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1)) ));
+ }
+ }
}
/**
@@ -1011,7 +1061,7 @@
* @since 1.5
*/
public static double signum(double d) {
- return sun.misc.FpUtils.signum(d);
+ return (d == 0.0 || Double.isNaN(d))?d:copySign(1.0, d);
}
/**
@@ -1032,7 +1082,7 @@
* @since 1.5
*/
public static float signum(float f) {
- return sun.misc.FpUtils.signum(f);
+ return (f == 0.0f || Float.isNaN(f))?f:copySign(1.0f, f);
}
/**
@@ -1252,7 +1302,11 @@
* @since 1.6
*/
public static double copySign(double magnitude, double sign) {
- return sun.misc.FpUtils.rawCopySign(magnitude, sign);
+ return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) &
+ (DoubleConsts.SIGN_BIT_MASK)) |
+ (Double.doubleToRawLongBits(magnitude) &
+ (DoubleConsts.EXP_BIT_MASK |
+ DoubleConsts.SIGNIF_BIT_MASK)));
}
/**
@@ -1271,7 +1325,11 @@
* @since 1.6
*/
public static float copySign(float magnitude, float sign) {
- return sun.misc.FpUtils.rawCopySign(magnitude, sign);
+ return Float.intBitsToFloat((Float.floatToRawIntBits(sign) &
+ (FloatConsts.SIGN_BIT_MASK)) |
+ (Float.floatToRawIntBits(magnitude) &
+ (FloatConsts.EXP_BIT_MASK |
+ FloatConsts.SIGNIF_BIT_MASK)));
}
/**
@@ -1289,7 +1347,13 @@
* @since 1.6
*/
public static int getExponent(float f) {
- return sun.misc.FpUtils.getExponent(f);
+ /*
+ * Bitwise convert f to integer, mask out exponent bits, shift
+ * to the right and then subtract out float's bias adjust to
+ * get true exponent value
+ */
+ return ((Float.floatToRawIntBits(f) & FloatConsts.EXP_BIT_MASK) >>
+ (FloatConsts.SIGNIFICAND_WIDTH - 1)) - FloatConsts.EXP_BIAS;
}
/**
@@ -1307,7 +1371,13 @@
* @since 1.6
*/
public static int getExponent(double d) {
- return sun.misc.FpUtils.getExponent(d);
+ /*
+ * Bitwise convert d to long, mask out exponent bits, shift
+ * to the right and then subtract out double's bias adjust to
+ * get true exponent value.
+ */
+ return (int)(((Double.doubleToRawLongBits(d) & DoubleConsts.EXP_BIT_MASK) >>
+ (DoubleConsts.SIGNIFICAND_WIDTH - 1)) - DoubleConsts.EXP_BIAS);
}
/**
@@ -1351,7 +1421,63 @@
* @since 1.6
*/
public static double nextAfter(double start, double direction) {
- return sun.misc.FpUtils.nextAfter(start, direction);
+ /*
+ * The cases:
+ *
+ * nextAfter(+infinity, 0) == MAX_VALUE
+ * nextAfter(+infinity, +infinity) == +infinity
+ * nextAfter(-infinity, 0) == -MAX_VALUE
+ * nextAfter(-infinity, -infinity) == -infinity
+ *
+ * are naturally handled without any additional testing
+ */
+
+ // First check for NaN values
+ if (Double.isNaN(start) || Double.isNaN(direction)) {
+ // return a NaN derived from the input NaN(s)
+ return start + direction;
+ } else if (start == direction) {
+ return direction;
+ } else { // start > direction or start < direction
+ // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
+ // then bitwise convert start to integer.
+ long transducer = Double.doubleToRawLongBits(start + 0.0d);
+
+ /*
+ * IEEE 754 floating-point numbers are lexicographically
+ * ordered if treated as signed- magnitude integers .
+ * Since Java's integers are two's complement,
+ * incrementing" the two's complement representation of a
+ * logically negative floating-point value *decrements*
+ * the signed-magnitude representation. Therefore, when
+ * the integer representation of a floating-point values
+ * is less than zero, the adjustment to the representation
+ * is in the opposite direction than would be expected at
+ * first .
+ */
+ if (direction > start) { // Calculate next greater value
+ transducer = transducer + (transducer >= 0L ? 1L:-1L);
+ } else { // Calculate next lesser value
+ assert direction < start;
+ if (transducer > 0L)
+ --transducer;
+ else
+ if (transducer < 0L )
+ ++transducer;
+ /*
+ * transducer==0, the result is -MIN_VALUE
+ *
+ * The transition from zero (implicitly
+ * positive) to the smallest negative
+ * signed magnitude value must be done
+ * explicitly.
+ */
+ else
+ transducer = DoubleConsts.SIGN_BIT_MASK | 1L;
+ }
+
+ return Double.longBitsToDouble(transducer);
+ }
}
/**
@@ -1394,7 +1520,63 @@
* @since 1.6
*/
public static float nextAfter(float start, double direction) {
- return sun.misc.FpUtils.nextAfter(start, direction);
+ /*
+ * The cases:
+ *
+ * nextAfter(+infinity, 0) == MAX_VALUE
+ * nextAfter(+infinity, +infinity) == +infinity
+ * nextAfter(-infinity, 0) == -MAX_VALUE
+ * nextAfter(-infinity, -infinity) == -infinity
+ *
+ * are naturally handled without any additional testing
+ */
+
+ // First check for NaN values
+ if (Float.isNaN(start) || Double.isNaN(direction)) {
+ // return a NaN derived from the input NaN(s)
+ return start + (float)direction;
+ } else if (start == direction) {
+ return (float)direction;
+ } else { // start > direction or start < direction
+ // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
+ // then bitwise convert start to integer.
+ int transducer = Float.floatToRawIntBits(start + 0.0f);
+
+ /*
+ * IEEE 754 floating-point numbers are lexicographically
+ * ordered if treated as signed- magnitude integers .
+ * Since Java's integers are two's complement,
+ * incrementing" the two's complement representation of a
+ * logically negative floating-point value *decrements*
+ * the signed-magnitude representation. Therefore, when
+ * the integer representation of a floating-point values
+ * is less than zero, the adjustment to the representation
+ * is in the opposite direction than would be expected at
+ * first.
+ */
+ if (direction > start) {// Calculate next greater value
+ transducer = transducer + (transducer >= 0 ? 1:-1);
+ } else { // Calculate next lesser value
+ assert direction < start;
+ if (transducer > 0)
+ --transducer;
+ else
+ if (transducer < 0 )
+ ++transducer;
+ /*
+ * transducer==0, the result is -MIN_VALUE
+ *
+ * The transition from zero (implicitly
+ * positive) to the smallest negative
+ * signed magnitude value must be done
+ * explicitly.
+ */
+ else
+ transducer = FloatConsts.SIGN_BIT_MASK | 1;
+ }
+
+ return Float.intBitsToFloat(transducer);
+ }
}
/**
@@ -1423,7 +1605,13 @@
* @since 1.6
*/
public static double nextUp(double d) {
- return sun.misc.FpUtils.nextUp(d);
+ if( Double.isNaN(d) || d == Double.POSITIVE_INFINITY)
+ return d;
+ else {
+ d += 0.0d;
+ return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
+ ((d >= 0.0d)?+1L:-1L));
+ }
}
/**
@@ -1452,7 +1640,13 @@
* @since 1.6
*/
public static float nextUp(float f) {
- return sun.misc.FpUtils.nextUp(f);
+ if( Float.isNaN(f) || f == FloatConsts.POSITIVE_INFINITY)
+ return f;
+ else {
+ f += 0.0f;
+ return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
+ ((f >= 0.0f)?+1:-1));
+ }
}
@@ -1487,7 +1681,80 @@
* @since 1.6
*/
public static double scalb(double d, int scaleFactor) {
- return sun.misc.FpUtils.scalb(d, scaleFactor);
+ /*
+ * This method does not need to be declared strictfp to
+ * compute the same correct result on all platforms. When
+ * scaling up, it does not matter what order the
+ * multiply-store operations are done; the result will be
+ * finite or overflow regardless of the operation ordering.
+ * However, to get the correct result when scaling down, a
+ * particular ordering must be used.
+ *
+ * When scaling down, the multiply-store operations are
+ * sequenced so that it is not possible for two consecutive
+ * multiply-stores to return subnormal results. If one
+ * multiply-store result is subnormal, the next multiply will
+ * round it away to zero. This is done by first multiplying
+ * by 2 ^ (scaleFactor % n) and then multiplying several
+ * times by by 2^n as needed where n is the exponent of number
+ * that is a covenient power of two. In this way, at most one
+ * real rounding error occurs. If the double value set is
+ * being used exclusively, the rounding will occur on a
+ * multiply. If the double-extended-exponent value set is
+ * being used, the products will (perhaps) be exact but the
+ * stores to d are guaranteed to round to the double value
+ * set.
+ *
+ * It is _not_ a valid implementation to first multiply d by
+ * 2^MIN_EXPONENT and then by 2 ^ (scaleFactor %
+ * MIN_EXPONENT) since even in a strictfp program double
+ * rounding on underflow could occur; e.g. if the scaleFactor
+ * argument was (MIN_EXPONENT - n) and the exponent of d was a
+ * little less than -(MIN_EXPONENT - n), meaning the final
+ * result would be subnormal.
+ *
+ * Since exact reproducibility of this method can be achieved
+ * without any undue performance burden, there is no
+ * compelling reason to allow double rounding on underflow in
+ * scalb.
+ */
+
+ // magnitude of a power of two so large that scaling a finite
+ // nonzero value by it would be guaranteed to over or
+ // underflow; due to rounding, scaling down takes takes an
+ // additional power of two which is reflected here
+ final int MAX_SCALE = DoubleConsts.MAX_EXPONENT + -DoubleConsts.MIN_EXPONENT +
+ DoubleConsts.SIGNIFICAND_WIDTH + 1;
+ int exp_adjust = 0;
+ int scale_increment = 0;
+ double exp_delta = Double.NaN;
+
+ // Make sure scaling factor is in a reasonable range
+
+ if(scaleFactor < 0) {
+ scaleFactor = Math.max(scaleFactor, -MAX_SCALE);
+ scale_increment = -512;
+ exp_delta = twoToTheDoubleScaleDown;
+ }
+ else {
+ scaleFactor = Math.min(scaleFactor, MAX_SCALE);
+ scale_increment = 512;
+ exp_delta = twoToTheDoubleScaleUp;
+ }
+
+ // Calculate (scaleFactor % +/-512), 512 = 2^9, using
+ // technique from "Hacker's Delight" section 10-2.
+ int t = (scaleFactor >> 9-1) >>> 32 - 9;
+ exp_adjust = ((scaleFactor + t) & (512 -1)) - t;
+
+ d *= powerOfTwoD(exp_adjust);
+ scaleFactor -= exp_adjust;
+
+ while(scaleFactor != 0) {
+ d *= exp_delta;
+ scaleFactor -= scale_increment;
+ }
+ return d;
}
/**
@@ -1521,6 +1788,49 @@
* @since 1.6
*/
public static float scalb(float f, int scaleFactor) {
- return sun.misc.FpUtils.scalb(f, scaleFactor);
+ // magnitude of a power of two so large that scaling a finite
+ // nonzero value by it would be guaranteed to over or
+ // underflow; due to rounding, scaling down takes takes an
+ // additional power of two which is reflected here
+ final int MAX_SCALE = FloatConsts.MAX_EXPONENT + -FloatConsts.MIN_EXPONENT +
+ FloatConsts.SIGNIFICAND_WIDTH + 1;
+
+ // Make sure scaling factor is in a reasonable range
+ scaleFactor = Math.max(Math.min(scaleFactor, MAX_SCALE), -MAX_SCALE);
+
+ /*
+ * Since + MAX_SCALE for float fits well within the double
+ * exponent range and + float -> double conversion is exact
+ * the multiplication below will be exact. Therefore, the
+ * rounding that occurs when the double product is cast to
+ * float will be the correctly rounded float result. Since
+ * all operations other than the final multiply will be exact,
+ * it is not necessary to declare this method strictfp.
+ */
+ return (float)((double)f*powerOfTwoD(scaleFactor));
+ }
+
+ // Constants used in scalb
+ static double twoToTheDoubleScaleUp = powerOfTwoD(512);
+ static double twoToTheDoubleScaleDown = powerOfTwoD(-512);
+
+ /**
+ * Returns a floating-point power of two in the normal range.
+ */
+ static double powerOfTwoD(int n) {
+ assert(n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT);
+ return Double.longBitsToDouble((((long)n + (long)DoubleConsts.EXP_BIAS) <<
+ (DoubleConsts.SIGNIFICAND_WIDTH-1))
+ & DoubleConsts.EXP_BIT_MASK);
+ }
+
+ /**
+ * Returns a floating-point power of two in the normal range.
+ */
+ public static float powerOfTwoF(int n) {
+ assert(n >= FloatConsts.MIN_EXPONENT && n <= FloatConsts.MAX_EXPONENT);
+ return Float.intBitsToFloat(((n + FloatConsts.EXP_BIAS) <<
+ (FloatConsts.SIGNIFICAND_WIDTH-1))
+ & FloatConsts.EXP_BIT_MASK);
}
}
--- a/jdk/src/share/classes/java/lang/StrictMath.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/java/lang/StrictMath.java Sun Sep 18 18:14:07 2011 -0700
@@ -25,7 +25,6 @@
package java.lang;
import java.util.Random;
-import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
/**
@@ -428,7 +427,7 @@
* 1.0, which is exact too.
*/
double twoToThe52 = (double)(1L << 52); // 2^52
- double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info
+ double sign = Math.copySign(1.0, a); // preserve sign info
a = Math.abs(a);
if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
@@ -955,7 +954,7 @@
* @since 1.5
*/
public static double ulp(double d) {
- return sun.misc.FpUtils.ulp(d);
+ return Math.ulp(d);
}
/**
@@ -982,7 +981,7 @@
* @since 1.5
*/
public static float ulp(float f) {
- return sun.misc.FpUtils.ulp(f);
+ return Math.ulp(f);
}
/**
@@ -1003,7 +1002,7 @@
* @since 1.5
*/
public static double signum(double d) {
- return sun.misc.FpUtils.signum(d);
+ return Math.signum(d);
}
/**
@@ -1024,7 +1023,7 @@
* @since 1.5
*/
public static float signum(float f) {
- return sun.misc.FpUtils.signum(f);
+ return Math.signum(f);
}
/**
@@ -1202,7 +1201,7 @@
* @since 1.6
*/
public static double copySign(double magnitude, double sign) {
- return sun.misc.FpUtils.copySign(magnitude, sign);
+ return Math.copySign(magnitude, (Double.isNaN(sign)?1.0d:sign));
}
/**
@@ -1218,7 +1217,7 @@
* @since 1.6
*/
public static float copySign(float magnitude, float sign) {
- return sun.misc.FpUtils.copySign(magnitude, sign);
+ return Math.copySign(magnitude, (Float.isNaN(sign)?1.0f:sign));
}
/**
* Returns the unbiased exponent used in the representation of a
@@ -1234,7 +1233,7 @@
* @since 1.6
*/
public static int getExponent(float f) {
- return sun.misc.FpUtils.getExponent(f);
+ return Math.getExponent(f);
}
/**
@@ -1251,7 +1250,7 @@
* @since 1.6
*/
public static int getExponent(double d) {
- return sun.misc.FpUtils.getExponent(d);
+ return Math.getExponent(d);
}
/**
@@ -1294,7 +1293,7 @@
* @since 1.6
*/
public static double nextAfter(double start, double direction) {
- return sun.misc.FpUtils.nextAfter(start, direction);
+ return Math.nextAfter(start, direction);
}
/**
@@ -1336,7 +1335,7 @@
* @since 1.6
*/
public static float nextAfter(float start, double direction) {
- return sun.misc.FpUtils.nextAfter(start, direction);
+ return Math.nextAfter(start, direction);
}
/**
@@ -1365,7 +1364,7 @@
* @since 1.6
*/
public static double nextUp(double d) {
- return sun.misc.FpUtils.nextUp(d);
+ return Math.nextUp(d);
}
/**
@@ -1394,10 +1393,9 @@
* @since 1.6
*/
public static float nextUp(float f) {
- return sun.misc.FpUtils.nextUp(f);
+ return Math.nextUp(f);
}
-
/**
* Return {@code d} ×
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
@@ -1429,7 +1427,7 @@
* @since 1.6
*/
public static double scalb(double d, int scaleFactor) {
- return sun.misc.FpUtils.scalb(d, scaleFactor);
+ return Math.scalb(d, scaleFactor);
}
/**
@@ -1463,6 +1461,6 @@
* @since 1.6
*/
public static float scalb(float f, int scaleFactor) {
- return sun.misc.FpUtils.scalb(f, scaleFactor);
+ return Math.scalb(f, scaleFactor);
}
}
--- a/jdk/src/share/classes/java/util/Formatter.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/java/util/Formatter.java Sun Sep 18 18:14:07 2011 -0700
@@ -3423,18 +3423,18 @@
else {
assert(prec >= 1 && prec <= 12);
- int exponent = FpUtils.getExponent(d);
+ int exponent = Math.getExponent(d);
boolean subnormal
= (exponent == DoubleConsts.MIN_EXPONENT - 1);
// If this is subnormal input so normalize (could be faster to
// do as integer operation).
if (subnormal) {
- scaleUp = FpUtils.scalb(1.0, 54);
+ scaleUp = Math.scalb(1.0, 54);
d *= scaleUp;
// Calculate the exponent. This is not just exponent + 54
// since the former is not the normalized exponent.
- exponent = FpUtils.getExponent(d);
+ exponent = Math.getExponent(d);
assert exponent >= DoubleConsts.MIN_EXPONENT &&
exponent <= DoubleConsts.MAX_EXPONENT: exponent;
}
--- a/jdk/src/share/classes/sun/misc/FloatingDecimal.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/sun/misc/FloatingDecimal.java Sun Sep 18 18:14:07 2011 -0700
@@ -25,7 +25,6 @@
package sun.misc;
-import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
import sun.misc.FloatConsts;
import java.util.regex.*;
@@ -2297,9 +2296,9 @@
significand++;
}
- FloatingDecimal fd = new FloatingDecimal(FpUtils.rawCopySign(
- Double.longBitsToDouble(significand),
- sign));
+ FloatingDecimal fd = new FloatingDecimal(Math.copySign(
+ Double.longBitsToDouble(significand),
+ sign));
/*
* Set roundingDir variable field of fd properly so
--- a/jdk/src/share/classes/sun/misc/FormattedFloatingDecimal.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/sun/misc/FormattedFloatingDecimal.java Sun Sep 18 18:14:07 2011 -0700
@@ -25,7 +25,6 @@
package sun.misc;
-import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
import sun.misc.FloatConsts;
import java.util.regex.*;
--- a/jdk/src/share/classes/sun/misc/FpUtils.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/src/share/classes/sun/misc/FpUtils.java Sun Sep 18 18:14:07 2011 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -125,10 +125,6 @@
*/
private FpUtils() {}
- // Constants used in scalb
- static double twoToTheDoubleScaleUp = powerOfTwoD(512);
- static double twoToTheDoubleScaleDown = powerOfTwoD(-512);
-
// Helper Methods
// The following helper methods are used in the implementation of
@@ -137,49 +133,22 @@
/**
* Returns unbiased exponent of a {@code double}.
+ * @deprecated Use Math.getExponent.
*/
+ @Deprecated
public static int getExponent(double d){
- /*
- * Bitwise convert d to long, mask out exponent bits, shift
- * to the right and then subtract out double's bias adjust to
- * get true exponent value.
- */
- return (int)(((Double.doubleToRawLongBits(d) & DoubleConsts.EXP_BIT_MASK) >>
- (DoubleConsts.SIGNIFICAND_WIDTH - 1)) - DoubleConsts.EXP_BIAS);
+ return Math.getExponent(d);
}
/**
* Returns unbiased exponent of a {@code float}.
+ * @deprecated Use Math.getExponent.
*/
+ @Deprecated
public static int getExponent(float f){
- /*
- * Bitwise convert f to integer, mask out exponent bits, shift
- * to the right and then subtract out float's bias adjust to
- * get true exponent value
- */
- return ((Float.floatToRawIntBits(f) & FloatConsts.EXP_BIT_MASK) >>
- (FloatConsts.SIGNIFICAND_WIDTH - 1)) - FloatConsts.EXP_BIAS;
+ return Math.getExponent(f);
}
- /**
- * Returns a floating-point power of two in the normal range.
- */
- static double powerOfTwoD(int n) {
- assert(n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT);
- return Double.longBitsToDouble((((long)n + (long)DoubleConsts.EXP_BIAS) <<
- (DoubleConsts.SIGNIFICAND_WIDTH-1))
- & DoubleConsts.EXP_BIT_MASK);
- }
-
- /**
- * Returns a floating-point power of two in the normal range.
- */
- static float powerOfTwoF(int n) {
- assert(n >= FloatConsts.MIN_EXPONENT && n <= FloatConsts.MAX_EXPONENT);
- return Float.intBitsToFloat(((n + FloatConsts.EXP_BIAS) <<
- (FloatConsts.SIGNIFICAND_WIDTH-1))
- & FloatConsts.EXP_BIT_MASK);
- }
/**
* Returns the first floating-point argument with the sign of the
@@ -195,13 +164,11 @@
* @return a value with the magnitude of {@code magnitude}
* and the sign of {@code sign}.
* @author Joseph D. Darcy
+ * @deprecated Use Math.copySign.
*/
+ @Deprecated
public static double rawCopySign(double magnitude, double sign) {
- return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) &
- (DoubleConsts.SIGN_BIT_MASK)) |
- (Double.doubleToRawLongBits(magnitude) &
- (DoubleConsts.EXP_BIT_MASK |
- DoubleConsts.SIGNIF_BIT_MASK)));
+ return Math.copySign(magnitude, sign);
}
/**
@@ -218,13 +185,11 @@
* @return a value with the magnitude of {@code magnitude}
* and the sign of {@code sign}.
* @author Joseph D. Darcy
+ * @deprecated Use Math.copySign.
*/
+ @Deprecated
public static float rawCopySign(float magnitude, float sign) {
- return Float.intBitsToFloat((Float.floatToRawIntBits(sign) &
- (FloatConsts.SIGN_BIT_MASK)) |
- (Float.floatToRawIntBits(magnitude) &
- (FloatConsts.EXP_BIT_MASK |
- FloatConsts.SIGNIF_BIT_MASK)));
+ return Math.copySign(magnitude, sign);
}
/* ***************************************************************** */
@@ -558,82 +523,11 @@
* @param scale_factor power of 2 used to scale {@code d}
* @return {@code d * }2<sup>{@code scale_factor}</sup>
* @author Joseph D. Darcy
+ * @deprecated Use Math.scalb.
*/
+ @Deprecated
public static double scalb(double d, int scale_factor) {
- /*
- * This method does not need to be declared strictfp to
- * compute the same correct result on all platforms. When
- * scaling up, it does not matter what order the
- * multiply-store operations are done; the result will be
- * finite or overflow regardless of the operation ordering.
- * However, to get the correct result when scaling down, a
- * particular ordering must be used.
- *
- * When scaling down, the multiply-store operations are
- * sequenced so that it is not possible for two consecutive
- * multiply-stores to return subnormal results. If one
- * multiply-store result is subnormal, the next multiply will
- * round it away to zero. This is done by first multiplying
- * by 2 ^ (scale_factor % n) and then multiplying several
- * times by by 2^n as needed where n is the exponent of number
- * that is a covenient power of two. In this way, at most one
- * real rounding error occurs. If the double value set is
- * being used exclusively, the rounding will occur on a
- * multiply. If the double-extended-exponent value set is
- * being used, the products will (perhaps) be exact but the
- * stores to d are guaranteed to round to the double value
- * set.
- *
- * It is _not_ a valid implementation to first multiply d by
- * 2^MIN_EXPONENT and then by 2 ^ (scale_factor %
- * MIN_EXPONENT) since even in a strictfp program double
- * rounding on underflow could occur; e.g. if the scale_factor
- * argument was (MIN_EXPONENT - n) and the exponent of d was a
- * little less than -(MIN_EXPONENT - n), meaning the final
- * result would be subnormal.
- *
- * Since exact reproducibility of this method can be achieved
- * without any undue performance burden, there is no
- * compelling reason to allow double rounding on underflow in
- * scalb.
- */
-
- // magnitude of a power of two so large that scaling a finite
- // nonzero value by it would be guaranteed to over or
- // underflow; due to rounding, scaling down takes takes an
- // additional power of two which is reflected here
- final int MAX_SCALE = DoubleConsts.MAX_EXPONENT + -DoubleConsts.MIN_EXPONENT +
- DoubleConsts.SIGNIFICAND_WIDTH + 1;
- int exp_adjust = 0;
- int scale_increment = 0;
- double exp_delta = Double.NaN;
-
- // Make sure scaling factor is in a reasonable range
-
- if(scale_factor < 0) {
- scale_factor = Math.max(scale_factor, -MAX_SCALE);
- scale_increment = -512;
- exp_delta = twoToTheDoubleScaleDown;
- }
- else {
- scale_factor = Math.min(scale_factor, MAX_SCALE);
- scale_increment = 512;
- exp_delta = twoToTheDoubleScaleUp;
- }
-
- // Calculate (scale_factor % +/-512), 512 = 2^9, using
- // technique from "Hacker's Delight" section 10-2.
- int t = (scale_factor >> 9-1) >>> 32 - 9;
- exp_adjust = ((scale_factor + t) & (512 -1)) - t;
-
- d *= powerOfTwoD(exp_adjust);
- scale_factor -= exp_adjust;
-
- while(scale_factor != 0) {
- d *= exp_delta;
- scale_factor -= scale_increment;
- }
- return d;
+ return Math.scalb(d, scale_factor);
}
/**
@@ -667,28 +561,11 @@
* @param scale_factor power of 2 used to scale {@code f}
* @return {@code f * }2<sup>{@code scale_factor}</sup>
* @author Joseph D. Darcy
+ * @deprecated Use Math.scalb.
*/
- public static float scalb(float f, int scale_factor) {
- // magnitude of a power of two so large that scaling a finite
- // nonzero value by it would be guaranteed to over or
- // underflow; due to rounding, scaling down takes takes an
- // additional power of two which is reflected here
- final int MAX_SCALE = FloatConsts.MAX_EXPONENT + -FloatConsts.MIN_EXPONENT +
- FloatConsts.SIGNIFICAND_WIDTH + 1;
-
- // Make sure scaling factor is in a reasonable range
- scale_factor = Math.max(Math.min(scale_factor, MAX_SCALE), -MAX_SCALE);
-
- /*
- * Since + MAX_SCALE for float fits well within the double
- * exponent range and + float -> double conversion is exact
- * the multiplication below will be exact. Therefore, the
- * rounding that occurs when the double product is cast to
- * float will be the correctly rounded float result. Since
- * all operations other than the final multiply will be exact,
- * it is not necessary to declare this method strictfp.
- */
- return (float)((double)f*powerOfTwoD(scale_factor));
+ @Deprecated
+ public static float scalb(float f, int scale_factor) {
+ return Math.scalb(f, scale_factor);
}
/**
@@ -730,65 +607,11 @@
* @return The floating-point number adjacent to {@code start} in the
* direction of {@code direction}.
* @author Joseph D. Darcy
+ * @deprecated Use Math.nextAfter
*/
+ @Deprecated
public static double nextAfter(double start, double direction) {
- /*
- * The cases:
- *
- * nextAfter(+infinity, 0) == MAX_VALUE
- * nextAfter(+infinity, +infinity) == +infinity
- * nextAfter(-infinity, 0) == -MAX_VALUE
- * nextAfter(-infinity, -infinity) == -infinity
- *
- * are naturally handled without any additional testing
- */
-
- // First check for NaN values
- if (isNaN(start) || isNaN(direction)) {
- // return a NaN derived from the input NaN(s)
- return start + direction;
- } else if (start == direction) {
- return direction;
- } else { // start > direction or start < direction
- // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
- // then bitwise convert start to integer.
- long transducer = Double.doubleToRawLongBits(start + 0.0d);
-
- /*
- * IEEE 754 floating-point numbers are lexicographically
- * ordered if treated as signed- magnitude integers .
- * Since Java's integers are two's complement,
- * incrementing" the two's complement representation of a
- * logically negative floating-point value *decrements*
- * the signed-magnitude representation. Therefore, when
- * the integer representation of a floating-point values
- * is less than zero, the adjustment to the representation
- * is in the opposite direction than would be expected at
- * first .
- */
- if (direction > start) { // Calculate next greater value
- transducer = transducer + (transducer >= 0L ? 1L:-1L);
- } else { // Calculate next lesser value
- assert direction < start;
- if (transducer > 0L)
- --transducer;
- else
- if (transducer < 0L )
- ++transducer;
- /*
- * transducer==0, the result is -MIN_VALUE
- *
- * The transition from zero (implicitly
- * positive) to the smallest negative
- * signed magnitude value must be done
- * explicitly.
- */
- else
- transducer = DoubleConsts.SIGN_BIT_MASK | 1L;
- }
-
- return Double.longBitsToDouble(transducer);
- }
+ return Math.nextAfter(start, direction);
}
/**
@@ -830,65 +653,11 @@
* @return The floating-point number adjacent to {@code start} in the
* direction of {@code direction}.
* @author Joseph D. Darcy
+ * @deprecated Use Math.nextAfter.
*/
- public static float nextAfter(float start, double direction) {
- /*
- * The cases:
- *
- * nextAfter(+infinity, 0) == MAX_VALUE
- * nextAfter(+infinity, +infinity) == +infinity
- * nextAfter(-infinity, 0) == -MAX_VALUE
- * nextAfter(-infinity, -infinity) == -infinity
- *
- * are naturally handled without any additional testing
- */
-
- // First check for NaN values
- if (isNaN(start) || isNaN(direction)) {
- // return a NaN derived from the input NaN(s)
- return start + (float)direction;
- } else if (start == direction) {
- return (float)direction;
- } else { // start > direction or start < direction
- // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
- // then bitwise convert start to integer.
- int transducer = Float.floatToRawIntBits(start + 0.0f);
-
- /*
- * IEEE 754 floating-point numbers are lexicographically
- * ordered if treated as signed- magnitude integers .
- * Since Java's integers are two's complement,
- * incrementing" the two's complement representation of a
- * logically negative floating-point value *decrements*
- * the signed-magnitude representation. Therefore, when
- * the integer representation of a floating-point values
- * is less than zero, the adjustment to the representation
- * is in the opposite direction than would be expected at
- * first.
- */
- if (direction > start) {// Calculate next greater value
- transducer = transducer + (transducer >= 0 ? 1:-1);
- } else { // Calculate next lesser value
- assert direction < start;
- if (transducer > 0)
- --transducer;
- else
- if (transducer < 0 )
- ++transducer;
- /*
- * transducer==0, the result is -MIN_VALUE
- *
- * The transition from zero (implicitly
- * positive) to the smallest negative
- * signed magnitude value must be done
- * explicitly.
- */
- else
- transducer = FloatConsts.SIGN_BIT_MASK | 1;
- }
-
- return Float.intBitsToFloat(transducer);
- }
+ @Deprecated
+ public static float nextAfter(float start, double direction) {
+ return Math.nextAfter(start, direction);
}
/**
@@ -915,15 +684,11 @@
* @return The adjacent floating-point value closer to positive
* infinity.
* @author Joseph D. Darcy
+ * @deprecated use Math.nextUp.
*/
+ @Deprecated
public static double nextUp(double d) {
- if( isNaN(d) || d == Double.POSITIVE_INFINITY)
- return d;
- else {
- d += 0.0d;
- return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
- ((d >= 0.0d)?+1L:-1L));
- }
+ return Math.nextUp(d);
}
/**
@@ -950,15 +715,11 @@
* @return The adjacent floating-point value closer to positive
* infinity.
* @author Joseph D. Darcy
+ * @deprecated Use Math.nextUp.
*/
- public static float nextUp(float f) {
- if( isNaN(f) || f == FloatConsts.POSITIVE_INFINITY)
- return f;
- else {
- f += 0.0f;
- return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
- ((f >= 0.0f)?+1:-1));
- }
+ @Deprecated
+ public static float nextUp(float f) {
+ return Math.nextUp(f);
}
/**
@@ -1047,9 +808,11 @@
* and the sign of {@code sign}.
* @author Joseph D. Darcy
* @since 1.5
+ * @deprecated Use StrictMath.copySign.
*/
+ @Deprecated
public static double copySign(double magnitude, double sign) {
- return rawCopySign(magnitude, (isNaN(sign)?1.0d:sign));
+ return StrictMath.copySign(magnitude, sign);
}
/**
@@ -1063,9 +826,11 @@
* @return a value with the magnitude of {@code magnitude}
* and the sign of {@code sign}.
* @author Joseph D. Darcy
+ * @deprecated Use StrictMath.copySign.
*/
- public static float copySign(float magnitude, float sign) {
- return rawCopySign(magnitude, (isNaN(sign)?1.0f:sign));
+ @Deprecated
+ public static float copySign(float magnitude, float sign) {
+ return StrictMath.copySign(magnitude, sign);
}
/**
@@ -1090,33 +855,11 @@
* @return the size of an ulp of the argument
* @author Joseph D. Darcy
* @since 1.5
+ * @deprecated Use Math.ulp.
*/
+ @Deprecated
public static double ulp(double d) {
- int exp = getExponent(d);
-
- switch(exp) {
- case DoubleConsts.MAX_EXPONENT+1: // NaN or infinity
- return Math.abs(d);
-
- case DoubleConsts.MIN_EXPONENT-1: // zero or subnormal
- return Double.MIN_VALUE;
-
- default:
- assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT;
-
- // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
- exp = exp - (DoubleConsts.SIGNIFICAND_WIDTH-1);
- if (exp >= DoubleConsts.MIN_EXPONENT) {
- return powerOfTwoD(exp);
- }
- else {
- // return a subnormal result; left shift integer
- // representation of Double.MIN_VALUE appropriate
- // number of positions
- return Double.longBitsToDouble(1L <<
- (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) ));
- }
- }
+ return Math.ulp(d);
}
/**
@@ -1141,33 +884,11 @@
* @return the size of an ulp of the argument
* @author Joseph D. Darcy
* @since 1.5
+ * @deprecated Use Math.ulp.
*/
+ @Deprecated
public static float ulp(float f) {
- int exp = getExponent(f);
-
- switch(exp) {
- case FloatConsts.MAX_EXPONENT+1: // NaN or infinity
- return Math.abs(f);
-
- case FloatConsts.MIN_EXPONENT-1: // zero or subnormal
- return FloatConsts.MIN_VALUE;
-
- default:
- assert exp <= FloatConsts.MAX_EXPONENT && exp >= FloatConsts.MIN_EXPONENT;
-
- // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
- exp = exp - (FloatConsts.SIGNIFICAND_WIDTH-1);
- if (exp >= FloatConsts.MIN_EXPONENT) {
- return powerOfTwoF(exp);
- }
- else {
- // return a subnormal result; left shift integer
- // representation of FloatConsts.MIN_VALUE appropriate
- // number of positions
- return Float.intBitsToFloat(1 <<
- (exp - (FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1)) ));
- }
- }
+ return Math.ulp(f);
}
/**
@@ -1186,9 +907,11 @@
* @return the signum function of the argument
* @author Joseph D. Darcy
* @since 1.5
+ * @deprecated Use Math.signum.
*/
+ @Deprecated
public static double signum(double d) {
- return (d == 0.0 || isNaN(d))?d:copySign(1.0, d);
+ return Math.signum(d);
}
/**
@@ -1207,9 +930,10 @@
* @return the signum function of the argument
* @author Joseph D. Darcy
* @since 1.5
+ * @deprecated Use Math.signum.
*/
+ @Deprecated
public static float signum(float f) {
- return (f == 0.0f || isNaN(f))?f:copySign(1.0f, f);
+ return Math.signum(f);
}
-
}
--- a/jdk/test/java/lang/Double/ToHexString.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Double/ToHexString.java Sun Sep 18 18:14:07 2011 -0700
@@ -29,7 +29,6 @@
*/
import java.util.regex.*;
-import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class ToHexString {
--- a/jdk/test/java/lang/Math/CubeRootTests.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/CubeRootTests.java Sun Sep 18 18:14:07 2011 -0700
@@ -95,14 +95,14 @@
// Test cbrt(2^(3n)) = 2^n.
for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; i++) {
- failures += testCubeRootCase(FpUtils.scalb(1.0, 3*i),
- FpUtils.scalb(1.0, i) );
+ failures += testCubeRootCase(Math.scalb(1.0, 3*i),
+ Math.scalb(1.0, i) );
}
// Test cbrt(2^(-3n)) = 2^-n.
- for(int i = -1; i >= FpUtils.ilogb(Double.MIN_VALUE)/3; i--) {
- failures += testCubeRootCase(FpUtils.scalb(1.0, 3*i),
- FpUtils.scalb(1.0, i) );
+ for(int i = -1; i >= DoubleConsts.MIN_SUB_EXPONENT/3; i--) {
+ failures += testCubeRootCase(Math.scalb(1.0, 3*i),
+ Math.scalb(1.0, i) );
}
// Test random perfect cubes. Create double values with
@@ -110,10 +110,10 @@
// significant bits in the significand set; 17*3 = 51, which
// is less than the number of bits in a double's significand.
long exponentBits1 =
- Double.doubleToLongBits(FpUtils.scalb(1.0, 55)) &
+ Double.doubleToLongBits(Math.scalb(1.0, 55)) &
DoubleConsts.EXP_BIT_MASK;
long exponentBits2=
- Double.doubleToLongBits(FpUtils.scalb(1.0, -55)) &
+ Double.doubleToLongBits(Math.scalb(1.0, -55)) &
DoubleConsts.EXP_BIT_MASK;
for(int i = 0; i < 100; i++) {
// Take 16 bits since the 17th bit is implicit in the
@@ -177,16 +177,16 @@
err = d - StrictMath.pow(y1, 3);
if (err != 0.0) {
- if(FpUtils.isNaN(err)) {
+ if(Double.isNaN(err)) {
failures++;
System.err.println("Encountered unexpected NaN value: d = " + d +
"\tcbrt(d) = " + y1);
} else {
if (err < 0.0) {
- err_adjacent = StrictMath.pow(FpUtils.nextUp(y1), 3) - d;
+ err_adjacent = StrictMath.pow(Math.nextUp(y1), 3) - d;
}
else { // (err > 0.0)
- err_adjacent = StrictMath.pow(FpUtils.nextAfter(y1,0.0), 3) - d;
+ err_adjacent = StrictMath.pow(Math.nextAfter(y1,0.0), 3) - d;
}
if (Math.abs(err) > Math.abs(err_adjacent)) {
@@ -200,16 +200,16 @@
err = d - StrictMath.pow(y2, 3);
if (err != 0.0) {
- if(FpUtils.isNaN(err)) {
+ if(Double.isNaN(err)) {
failures++;
System.err.println("Encountered unexpected NaN value: d = " + d +
"\tcbrt(d) = " + y2);
} else {
if (err < 0.0) {
- err_adjacent = StrictMath.pow(FpUtils.nextUp(y2), 3) - d;
+ err_adjacent = StrictMath.pow(Math.nextUp(y2), 3) - d;
}
else { // (err > 0.0)
- err_adjacent = StrictMath.pow(FpUtils.nextAfter(y2,0.0), 3) - d;
+ err_adjacent = StrictMath.pow(Math.nextAfter(y2,0.0), 3) - d;
}
if (Math.abs(err) > Math.abs(err_adjacent)) {
@@ -242,13 +242,13 @@
// Test near cbrt(2^(3n)) = 2^n.
for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; i++) {
- double pc = FpUtils.scalb(1.0, 3*i);
+ double pc = Math.scalb(1.0, 3*i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
- pcNeighbors[3] = FpUtils.nextUp(pc);
- pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
+ pcNeighbors[3] = Math.nextUp(pc);
+ pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsCbrt[j] = Math.cbrt(pcNeighbors[j]);
@@ -280,14 +280,14 @@
}
// Test near cbrt(2^(-3n)) = 2^-n.
- for(int i = -1; i >= FpUtils.ilogb(Double.MIN_VALUE)/3; i--) {
- double pc = FpUtils.scalb(1.0, 3*i);
+ for(int i = -1; i >= DoubleConsts.MIN_SUB_EXPONENT/3; i--) {
+ double pc = Math.scalb(1.0, 3*i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
- pcNeighbors[3] = FpUtils.nextUp(pc);
- pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
+ pcNeighbors[3] = Math.nextUp(pc);
+ pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsCbrt[j] = Math.cbrt(pcNeighbors[j]);
--- a/jdk/test/java/lang/Math/Expm1Tests.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/Expm1Tests.java Sun Sep 18 18:14:07 2011 -0700
@@ -82,7 +82,7 @@
// For |x| < 2^-54 expm1(x) ~= x
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i <= -54; i++) {
- double d = FpUtils.scalb(2, i);
+ double d = Math.scalb(2, i);
failures += testExpm1Case(d, d);
failures += testExpm1Case(-d, -d);
}
@@ -101,7 +101,7 @@
// For x > 710, expm1(x) should be infinity
for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
- double d = FpUtils.scalb(2, i);
+ double d = Math.scalb(2, i);
failures += testExpm1Case(d, infinityD);
}
@@ -118,7 +118,7 @@
}
for(int i = 7; i <= DoubleConsts.MAX_EXPONENT; i++) {
- double d = -FpUtils.scalb(2, i);
+ double d = -Math.scalb(2, i);
failures += testExpm1CaseWithUlpDiff(d, -1.0, 1, reachedLimit);
}
@@ -145,8 +145,8 @@
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
- pcNeighbors[3] = FpUtils.nextUp(pc);
- pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
+ pcNeighbors[3] = Math.nextUp(pc);
+ pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsExpm1[j] = Math.expm1(pcNeighbors[j]);
--- a/jdk/test/java/lang/Math/HyperbolicTests.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/HyperbolicTests.java Sun Sep 18 18:14:07 2011 -0700
@@ -266,7 +266,7 @@
// double significand.
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
- double d = FpUtils.scalb(2.0, i);
+ double d = Math.scalb(2.0, i);
// Result and expected are the same.
failures += testSinhCaseWithUlpDiff(d, d, 2.5);
@@ -344,7 +344,7 @@
// sinh(x) overflows for values greater than 710; in
// particular, it overflows for all 2^i, i > 10.
for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
- double d = FpUtils.scalb(2.0, i);
+ double d = Math.scalb(2.0, i);
// Result and expected are the same.
failures += testSinhCaseWithUlpDiff(d,
@@ -625,7 +625,7 @@
// rounded.
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
- double d = FpUtils.scalb(2.0, i);
+ double d = Math.scalb(2.0, i);
// Result and expected are the same.
failures += testCoshCaseWithUlpDiff(d, 1.0, 2.5);
@@ -703,7 +703,7 @@
// cosh(x) overflows for values greater than 710; in
// particular, it overflows for all 2^i, i > 10.
for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
- double d = FpUtils.scalb(2.0, i);
+ double d = Math.scalb(2.0, i);
// Result and expected are the same.
failures += testCoshCaseWithUlpDiff(d,
@@ -984,7 +984,7 @@
// double significand.
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
- double d = FpUtils.scalb(2.0, i);
+ double d = Math.scalb(2.0, i);
// Result and expected are the same.
failures += testTanhCaseWithUlpDiff(d, d, 2.5);
@@ -998,7 +998,7 @@
}
for(int i = 5; i <= DoubleConsts.MAX_EXPONENT; i++) {
- double d = FpUtils.scalb(2.0, i);
+ double d = Math.scalb(2.0, i);
failures += testTanhCaseWithUlpDiff(d, 1.0, 2.5);
}
--- a/jdk/test/java/lang/Math/HypotTests.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/HypotTests.java Sun Sep 18 18:14:07 2011 -0700
@@ -90,7 +90,7 @@
for(int i = DoubleConsts.MIN_SUB_EXPONENT;
i <= DoubleConsts.MAX_EXPONENT;
i++) {
- double input = FpUtils.scalb(2, i);
+ double input = Math.scalb(2, i);
failures += testHypotCase(input, 0.0, input);
}
@@ -126,7 +126,7 @@
for(int i = 0; i < 1000; i++) {
double d = rand.nextDouble();
// Scale d to have an exponent equal to MAX_EXPONENT -15
- d = FpUtils.scalb(d, DoubleConsts.MAX_EXPONENT
+ d = Math.scalb(d, DoubleConsts.MAX_EXPONENT
-15 - FpUtils.ilogb(d));
for(int j = 0; j <= 13; j += 1) {
failures += testHypotCase(3*d, 4*d, 5*d, 2.5);
@@ -153,13 +153,13 @@
for(int i = -18; i <= 18; i++) {
- double pc = FpUtils.scalb(1.0, i);
+ double pc = Math.scalb(1.0, i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
- pcNeighbors[3] = FpUtils.nextUp(pc);
- pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
+ pcNeighbors[3] = Math.nextUp(pc);
+ pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsHypot[j] = Math.hypot(2.0, pcNeighbors[j]);
--- a/jdk/test/java/lang/Math/IeeeRecommendedTests.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/IeeeRecommendedTests.java Sun Sep 18 18:14:07 2011 -0700
@@ -177,7 +177,7 @@
}
if (i > FloatConsts.MIN_EXPONENT) {
- float po2minus = FpUtils.nextAfter(po2,
+ float po2minus = Math.nextAfter(po2,
Float.NEGATIVE_INFINITY);
failures += testGetExponentCase(po2minus, i-1);
}
@@ -205,7 +205,7 @@
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
- testGetExponentCase(FpUtils.nextAfter(top, 0.0f),
+ testGetExponentCase(Math.nextAfter(top, 0.0f),
FloatConsts.MIN_EXPONENT - 1);
if( i >= 10) {
@@ -284,7 +284,7 @@
}
if (i > DoubleConsts.MIN_EXPONENT) {
- double po2minus = FpUtils.nextAfter(po2,
+ double po2minus = Math.nextAfter(po2,
Double.NEGATIVE_INFINITY);
failures += testGetExponentCase(po2minus, i-1);
}
@@ -312,7 +312,7 @@
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
- testGetExponentCase(FpUtils.nextAfter(top, 0.0),
+ testGetExponentCase(Math.nextAfter(top, 0.0),
DoubleConsts.MIN_EXPONENT - 1);
if( i >= 10) {
@@ -1061,7 +1061,7 @@
float value = someTestCases[i];
failures+=testScalbCase(value,
scaleFactor,
- FpUtils.copySign( (scaleFactor>0?infinityF:0.0f), value) );
+ Math.copySign( (scaleFactor>0?infinityF:0.0f), value) );
}
}
}
@@ -1095,7 +1095,7 @@
failures+=testScalbCase(value,
scaleFactor,
(FpUtils.ilogb(value) +j > FloatConsts.MAX_EXPONENT ) ?
- FpUtils.copySign(infinityF, value) : // overflow
+ Math.copySign(infinityF, value) : // overflow
// calculate right answer
twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
scale*=2.0f;
@@ -1268,7 +1268,7 @@
double value = someTestCases[i];
failures+=testScalbCase(value,
scaleFactor,
- FpUtils.copySign( (scaleFactor>0?infinityD:0.0), value) );
+ Math.copySign( (scaleFactor>0?infinityD:0.0), value) );
}
}
}
@@ -1302,7 +1302,7 @@
failures+=testScalbCase(value,
scaleFactor,
(FpUtils.ilogb(value) +j > DoubleConsts.MAX_EXPONENT ) ?
- FpUtils.copySign(infinityD, value) : // overflow
+ Math.copySign(infinityD, value) : // overflow
// calculate right answer
twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
scale*=2.0;
@@ -1423,7 +1423,7 @@
// Create power of two
float po2 = powerOfTwoF(i);
- expected = FpUtils.scalb(1.0f, i - (FloatConsts.SIGNIFICAND_WIDTH-1));
+ expected = Math.scalb(1.0f, i - (FloatConsts.SIGNIFICAND_WIDTH-1));
failures += testUlpCase(po2, expected);
@@ -1443,7 +1443,7 @@
}
if (i > FloatConsts.MIN_EXPONENT) {
- float po2minus = FpUtils.nextAfter(po2,
+ float po2minus = Math.nextAfter(po2,
Float.NEGATIVE_INFINITY);
failures += testUlpCase(po2minus, expected/2.0f);
}
@@ -1470,7 +1470,7 @@
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
- testUlpCase(FpUtils.nextAfter(top, 0.0f),
+ testUlpCase(Math.nextAfter(top, 0.0f),
Float.MIN_VALUE);
if( i >= 10) {
@@ -1528,7 +1528,7 @@
// Create power of two
double po2 = powerOfTwoD(i);
- expected = FpUtils.scalb(1.0, i - (DoubleConsts.SIGNIFICAND_WIDTH-1));
+ expected = Math.scalb(1.0, i - (DoubleConsts.SIGNIFICAND_WIDTH-1));
failures += testUlpCase(po2, expected);
@@ -1548,7 +1548,7 @@
}
if (i > DoubleConsts.MIN_EXPONENT) {
- double po2minus = FpUtils.nextAfter(po2,
+ double po2minus = Math.nextAfter(po2,
Double.NEGATIVE_INFINITY);
failures += testUlpCase(po2minus, expected/2.0f);
}
@@ -1575,7 +1575,7 @@
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
- testUlpCase(FpUtils.nextAfter(top, 0.0f),
+ testUlpCase(Math.nextAfter(top, 0.0f),
Double.MIN_VALUE);
if( i >= 10) {
--- a/jdk/test/java/lang/Math/Log10Tests.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/Log10Tests.java Sun Sep 18 18:14:07 2011 -0700
@@ -153,12 +153,12 @@
for(int i = 0; i < half; i++) {
if (i == 0) {
input[half] = 1.0;
- up = FpUtils.nextUp(1.0);
+ up = Math.nextUp(1.0);
down = FpUtils.nextDown(1.0);
} else {
input[half + i] = up;
input[half - i] = down;
- up = FpUtils.nextUp(up);
+ up = Math.nextUp(up);
down = FpUtils.nextDown(down);
}
}
--- a/jdk/test/java/lang/Math/Log1pTests.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/Log1pTests.java Sun Sep 18 18:14:07 2011 -0700
@@ -88,14 +88,14 @@
// For |x| < 2^-54 log1p(x) ~= x
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i <= -54; i++) {
- double d = FpUtils.scalb(2, i);
+ double d = Math.scalb(2, i);
failures += testLog1pCase(d, d);
failures += testLog1pCase(-d, -d);
}
// For x > 2^53 log1p(x) ~= log(x)
for(int i = 53; i <= DoubleConsts.MAX_EXPONENT; i++) {
- double d = FpUtils.scalb(2, i);
+ double d = Math.scalb(2, i);
failures += testLog1pCaseWithUlpDiff(d, StrictMath.log(d), 2.001);
}
@@ -105,7 +105,7 @@
for(int i = 0; i < 1000; i++) {
double d = rand.nextDouble();
- d = FpUtils.scalb(d, -53 - FpUtils.ilogb(d));
+ d = Math.scalb(d, -53 - FpUtils.ilogb(d));
for(int j = -53; j <= 52; j++) {
failures += testLog1pCaseWithUlpDiff(d, hp15cLogp(d), 5);
@@ -137,8 +137,8 @@
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
- pcNeighbors[3] = FpUtils.nextUp(pc);
- pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
+ pcNeighbors[3] = Math.nextUp(pc);
+ pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsLog1p[j] = Math.log1p(pcNeighbors[j]);
--- a/jdk/test/java/lang/Math/Rint.java Sun Sep 18 12:33:56 2011 +0100
+++ b/jdk/test/java/lang/Math/Rint.java Sun Sep 18 18:14:07 2011 -0700
@@ -48,7 +48,7 @@
public static void main(String args[]) {
int failures = 0;
- double twoToThe52 = FpUtils.scalb(1.0, 52); // 2^52
+ double twoToThe52 = Math.scalb(1.0, 52); // 2^52
double [][] testCases = {
{0.0, 0.0},
@@ -60,16 +60,16 @@
{FpUtils.nextDown(0.5), 0.0},
{ 0.5, 0.0},
- { FpUtils.nextUp(0.5), 1.0},
+ { Math.nextUp(0.5), 1.0},
{0.7, 1.0},
{FpUtils.nextDown(1.0), 1.0},
{ 1.0, 1.0},
- { FpUtils.nextUp(1.0), 1.0},
+ { Math.nextUp(1.0), 1.0},
{FpUtils.nextDown(1.5), 1.0},
{ 1.5, 2.0},
- { FpUtils.nextUp(1.5), 2.0},
+ { Math.nextUp(1.5), 2.0},
{4.2, 4.0},
{4.5, 4.0},
@@ -81,10 +81,10 @@
{150000.75, 150001.0},
{300000.5, 300000.0},
- {FpUtils.nextUp(300000.5), 300001.0},
+ {Math.nextUp(300000.5), 300001.0},
{FpUtils.nextDown(300000.75), 300001.0},
{300000.75, 300001.0},
- {FpUtils.nextUp(300000.75), 300001.0},
+ {Math.nextUp(300000.75), 300001.0},
{300000.99, 300001.0},
{262144.75, 262145.0}, //(2^18 ) + 0.75
{499998.75, 499999.0},
@@ -93,7 +93,7 @@
{FpUtils.nextDown(twoToThe52), twoToThe52},
{twoToThe52, twoToThe52},
- {FpUtils.nextUp(twoToThe52), FpUtils.nextUp(twoToThe52)},
+ {Math.nextUp(twoToThe52), Math.nextUp(twoToThe52)},
{Double.MAX_VALUE, Double.MAX_VALUE},
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},