7091682: Move sun.misc.FpUtils code into java.lang.Math
Reviewed-by: alanb
diff --git a/test/java/lang/Double/ToHexString.java b/test/java/lang/Double/ToHexString.java
index fcea456..c9fb07e 100644
--- a/test/java/lang/Double/ToHexString.java
+++ b/test/java/lang/Double/ToHexString.java
@@ -29,7 +29,6 @@
*/
import java.util.regex.*;
-import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class ToHexString {
diff --git a/test/java/lang/Math/CubeRootTests.java b/test/java/lang/Math/CubeRootTests.java
index 6b70da3..8b82183 100644
--- a/test/java/lang/Math/CubeRootTests.java
+++ b/test/java/lang/Math/CubeRootTests.java
@@ -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]);
diff --git a/test/java/lang/Math/Expm1Tests.java b/test/java/lang/Math/Expm1Tests.java
index 49fb968..f0f55d4 100644
--- a/test/java/lang/Math/Expm1Tests.java
+++ b/test/java/lang/Math/Expm1Tests.java
@@ -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]);
diff --git a/test/java/lang/Math/HyperbolicTests.java b/test/java/lang/Math/HyperbolicTests.java
index db12157..d82da69 100644
--- a/test/java/lang/Math/HyperbolicTests.java
+++ b/test/java/lang/Math/HyperbolicTests.java
@@ -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);
}
diff --git a/test/java/lang/Math/HypotTests.java b/test/java/lang/Math/HypotTests.java
index e124220..465497e 100644
--- a/test/java/lang/Math/HypotTests.java
+++ b/test/java/lang/Math/HypotTests.java
@@ -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]);
diff --git a/test/java/lang/Math/IeeeRecommendedTests.java b/test/java/lang/Math/IeeeRecommendedTests.java
index 6b4199e..68e8a5c 100644
--- a/test/java/lang/Math/IeeeRecommendedTests.java
+++ b/test/java/lang/Math/IeeeRecommendedTests.java
@@ -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) {
diff --git a/test/java/lang/Math/Log10Tests.java b/test/java/lang/Math/Log10Tests.java
index 60d9ec6..c245a74 100644
--- a/test/java/lang/Math/Log10Tests.java
+++ b/test/java/lang/Math/Log10Tests.java
@@ -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);
}
}
diff --git a/test/java/lang/Math/Log1pTests.java b/test/java/lang/Math/Log1pTests.java
index 1666d7b..bd5f0e0 100644
--- a/test/java/lang/Math/Log1pTests.java
+++ b/test/java/lang/Math/Log1pTests.java
@@ -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]);
diff --git a/test/java/lang/Math/Rint.java b/test/java/lang/Math/Rint.java
index 49a8edd..09821c8 100644
--- a/test/java/lang/Math/Rint.java
+++ b/test/java/lang/Math/Rint.java
@@ -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},