## test/java/lang/Math/CubeRootTests.java

```*** 23,36 ****

/*
* @test
* @bug 4347132 4939441
* @summary Tests for {Math, StrictMath}.cbrt
* @author Joseph D. Darcy
*/

! import sun.misc.DoubleConsts;

public class CubeRootTests {
private CubeRootTests(){}

static final double infinityD = Double.POSITIVE_INFINITY;
--- 23,39 ----

/*
* @test
* @bug 4347132 4939441
* @summary Tests for {Math, StrictMath}.cbrt
+  * @library /lib/testlibrary
+  * @build jdk.testlibrary.DoubleUtils jdk.testlibrary.FloatUtils
+  * @run main CubeRootTests
* @author Joseph D. Darcy
*/

! import static jdk.testlibrary.DoubleUtils.*;

public class CubeRootTests {
private CubeRootTests(){}

static final double infinityD = Double.POSITIVE_INFINITY;
*** 91,136 ****
double d = i;
failures += testCubeRootCase(d*d*d, (double)i);
}

// Test cbrt(2^(3n)) = 2^n.
!         for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; 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 >= 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
// modest exponents but only have at most the 17 most
// 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(Math.scalb(1.0, 55)) &
long exponentBits2=
Double.doubleToLongBits(Math.scalb(1.0, -55)) &
for(int i = 0; i < 100; i++) {
// Take 16 bits since the 17th bit is implicit in the
// exponent
double input1 =
Double.longBitsToDouble(exponentBits1 |
// Significand bits
((long) (rand.nextInt() & 0xFFFF))<<
!                                        (DoubleConsts.SIGNIFICAND_WIDTH-1-16));
failures += testCubeRootCase(input1*input1*input1, input1);

double input2 =
Double.longBitsToDouble(exponentBits2 |
// Significand bits
((long) (rand.nextInt() & 0xFFFF))<<
!                                        (DoubleConsts.SIGNIFICAND_WIDTH-1-16));
failures += testCubeRootCase(input2*input2*input2, input2);
}

// Directly test quality of implementation properties of cbrt
// for values that aren't perfect cubes.  Verify returned
--- 94,139 ----
double d = i;
failures += testCubeRootCase(d*d*d, (double)i);
}

// Test cbrt(2^(3n)) = 2^n.
!         for(int i = 18; i <= Double.MAX_EXPONENT/3; 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 >= 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
// modest exponents but only have at most the 17 most
// 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(Math.scalb(1.0, 55)) &
long exponentBits2=
Double.doubleToLongBits(Math.scalb(1.0, -55)) &
for(int i = 0; i < 100; i++) {
// Take 16 bits since the 17th bit is implicit in the
// exponent
double input1 =
Double.longBitsToDouble(exponentBits1 |
// Significand bits
((long) (rand.nextInt() & 0xFFFF))<<
!                                        (SIGNIFICAND_WIDTH-1-16));
failures += testCubeRootCase(input1*input1*input1, input1);

double input2 =
Double.longBitsToDouble(exponentBits2 |
// Significand bits
((long) (rand.nextInt() & 0xFFFF))<<
!                                        (SIGNIFICAND_WIDTH-1-16));
failures += testCubeRootCase(input2*input2*input2, input2);
}

// Directly test quality of implementation properties of cbrt
// for values that aren't perfect cubes.  Verify returned
*** 238,248 ****
double pcNeighbors[] = new double[5];
double pcNeighborsCbrt[] = new double[5];
double pcNeighborsStrictCbrt[] = new double[5];

// Test near cbrt(2^(3n)) = 2^n.
!             for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; i++) {
double pc = Math.scalb(1.0, 3*i);

pcNeighbors[2] = pc;
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
--- 241,251 ----
double pcNeighbors[] = new double[5];
double pcNeighborsCbrt[] = new double[5];
double pcNeighborsStrictCbrt[] = new double[5];

// Test near cbrt(2^(3n)) = 2^n.
!             for(int i = 18; i <= Double.MAX_EXPONENT/3; i++) {
double pc = Math.scalb(1.0, 3*i);

pcNeighbors[2] = pc;
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
*** 277,287 ****
}

}

// Test near cbrt(2^(-3n)) = 2^-n.
!             for(int i = -1; i >= DoubleConsts.MIN_SUB_EXPONENT/3; i--) {
double pc = Math.scalb(1.0, 3*i);

pcNeighbors[2] = pc;
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
--- 280,290 ----
}

}

// Test near cbrt(2^(-3n)) = 2^-n.
!             for(int i = -1; i >= MIN_SUB_EXPONENT/3; i--) {
double pc = Math.scalb(1.0, 3*i);

pcNeighbors[2] = pc;
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
```