提交 b80f5552 编写于 作者: D darcy

7092404: Add Math.nextDown and Double.isFinite

Reviewed-by: mduigou
上级 299cf0f0
......@@ -276,7 +276,7 @@ public final class Double extends Number implements Comparable<Double> {
* 7.19.6.1; however, the output of this method is more
* tightly specified.
*/
if (!FpUtils.isFinite(d) )
if (!isFinite(d) )
// For infinity and NaN, use the decimal output.
return Double.toString(d);
else {
......@@ -548,7 +548,7 @@ public final class Double extends Number implements Comparable<Double> {
* @return {@code true} if the value of the argument is NaN;
* {@code false} otherwise.
*/
static public boolean isNaN(double v) {
public static boolean isNaN(double v) {
return (v != v);
}
......@@ -560,10 +560,24 @@ public final class Double extends Number implements Comparable<Double> {
* @return {@code true} if the value of the argument is positive
* infinity or negative infinity; {@code false} otherwise.
*/
static public boolean isInfinite(double v) {
public static boolean isInfinite(double v) {
return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
}
/**
* Returns {@code true} if the argument is a finite floating-point
* value; returns {@code false} otherwise (for NaN and infinity
* arguments).
*
* @param d the {@code double} value to be tested
* @return {@code true} if the argument is a finite
* floating-point value, {@code false} otherwise.
* @since 1.8
*/
public static boolean isFinite(double d) {
return Math.abs(d) <= DoubleConsts.MAX_VALUE;
}
/**
* The value of the Double.
*
......
......@@ -459,7 +459,7 @@ public final class Float extends Number implements Comparable<Float> {
* @return {@code true} if the argument is NaN;
* {@code false} otherwise.
*/
static public boolean isNaN(float v) {
public static boolean isNaN(float v) {
return (v != v);
}
......@@ -471,10 +471,25 @@ public final class Float extends Number implements Comparable<Float> {
* @return {@code true} if the argument is positive infinity or
* negative infinity; {@code false} otherwise.
*/
static public boolean isInfinite(float v) {
public static boolean isInfinite(float v) {
return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
}
/**
* Returns {@code true} if the argument is a finite floating-point
* value; returns {@code false} otherwise (for NaN and infinity
* arguments).
*
* @param f the {@code float} value to be tested
* @return {@code true} if the argument is a finite
* floating-point value, {@code false} otherwise.
* @since 1.8
*/
public static boolean isFinite(float f) {
return Math.abs(f) <= FloatConsts.MAX_VALUE;
}
/**
* The value of the Float.
*
......
......@@ -1649,6 +1649,79 @@ public final class Math {
}
}
/**
* Returns the floating-point value adjacent to {@code d} in
* the direction of negative infinity. This method is
* semantically equivalent to {@code nextAfter(d,
* Double.NEGATIVE_INFINITY)}; however, a
* {@code nextDown} implementation may run faster than its
* equivalent {@code nextAfter} call.
*
* <p>Special Cases:
* <ul>
* <li> If the argument is NaN, the result is NaN.
*
* <li> If the argument is negative infinity, the result is
* negative infinity.
*
* <li> If the argument is zero, the result is
* {@code -Double.MIN_VALUE}
*
* </ul>
*
* @param d starting floating-point value
* @return The adjacent floating-point value closer to negative
* infinity.
* @since 1.8
*/
public static double nextDown(double d) {
if (Double.isNaN(d) || d == Double.NEGATIVE_INFINITY)
return d;
else {
if (d == 0.0)
return -Double.MIN_VALUE;
else
return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
((d > 0.0d)?-1L:+1L));
}
}
/**
* Returns the floating-point value adjacent to {@code f} in
* the direction of negative infinity. This method is
* semantically equivalent to {@code nextAfter(f,
* Float.NEGATIVE_INFINITY)}; however, a
* {@code nextDown} implementation may run faster than its
* equivalent {@code nextAfter} call.
*
* <p>Special Cases:
* <ul>
* <li> If the argument is NaN, the result is NaN.
*
* <li> If the argument is negative infinity, the result is
* negative infinity.
*
* <li> If the argument is zero, the result is
* {@code -Float.MIN_VALUE}
*
* </ul>
*
* @param f starting floating-point value
* @return The adjacent floating-point value closer to negative
* infinity.
* @since 1.8
*/
public static float nextDown(float f) {
if (Float.isNaN(f) || f == Float.NEGATIVE_INFINITY)
return f;
else {
if (f == 0.0f)
return -Float.MIN_VALUE;
else
return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
((f > 0.0f)?-1:+1));
}
}
/**
* Return {@code d} &times;
......
......@@ -1396,6 +1396,64 @@ public final class StrictMath {
return Math.nextUp(f);
}
/**
* Returns the floating-point value adjacent to {@code d} in
* the direction of negative infinity. This method is
* semantically equivalent to {@code nextAfter(d,
* Double.NEGATIVE_INFINITY)}; however, a
* {@code nextDown} implementation may run faster than its
* equivalent {@code nextAfter} call.
*
* <p>Special Cases:
* <ul>
* <li> If the argument is NaN, the result is NaN.
*
* <li> If the argument is negative infinity, the result is
* negative infinity.
*
* <li> If the argument is zero, the result is
* {@code -Double.MIN_VALUE}
*
* </ul>
*
* @param d starting floating-point value
* @return The adjacent floating-point value closer to negative
* infinity.
* @since 1.8
*/
public static double nextDown(double d) {
return Math.nextDown(d);
}
/**
* Returns the floating-point value adjacent to {@code f} in
* the direction of negative infinity. This method is
* semantically equivalent to {@code nextAfter(f,
* Float.NEGATIVE_INFINITY)}; however, a
* {@code nextDown} implementation may run faster than its
* equivalent {@code nextAfter} call.
*
* <p>Special Cases:
* <ul>
* <li> If the argument is NaN, the result is NaN.
*
* <li> If the argument is negative infinity, the result is
* negative infinity.
*
* <li> If the argument is zero, the result is
* {@code -Float.MIN_VALUE}
*
* </ul>
*
* @param f starting floating-point value
* @return The adjacent floating-point value closer to negative
* infinity.
* @since 1.8
*/
public static float nextDown(float f) {
return Math.nextDown(f);
}
/**
* Return {@code d} &times;
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
......
......@@ -50,7 +50,6 @@ import java.text.NumberFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
import sun.misc.FormattedFloatingDecimal;
......@@ -3417,7 +3416,7 @@ public final class Formatter implements Closeable, Flushable {
// Method assumes that d > 0.
private String hexDouble(double d, int prec) {
// Let Double.toHexString handle simple cases
if(!FpUtils.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13)
if(!Double.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13)
// remove "0x"
return Double.toHexString(d).substring(2);
else {
......
......@@ -202,9 +202,11 @@ public class FpUtils {
* @param d the {@code double} value to be tested
* @return {@code true} if the argument is a finite
* floating-point value, {@code false} otherwise.
* @deprecated Use Double.isFinite.
*/
@Deprecated
public static boolean isFinite(double d) {
return Math.abs(d) <= DoubleConsts.MAX_VALUE;
return Double.isFinite(d);
}
/**
......@@ -215,9 +217,11 @@ public class FpUtils {
* @param f the {@code float} value to be tested
* @return {@code true} if the argument is a finite
* floating-point value, {@code false} otherwise.
* @deprecated Use Float.isFinite.
*/
@Deprecated
public static boolean isFinite(float f) {
return Math.abs(f) <= FloatConsts.MAX_VALUE;
return Float.isFinite(f);
}
/**
......@@ -746,17 +750,11 @@ public class FpUtils {
* @return The adjacent floating-point value closer to negative
* infinity.
* @author Joseph D. Darcy
* @deprecated Use Math.nextDown.
*/
@Deprecated
public static double nextDown(double d) {
if( isNaN(d) || d == Double.NEGATIVE_INFINITY)
return d;
else {
if (d == 0.0)
return -Double.MIN_VALUE;
else
return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
((d > 0.0d)?-1L:+1L));
}
return Math.nextDown(d);
}
/**
......@@ -783,17 +781,11 @@ public class FpUtils {
* @return The adjacent floating-point value closer to negative
* infinity.
* @author Joseph D. Darcy
* @deprecated Use Math.nextDown.
*/
@Deprecated
public static double nextDown(float f) {
if( isNaN(f) || f == Float.NEGATIVE_INFINITY)
return f;
else {
if (f == 0.0f)
return -Float.MIN_VALUE;
else
return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
((f > 0.0f)?-1:+1));
}
return Math.nextDown(f);
}
/**
......
/*
* Copyright (c) 2003, 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
......@@ -30,7 +30,6 @@
import java.util.regex.*;
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class ParseHexFloatingPoint {
......@@ -227,7 +226,7 @@ public class ParseHexFloatingPoint {
new PairSD("0x1.000000000000001p-1075", Double.MIN_VALUE),
// More subnormal rounding tests
new PairSD("0x0.fffffffffffff7fffffp-1022", FpUtils.nextDown(DoubleConsts.MIN_NORMAL)),
new PairSD("0x0.fffffffffffff7fffffp-1022", Math.nextDown(DoubleConsts.MIN_NORMAL)),
new PairSD("0x0.fffffffffffff8p-1022", DoubleConsts.MIN_NORMAL),
new PairSD("0x0.fffffffffffff800000001p-1022",DoubleConsts.MIN_NORMAL),
new PairSD("0x0.fffffffffffff80000000000000001p-1022",DoubleConsts.MIN_NORMAL),
......@@ -242,10 +241,10 @@ public class ParseHexFloatingPoint {
new PairSD("0x1.fffffffffffff8p1023", infinityD),
new PairSD("0x1.fffffffffffff8000001p1023", infinityD),
new PairSD("0x1.ffffffffffffep1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe0000p1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe8p1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe7p1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffep1023", Math.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe0000p1023", Math.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe8p1023", Math.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe7p1023", Math.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffeffffffp1023", Double.MAX_VALUE),
new PairSD("0x1.ffffffffffffe8000001p1023", Double.MAX_VALUE),
};
......@@ -284,8 +283,8 @@ public class ParseHexFloatingPoint {
};
double [] answers = {
FpUtils.nextDown(FpUtils.nextDown(2.0)),
FpUtils.nextDown(2.0),
Math.nextDown(Math.nextDown(2.0)),
Math.nextDown(2.0),
2.0
};
......
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 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
......@@ -27,7 +27,6 @@
* @summary Check for correct implementation of Math.ceil and Math.floor
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class CeilAndFloorTests {
......@@ -69,7 +68,7 @@ public class CeilAndFloorTests {
for(int i = Double.MIN_EXPONENT; i <= Double.MAX_EXPONENT; i++) {
double powerOfTwo = Math.scalb(1.0, i);
double neighborDown = FpUtils.nextDown(powerOfTwo);
double neighborDown = Math.nextDown(powerOfTwo);
double neighborUp = Math.nextUp(powerOfTwo);
if (i < 0) {
......@@ -114,7 +113,7 @@ public class CeilAndFloorTests {
for(int i = -(0x10000); i <= 0x10000; i++) {
double d = (double) i;
double neighborDown = FpUtils.nextDown(d);
double neighborDown = Math.nextDown(d);
double neighborUp = Math.nextUp(d);
failures += testCeilCase( d, d);
......@@ -140,8 +139,8 @@ public class CeilAndFloorTests {
double [][] testCases = {
{ Double.MIN_VALUE, 1.0},
{-Double.MIN_VALUE, -0.0},
{ FpUtils.nextDown(DoubleConsts.MIN_NORMAL), 1.0},
{-FpUtils.nextDown(DoubleConsts.MIN_NORMAL), -0.0},
{ Math.nextDown(DoubleConsts.MIN_NORMAL), 1.0},
{-Math.nextDown(DoubleConsts.MIN_NORMAL), -0.0},
{ DoubleConsts.MIN_NORMAL, 1.0},
{-DoubleConsts.MIN_NORMAL, -0.0},
......@@ -157,8 +156,8 @@ public class CeilAndFloorTests {
{ 2.5, 3.0},
{-2.5, -2.0},
{ FpUtils.nextDown(1.0), 1.0},
{ FpUtils.nextDown(-1.0), -1.0},
{ Math.nextDown(1.0), 1.0},
{ Math.nextDown(-1.0), -1.0},
{ Math.nextUp(1.0), 2.0},
{ Math.nextUp(-1.0), -0.0},
......@@ -166,17 +165,17 @@ public class CeilAndFloorTests {
{ 0x1.0p51, 0x1.0p51},
{-0x1.0p51, -0x1.0p51},
{ FpUtils.nextDown(0x1.0p51), 0x1.0p51},
{ Math.nextDown(0x1.0p51), 0x1.0p51},
{-Math.nextUp(0x1.0p51), -0x1.0p51},
{ Math.nextUp(0x1.0p51), 0x1.0p51+1},
{-FpUtils.nextDown(0x1.0p51), -0x1.0p51+1},
{-Math.nextDown(0x1.0p51), -0x1.0p51+1},
{ FpUtils.nextDown(0x1.0p52), 0x1.0p52},
{ Math.nextDown(0x1.0p52), 0x1.0p52},
{-Math.nextUp(0x1.0p52), -0x1.0p52-1.0},
{ Math.nextUp(0x1.0p52), 0x1.0p52+1.0},
{-FpUtils.nextDown(0x1.0p52), -0x1.0p52+1.0},
{-Math.nextDown(0x1.0p52), -0x1.0p52+1.0},
};
for(double[] testCase : testCases) {
......
/*
* Copyright (c) 2003, 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
......@@ -28,7 +28,6 @@
* @author Joseph D. Darcy
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class CubeRootTests {
......@@ -245,8 +244,8 @@ public class CubeRootTests {
double pc = Math.scalb(1.0, 3*i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
pcNeighbors[3] = Math.nextUp(pc);
pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
......@@ -284,8 +283,8 @@ public class CubeRootTests {
double pc = Math.scalb(1.0, 3*i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
pcNeighbors[3] = Math.nextUp(pc);
pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
......
/*
* Copyright (c) 2003, 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
......@@ -29,7 +29,6 @@
*/
import sun.misc.DoubleConsts;
import sun.misc.FpUtils;
/*
* The Taylor expansion of expxm1(x) = exp(x) -1 is
......@@ -143,8 +142,8 @@ public class Expm1Tests {
double pc = StrictMath.log(2)*i;
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
pcNeighbors[3] = Math.nextUp(pc);
pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
......
/*
* Copyright (c) 2003, 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
......@@ -29,7 +29,6 @@
*/
import sun.misc.DoubleConsts;
import sun.misc.FpUtils;
public class HyperbolicTests {
private HyperbolicTests(){}
......@@ -280,7 +279,7 @@ public class HyperbolicTests {
long trans22 = Double.doubleToLongBits(22.0);
// (approximately) largest value such that exp shouldn't
// overflow
long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
long transExpOvfl = Double.doubleToLongBits(Math.nextDown(709.7827128933841));
for(long i = trans22;
i < transExpOvfl;
......@@ -639,7 +638,7 @@ public class HyperbolicTests {
long trans22 = Double.doubleToLongBits(22.0);
// (approximately) largest value such that exp shouldn't
// overflow
long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
long transExpOvfl = Double.doubleToLongBits(Math.nextDown(709.7827128933841));
for(long i = trans22;
i < transExpOvfl;
......
/*
* Copyright (c) 2003, 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
......@@ -156,8 +156,8 @@ public class HypotTests {
double pc = Math.scalb(1.0, i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
pcNeighbors[3] = Math.nextUp(pc);
pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
......
/*
* Copyright (c) 2003, 2005, 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
......@@ -623,8 +623,11 @@ public class IeeeRecommendedTests {
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("FpUtils.nextDown(float)",
testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("Math.nextDown(float)",
testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("StrictMath.nextDown(float)",
testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
}
return failures;
......@@ -659,8 +662,11 @@ public class IeeeRecommendedTests {
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("FpUtils.nextDown(double)",
testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("Math.nextDown(double)",
testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("StrictMath.nextDown(double)",
testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
}
return failures;
......@@ -706,8 +712,8 @@ public class IeeeRecommendedTests {
FpUtils.isNaN(testCases[i]), (i ==0));
// isFinite
failures+=Tests.test("FpUtils.isFinite(float)", testCases[i],
FpUtils.isFinite(testCases[i]), (i >= 3));
failures+=Tests.test("Float.isFinite(float)", testCases[i],
Float.isFinite(testCases[i]), (i >= 3));
// isInfinite
failures+=Tests.test("FpUtils.isInfinite(float)", testCases[i],
......@@ -756,8 +762,8 @@ public class IeeeRecommendedTests {
FpUtils.isNaN(testCases[i]), (i ==0));
// isFinite
failures+=Tests.test("FpUtils.isFinite(double)", testCases[i],
FpUtils.isFinite(testCases[i]), (i >= 3));
failures+=Tests.test("Double.isFinite(double)", testCases[i],
Double.isFinite(testCases[i]), (i >= 3));
// isInfinite
failures+=Tests.test("FpUtils.isInfinite(double)", testCases[i],
......
/*
* Copyright (c) 2003, 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
......@@ -28,7 +28,6 @@
* @author Joseph D. Darcy
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class Log10Tests {
......@@ -98,13 +97,13 @@ public class Log10Tests {
// within a few ulps of log(x)/log(10)
for(int i = 0; i < 10000; i++) {
double input = Double.longBitsToDouble(rand.nextLong());
if(! FpUtils.isFinite(input))
if(! Double.isFinite(input))
continue; // avoid testing NaN and infinite values
else {
input = Math.abs(input);
double expected = StrictMath.log(input)/LN_10;
if( ! FpUtils.isFinite(expected))
if( ! Double.isFinite(expected))
continue; // if log(input) overflowed, try again
else {
double result;
......@@ -154,15 +153,15 @@ public class Log10Tests {
if (i == 0) {
input[half] = 1.0;
up = Math.nextUp(1.0);
down = FpUtils.nextDown(1.0);
down = Math.nextDown(1.0);
} else {
input[half + i] = up;
input[half - i] = down;
up = Math.nextUp(up);
down = FpUtils.nextDown(down);
down = Math.nextDown(down);
}
}
input[0] = FpUtils.nextDown(input[1]);
input[0] = Math.nextDown(input[1]);
for(int i = 0; i < neighbors.length; i++) {
neighbors[i] = Math.log10(input[i]);
......
/*
* Copyright (c) 2003, 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
......@@ -135,8 +135,8 @@ public class Log1pTests {
double pc = StrictMath.pow(Math.E, i) - 1;
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[1] = Math.nextDown(pc);
pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
pcNeighbors[3] = Math.nextUp(pc);
pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
......@@ -202,5 +202,4 @@ public class Log1pTests {
throw new RuntimeException();
}
}
}
/*
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
......@@ -25,10 +25,8 @@
* @test
* @bug 4101566 4831589
* @summary Check for correct implementation of Math.rint(double)
*
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class Rint {
......@@ -53,22 +51,22 @@ public class Rint {
double [][] testCases = {
{0.0, 0.0},
{Double.MIN_VALUE, 0.0},
{FpUtils.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
{Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
{DoubleConsts.MIN_NORMAL, 0.0},
{0.2, 0.0},
{FpUtils.nextDown(0.5), 0.0},
{ 0.5, 0.0},
{Math.nextDown(0.5), 0.0},
{ 0.5, 0.0},
{ Math.nextUp(0.5), 1.0},
{0.7, 1.0},
{FpUtils.nextDown(1.0), 1.0},
{ 1.0, 1.0},
{Math.nextDown(1.0), 1.0},
{ 1.0, 1.0},
{ Math.nextUp(1.0), 1.0},
{FpUtils.nextDown(1.5), 1.0},
{ 1.5, 2.0},
{Math.nextDown(1.5), 1.0},
{ 1.5, 2.0},
{ Math.nextUp(1.5), 2.0},
{4.2, 4.0},
......@@ -82,7 +80,7 @@ public class Rint {
{150000.75, 150001.0},
{300000.5, 300000.0},
{Math.nextUp(300000.5), 300001.0},
{FpUtils.nextDown(300000.75), 300001.0},
{Math.nextDown(300000.75), 300001.0},
{300000.75, 300001.0},
{Math.nextUp(300000.75), 300001.0},
{300000.99, 300001.0},
......@@ -91,7 +89,7 @@ public class Rint {
{524287.75, 524288.0}, //(2^19 -1) + 0.75
{524288.75, 524289.0},
{FpUtils.nextDown(twoToThe52), twoToThe52},
{Math.nextDown(twoToThe52), twoToThe52},
{twoToThe52, twoToThe52},
{Math.nextUp(twoToThe52), Math.nextUp(twoToThe52)},
......@@ -118,5 +116,4 @@ public class Rint {
throw new RuntimeException();
}
}
}
/*
* Copyright (c) 2003, 2007, 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
......@@ -36,7 +36,6 @@ import java.math.BigInteger;
import java.text.DateFormatSymbols;
import java.util.*;
#if[double]
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
#end[double]
......@@ -1301,9 +1300,9 @@ public class Basic$Type$ extends Basic {
test("%.11a", "0x1.00000000000p-1022", DoubleConsts.MIN_NORMAL);
test("%.1a", "0x1.0p-1022", DoubleConsts.MIN_NORMAL);
test("%.11a", "0x1.00000000000p-1022",
FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
Math.nextDown(DoubleConsts.MIN_NORMAL));
test("%.1a", "0x1.0p-1022",
FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
Math.nextDown(DoubleConsts.MIN_NORMAL));
test("%.11a", "0x1.ffffffffffep-1023",
Double.parseDouble("0x0.fffffffffffp-1022"));
test("%.1a", "0x1.0p-1022",
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
import static java.util.SimpleTimeZone.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -36,7 +36,6 @@ import java.math.BigInteger;
import java.text.DateFormatSymbols;
import java.util.*;
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
......@@ -1301,9 +1300,9 @@ public class BasicDouble extends Basic {
test("%.11a", "0x1.00000000000p-1022", DoubleConsts.MIN_NORMAL);
test("%.1a", "0x1.0p-1022", DoubleConsts.MIN_NORMAL);
test("%.11a", "0x1.00000000000p-1022",
FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
Math.nextDown(DoubleConsts.MIN_NORMAL));
test("%.1a", "0x1.0p-1022",
FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
Math.nextDown(DoubleConsts.MIN_NORMAL));
test("%.11a", "0x1.ffffffffffep-1023",
Double.parseDouble("0x0.fffffffffffp-1022"));
test("%.1a", "0x1.0p-1022",
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
/*
* Copyright (c) 2003, 2007, 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
......@@ -39,7 +39,6 @@ import java.util.*;
import static java.util.Calendar.*;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部