test/java/lang/Math/CubeRootTests.java

Print this page

        

*** 93,121 **** 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(FpUtils.scalb(1.0, 3*i), ! FpUtils.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) ); } // 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(FpUtils.scalb(1.0, 55)) & DoubleConsts.EXP_BIT_MASK; long exponentBits2= ! Double.doubleToLongBits(FpUtils.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 // exponent double input1 = --- 93,121 ---- 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)) & DoubleConsts.EXP_BIT_MASK; long exponentBits2= ! 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 // exponent double input1 =
*** 175,194 **** double y1 = Math.cbrt(d); double y2 = StrictMath.cbrt(d); err = d - StrictMath.pow(y1, 3); if (err != 0.0) { ! if(FpUtils.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; } else { // (err > 0.0) ! err_adjacent = StrictMath.pow(FpUtils.nextAfter(y1,0.0), 3) - d; } if (Math.abs(err) > Math.abs(err_adjacent)) { failures++; System.err.println("For Math.cbrt(" + d + "), returned result " + --- 175,194 ---- double y1 = Math.cbrt(d); double y2 = StrictMath.cbrt(d); err = d - StrictMath.pow(y1, 3); if (err != 0.0) { ! 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(Math.nextUp(y1), 3) - d; } else { // (err > 0.0) ! err_adjacent = StrictMath.pow(Math.nextAfter(y1,0.0), 3) - d; } if (Math.abs(err) > Math.abs(err_adjacent)) { failures++; System.err.println("For Math.cbrt(" + d + "), returned result " +
*** 198,217 **** } err = d - StrictMath.pow(y2, 3); if (err != 0.0) { ! if(FpUtils.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; } else { // (err > 0.0) ! err_adjacent = StrictMath.pow(FpUtils.nextAfter(y2,0.0), 3) - d; } if (Math.abs(err) > Math.abs(err_adjacent)) { failures++; System.err.println("For StrictMath.cbrt(" + d + "), returned result " + --- 198,217 ---- } err = d - StrictMath.pow(y2, 3); if (err != 0.0) { ! 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(Math.nextUp(y2), 3) - d; } else { // (err > 0.0) ! err_adjacent = StrictMath.pow(Math.nextAfter(y2,0.0), 3) - d; } if (Math.abs(err) > Math.abs(err_adjacent)) { failures++; System.err.println("For StrictMath.cbrt(" + d + "), returned result " +
*** 240,256 **** 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 = FpUtils.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]); for(int j = 0; j < pcNeighbors.length; j++) { pcNeighborsCbrt[j] = Math.cbrt(pcNeighbors[j]); pcNeighborsStrictCbrt[j] = StrictMath.cbrt(pcNeighbors[j]); } --- 240,256 ---- 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] = FpUtils.nextDown(pc); pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]); ! 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]); pcNeighborsStrictCbrt[j] = StrictMath.cbrt(pcNeighbors[j]); }
*** 278,295 **** } } // 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); 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]); for(int j = 0; j < pcNeighbors.length; j++) { pcNeighborsCbrt[j] = Math.cbrt(pcNeighbors[j]); pcNeighborsStrictCbrt[j] = StrictMath.cbrt(pcNeighbors[j]); } --- 278,295 ---- } } // 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] = FpUtils.nextDown(pc); pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]); ! 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]); pcNeighborsStrictCbrt[j] = StrictMath.cbrt(pcNeighbors[j]); }