--- old/src/share/classes/java/lang/Double.java 2010-12-01 13:01:46.000000000 -0800
+++ new/src/share/classes/java/lang/Double.java 2010-12-01 13:01:45.000000000 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2010, 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
@@ -973,7 +973,8 @@
if (d1 > d2)
return 1; // Neither val is NaN, thisVal is larger
- long thisBits = Double.doubleToLongBits(d1);
+ // Cannot use doubleToRawLongBits because of possibility of NaNs.
+ long thisBits = Double.doubleToLongBits(d1);
long anotherBits = Double.doubleToLongBits(d2);
return (thisBits == anotherBits ? 0 : // Values are equal
--- old/src/share/classes/java/lang/Float.java 2010-12-01 13:01:46.000000000 -0800
+++ new/src/share/classes/java/lang/Float.java 2010-12-01 13:01:46.000000000 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2010, 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
@@ -872,12 +872,13 @@
* @since 1.4
*/
public static int compare(float f1, float f2) {
- if (f1 < f2)
+ if (f1 < f2)
return -1; // Neither val is NaN, thisVal is smaller
if (f1 > f2)
return 1; // Neither val is NaN, thisVal is larger
- int thisBits = Float.floatToIntBits(f1);
+ // Cannot use floatToRawIntBits because of possibility of NaNs.
+ int thisBits = Float.floatToIntBits(f1);
int anotherBits = Float.floatToIntBits(f2);
return (thisBits == anotherBits ? 0 : // Values are equal
--- old/src/share/classes/java/lang/StrictMath.java 2010-12-01 13:01:47.000000000 -0800
+++ new/src/share/classes/java/lang/StrictMath.java 2010-12-01 13:01:47.000000000 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2010, 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
@@ -801,8 +801,9 @@
return (a >= b) ? a : b;
}
- private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f);
- private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d);
+ // Use raw bit-wise conversions on guaranteed non-NaN arguments.
+ private static long negativeZeroFloatBits = Float.floatToRawIntBits(-0.0f);
+ private static long negativeZeroDoubleBits = Double.doubleToRawLongBits(-0.0d);
/**
* Returns the greater of two {@code float} values. That is,
@@ -819,9 +820,12 @@
* @return the larger of {@code a} and {@code b}.
*/
public static float max(float a, float b) {
- if (a != a) return a; // a is NaN
- if ((a == 0.0f) && (b == 0.0f)
- && (Float.floatToIntBits(a) == negativeZeroFloatBits)) {
+ if (a != a)
+ return a; // a is NaN
+ if ((a == 0.0f) &&
+ (b == 0.0f) &&
+ (Float.floatToRawIntBits(a) == negativeZeroFloatBits)) {
+ // Raw conversion ok since NaN can't map to -0.0.
return b;
}
return (a >= b) ? a : b;
@@ -842,9 +846,12 @@
* @return the larger of {@code a} and {@code b}.
*/
public static double max(double a, double b) {
- if (a != a) return a; // a is NaN
- if ((a == 0.0d) && (b == 0.0d)
- && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) {
+ if (a != a)
+ return a; // a is NaN
+ if ((a == 0.0d) &&
+ (b == 0.0d) &&
+ (Double.doubleToRawLongBits(a) == negativeZeroDoubleBits)) {
+ // Raw conversion ok since NaN can't map to -0.0.
return b;
}
return (a >= b) ? a : b;
@@ -893,9 +900,12 @@
* @return the smaller of {@code a} and {@code b.}
*/
public static float min(float a, float b) {
- if (a != a) return a; // a is NaN
- if ((a == 0.0f) && (b == 0.0f)
- && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
+ if (a != a)
+ return a; // a is NaN
+ if ((a == 0.0f) &&
+ (b == 0.0f) &&
+ (Float.floatToRawIntBits(b) == negativeZeroFloatBits)) {
+ // Raw conversion ok since NaN can't map to -0.0.
return b;
}
return (a <= b) ? a : b;
@@ -916,9 +926,12 @@
* @return the smaller of {@code a} and {@code b}.
*/
public static double min(double a, double b) {
- if (a != a) return a; // a is NaN
- if ((a == 0.0d) && (b == 0.0d)
- && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
+ if (a != a)
+ return a; // a is NaN
+ if ((a == 0.0d) &&
+ (b == 0.0d) &&
+ (Double.doubleToRawLongBits(b) == negativeZeroDoubleBits)) {
+ // Raw conversion ok since NaN can't map to -0.0.
return b;
}
return (a <= b) ? a : b;
--- old/src/share/classes/sun/misc/FpUtils.java 2010-12-01 13:01:48.000000000 -0800
+++ new/src/share/classes/sun/misc/FpUtils.java 2010-12-01 13:01:48.000000000 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2010 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,9 +29,9 @@
import sun.misc.DoubleConsts;
/**
- * The class FpUtils
contains static utility methods for
- * manipulating and inspecting float
and
- * double
floating-point numbers. These methods include
+ * The class {@code FpUtils} contains static utility methods for
+ * manipulating and inspecting {@code float} and
+ * {@code double} floating-point numbers. These methods include
* functionality recommended or required by the IEEE 754
* floating-point standard.
*
@@ -136,7 +136,7 @@
// tests for exception cases.
/**
- * Returns unbiased exponent of a double
.
+ * Returns unbiased exponent of a {@code double}.
*/
public static int getExponent(double d){
/*
@@ -149,7 +149,7 @@
}
/**
- * Returns unbiased exponent of a float
.
+ * Returns unbiased exponent of a {@code float}.
*/
public static int getExponent(float f){
/*
@@ -185,15 +185,15 @@
* Returns the first floating-point argument with the sign of the
* second floating-point argument. Note that unlike the {@link
* FpUtils#copySign(double, double) copySign} method, this method
- * does not require NaN sign
arguments to be treated
+ * does not require NaN {@code sign} arguments to be treated
* as positive values; implementations are permitted to treat some
* NaN arguments as positive and other NaN arguments as negative
* to allow greater performance.
*
* @param magnitude the parameter providing the magnitude of the result
* @param sign the parameter providing the sign of the result
- * @return a value with the magnitude of magnitude
- * and the sign of sign
.
+ * @return a value with the magnitude of {@code magnitude}
+ * and the sign of {@code sign}.
* @author Joseph D. Darcy
*/
public static double rawCopySign(double magnitude, double sign) {
@@ -208,15 +208,15 @@
* Returns the first floating-point argument with the sign of the
* second floating-point argument. Note that unlike the {@link
* FpUtils#copySign(float, float) copySign} method, this method
- * does not require NaN sign
arguments to be treated
+ * does not require NaN {@code sign} arguments to be treated
* as positive values; implementations are permitted to treat some
* NaN arguments as positive and other NaN arguments as negative
* to allow greater performance.
*
* @param magnitude the parameter providing the magnitude of the result
* @param sign the parameter providing the sign of the result
- * @return a value with the magnitude of magnitude
- * and the sign of sign
.
+ * @return a value with the magnitude of {@code magnitude}
+ * and the sign of {@code sign}.
* @author Joseph D. Darcy
*/
public static float rawCopySign(float magnitude, float sign) {
@@ -230,129 +230,129 @@
/* ***************************************************************** */
/**
- * Returns true
if the argument is a finite
- * floating-point value; returns false
otherwise (for
+ * Returns {@code true} if the argument is a finite
+ * floating-point value; returns {@code false} otherwise (for
* NaN and infinity arguments).
*
- * @param d the double
value to be tested
- * @return true
if the argument is a finite
- * floating-point value, false
otherwise.
+ * @param d the {@code double} value to be tested
+ * @return {@code true} if the argument is a finite
+ * floating-point value, {@code false} otherwise.
*/
public static boolean isFinite(double d) {
return Math.abs(d) <= DoubleConsts.MAX_VALUE;
}
/**
- * Returns true
if the argument is a finite
- * floating-point value; returns false
otherwise (for
+ * Returns {@code true} if the argument is a finite
+ * floating-point value; returns {@code false} otherwise (for
* NaN and infinity arguments).
*
- * @param f the float
value to be tested
- * @return true
if the argument is a finite
- * floating-point value, false
otherwise.
+ * @param f the {@code float} value to be tested
+ * @return {@code true} if the argument is a finite
+ * floating-point value, {@code false} otherwise.
*/
public static boolean isFinite(float f) {
return Math.abs(f) <= FloatConsts.MAX_VALUE;
}
/**
- * Returns true
if the specified number is infinitely
- * large in magnitude, false
otherwise.
+ * Returns {@code true} if the specified number is infinitely
+ * large in magnitude, {@code false} otherwise.
*
*
Note that this method is equivalent to the {@link
* Double#isInfinite(double) Double.isInfinite} method; the
* functionality is included in this class for convenience.
*
* @param d the value to be tested.
- * @return true
if the value of the argument is positive
- * infinity or negative infinity; false
otherwise.
+ * @return {@code true} if the value of the argument is positive
+ * infinity or negative infinity; {@code false} otherwise.
*/
public static boolean isInfinite(double d) {
return Double.isInfinite(d);
}
/**
- * Returns true
if the specified number is infinitely
- * large in magnitude, false
otherwise.
+ * Returns {@code true} if the specified number is infinitely
+ * large in magnitude, {@code false} otherwise.
*
*
Note that this method is equivalent to the {@link
* Float#isInfinite(float) Float.isInfinite} method; the
* functionality is included in this class for convenience.
*
* @param f the value to be tested.
- * @return true
if the argument is positive infinity or
- * negative infinity; false
otherwise.
+ * @return {@code true} if the argument is positive infinity or
+ * negative infinity; {@code false} otherwise.
*/
public static boolean isInfinite(float f) {
return Float.isInfinite(f);
}
/**
- * Returns true
if the specified number is a
- * Not-a-Number (NaN) value, false
otherwise.
+ * Returns {@code true} if the specified number is a
+ * Not-a-Number (NaN) value, {@code false} otherwise.
*
*
Note that this method is equivalent to the {@link
* Double#isNaN(double) Double.isNaN} method; the functionality is
* included in this class for convenience.
*
* @param d the value to be tested.
- * @return true
if the value of the argument is NaN;
- * false
otherwise.
+ * @return {@code true} if the value of the argument is NaN;
+ * {@code false} otherwise.
*/
public static boolean isNaN(double d) {
return Double.isNaN(d);
}
/**
- * Returns true
if the specified number is a
- * Not-a-Number (NaN) value, false
otherwise.
+ * Returns {@code true} if the specified number is a
+ * Not-a-Number (NaN) value, {@code false} otherwise.
*
*
Note that this method is equivalent to the {@link
* Float#isNaN(float) Float.isNaN} method; the functionality is
* included in this class for convenience.
*
* @param f the value to be tested.
- * @return true
if the argument is NaN;
- * false
otherwise.
+ * @return {@code true} if the argument is NaN;
+ * {@code false} otherwise.
*/
public static boolean isNaN(float f) {
return Float.isNaN(f);
}
/**
- * Returns true
if the unordered relation holds
+ * Returns {@code true} if the unordered relation holds
* between the two arguments. When two floating-point values are
* unordered, one value is neither less than, equal to, nor
* greater than the other. For the unordered relation to be true,
- * at least one argument must be a NaN
.
+ * at least one argument must be a {@code NaN}.
*
* @param arg1 the first argument
* @param arg2 the second argument
- * @return true
if at least one argument is a NaN,
- * false
otherwise.
+ * @return {@code true} if at least one argument is a NaN,
+ * {@code false} otherwise.
*/
public static boolean isUnordered(double arg1, double arg2) {
return isNaN(arg1) || isNaN(arg2);
}
/**
- * Returns true
if the unordered relation holds
+ * Returns {@code true} if the unordered relation holds
* between the two arguments. When two floating-point values are
* unordered, one value is neither less than, equal to, nor
* greater than the other. For the unordered relation to be true,
- * at least one argument must be a NaN
.
+ * at least one argument must be a {@code NaN}.
*
* @param arg1 the first argument
* @param arg2 the second argument
- * @return true
if at least one argument is a NaN,
- * false
otherwise.
+ * @return {@code true} if at least one argument is a NaN,
+ * {@code false} otherwise.
*/
public static boolean isUnordered(float arg1, float arg2) {
return isNaN(arg1) || isNaN(arg2);
}
/**
- * Returns unbiased exponent of a double
; for
+ * Returns unbiased exponent of a {@code double}; for
* subnormal values, the number is treated as if it were
* normalized. That is for all finite, non-zero, positive numbers
* x, scalb(x, -ilogb(x))
is
@@ -378,7 +378,6 @@
return (1<<30); // 2^30
else // infinite value
return (1<<28); // 2^28
- // break;
case DoubleConsts.MIN_EXPONENT-1: // zero or subnormal
if(d == 0.0) {
@@ -414,18 +413,16 @@
exponent < DoubleConsts.MIN_EXPONENT);
return exponent;
}
- // break;
default:
assert( exponent >= DoubleConsts.MIN_EXPONENT &&
exponent <= DoubleConsts.MAX_EXPONENT);
return exponent;
- // break;
}
}
/**
- * Returns unbiased exponent of a float
; for
+ * Returns unbiased exponent of a {@code float}; for
* subnormal values, the number is treated as if it were
* normalized. That is for all finite, non-zero, positive numbers
* x, scalb(x, -ilogb(x))
is
@@ -451,7 +448,6 @@
return (1<<30); // 2^30
else // infinite value
return (1<<28); // 2^28
- // break;
case FloatConsts.MIN_EXPONENT-1: // zero or subnormal
if(f == 0.0f) {
@@ -487,13 +483,11 @@
exponent < FloatConsts.MIN_EXPONENT);
return exponent;
}
- // break;
default:
assert( exponent >= FloatConsts.MIN_EXPONENT &&
exponent <= FloatConsts.MAX_EXPONENT);
return exponent;
- // break;
}
}
@@ -534,22 +528,22 @@
*/
/**
- * Return d
×
- * 2scale_factor
rounded as if performed
+ * Return {@code d} ×
+ * 2{@code scale_factor} rounded as if performed
* by a single correctly rounded floating-point multiply to a
* member of the double value set. See §4.2.3
* of the Java
* Language Specification for a discussion of floating-point
* value sets. If the exponent of the result is between the
- * double
's minimum exponent and maximum exponent,
+ * {@code double}'s minimum exponent and maximum exponent,
* the answer is calculated exactly. If the exponent of the
- * result would be larger than doubles
's maximum
+ * result would be larger than {@code doubles}'s maximum
* exponent, an infinity is returned. Note that if the result is
- * subnormal, precision may be lost; that is, when scalb(x,
- * n)
is subnormal, scalb(scalb(x, n), -n)
may
+ * subnormal, precision may be lost; that is, when {@code scalb(x,
+ * n)} is subnormal, {@code scalb(scalb(x, n), -n)} may
* not equal x. When the result is non-NaN, the result has
- * the same sign as d
.
+ * the same sign as {@code d}.
*
*
* Special cases:
@@ -562,8 +556,8 @@
*
*
* @param d number to be scaled by a power of two.
- * @param scale_factor power of 2 used to scale d
- * @return d *
2scale_factor
+ * @param scale_factor power of 2 used to scale {@code d}
+ * @return {@code d * }2{@code scale_factor}
* @author Joseph D. Darcy
*/
public static double scalb(double d, int scale_factor) {
@@ -644,22 +638,22 @@
}
/**
- * Return f
×
- * 2scale_factor
rounded as if performed
+ * Return {@code f} ×
+ * 2{@code scale_factor} rounded as if performed
* by a single correctly rounded floating-point multiply to a
* member of the float value set. See §4.2.3
* of the Java
* Language Specification for a discussion of floating-point
* value set. If the exponent of the result is between the
- * float
's minimum exponent and maximum exponent, the
+ * {@code float}'s minimum exponent and maximum exponent, the
* answer is calculated exactly. If the exponent of the result
- * would be larger than float
's maximum exponent, an
+ * would be larger than {@code float}'s maximum exponent, an
* infinity is returned. Note that if the result is subnormal,
- * precision may be lost; that is, when scalb(x, n)
- * is subnormal, scalb(scalb(x, n), -n)
may not equal
+ * precision may be lost; that is, when {@code scalb(x, n)}
+ * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
* x. When the result is non-NaN, the result has the same
- * sign as f
.
+ * sign as {@code f}.
*
*
* Special cases:
@@ -672,8 +666,8 @@
*
*
* @param f number to be scaled by a power of two.
- * @param scale_factor power of 2 used to scale f
- * @return f *
2scale_factor
+ * @param scale_factor power of 2 used to scale {@code f}
+ * @return {@code f * }2{@code scale_factor}
* @author Joseph D. Darcy
*/
public static float scalb(float f, int scale_factor) {
@@ -709,34 +703,34 @@
*
direction
+ * start
is
- * ±Double.MIN_VALUE
and direction
+ * start
+ * magnitude, then a zero with the same sign as {@code start}
* is returned.
*
- * start
is infinite and
- * direction
has a value such that the result should
- * have a smaller magnitude, Double.MAX_VALUE
with the
- * same sign as start
is returned.
+ * start
is equal to ±
- * Double.MAX_VALUE
and direction
has a
+ * start
is returned.
+ * infinity with same sign as {@code start} is returned.
* start
's neighbors or start
should
+ * {@code start}'s neighbors or {@code start} should
* be returned
- * @return The floating-point number adjacent to start
in the
- * direction of direction
.
+ * @return The floating-point number adjacent to {@code start} in the
+ * direction of {@code direction}.
* @author Joseph D. Darcy
*/
public static double nextAfter(double start, double direction) {
@@ -809,34 +803,34 @@
* float
- * zero with the same sign as direction
is returned
+ * start
is
- * ±Float.MIN_VALUE
and direction
+ * start
+ * magnitude, then a zero with the same sign as {@code start}
* is returned.
*
- * start
is infinite and
- * direction
has a value such that the result should
- * have a smaller magnitude, Float.MAX_VALUE
with the
- * same sign as start
is returned.
+ * start
is equal to ±
- * Float.MAX_VALUE
and direction
has a
+ * start
is returned.
+ * infinity with same sign as {@code start} is returned.
* start
's neighbors or start
should
+ * {@code start}'s neighbors or {@code start} should
* be returned
- * @return The floating-point number adjacent to start
in the
- * direction of direction
.
+ * @return The floating-point number adjacent to {@code start} in the
+ * direction of {@code direction}.
* @author Joseph D. Darcy
*/
public static float nextAfter(float start, double direction) {
@@ -900,12 +894,12 @@
}
/**
- * Returns the floating-point value adjacent to d
in
+ * Returns the floating-point value adjacent to {@code d} in
* the direction of positive infinity. This method is
- * semantically equivalent to nextAfter(d,
- * Double.POSITIVE_INFINITY)
; however, a nextUp
+ * semantically equivalent to {@code nextAfter(d,
+ * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
* implementation may run faster than its equivalent
- * nextAfter
call.
+ * {@code nextAfter} call.
*
* Special Cases: *
Double.MIN_VALUE
+ * {@code Double.MIN_VALUE}
*
* f
in
+ * Returns the floating-point value adjacent to {@code f} in
* the direction of positive infinity. This method is
- * semantically equivalent to nextAfter(f,
- * Double.POSITIVE_INFINITY)
; however, a nextUp
+ * semantically equivalent to {@code nextAfter(f,
+ * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
* implementation may run faster than its equivalent
- * nextAfter
call.
+ * {@code nextAfter} call.
*
* Special Cases: *
Float.MIN_VALUE
+ * {@code Float.MIN_VALUE}
*
* d
in
+ * Returns the floating-point value adjacent to {@code d} in
* the direction of negative infinity. This method is
- * semantically equivalent to nextAfter(d,
- * Double.NEGATIVE_INFINITY)
; however, a
- * nextDown
implementation may run faster than its
- * equivalent nextAfter
call.
+ * semantically equivalent to {@code nextAfter(d,
+ * Double.NEGATIVE_INFINITY)}; however, a
+ * {@code nextDown} implementation may run faster than its
+ * equivalent {@code nextAfter} call.
*
* Special Cases: *
-Double.MIN_VALUE
+ * {@code -Double.MIN_VALUE}
*
* f
in
+ * Returns the floating-point value adjacent to {@code f} in
* the direction of negative infinity. This method is
- * semantically equivalent to nextAfter(f,
- * Float.NEGATIVE_INFINITY)
; however, a
- * nextDown
implementation may run faster than its
- * equivalent nextAfter
call.
+ * semantically equivalent to {@code nextAfter(f,
+ * Float.NEGATIVE_INFINITY)}; however, a
+ * {@code nextDown} implementation may run faster than its
+ * equivalent {@code nextAfter} call.
*
* Special Cases: *
-Float.MIN_VALUE
+ * {@code -Float.MIN_VALUE}
*
* sign
argument is always treated as if it were
+ * {@code sign} argument is always treated as if it were
* positive.
*
* @param magnitude the parameter providing the magnitude of the result
* @param sign the parameter providing the sign of the result
- * @return a value with the magnitude of magnitude
- * and the sign of sign
.
+ * @return a value with the magnitude of {@code magnitude}
+ * and the sign of {@code sign}.
* @author Joseph D. Darcy
* @since 1.5
*/
@@ -1063,13 +1057,13 @@
/**
* Returns the first floating-point argument with the sign of the
* second floating-point argument. For this method, a NaN
- * sign
argument is always treated as if it were
+ * {@code sign} argument is always treated as if it were
* positive.
*
* @param magnitude the parameter providing the magnitude of the result
* @param sign the parameter providing the sign of the result
- * @return a value with the magnitude of magnitude
- * and the sign of sign
.
+ * @return a value with the magnitude of {@code magnitude}
+ * and the sign of {@code sign}.
* @author Joseph D. Darcy
*/
public static float copySign(float magnitude, float sign) {
@@ -1078,8 +1072,8 @@
/**
* Returns the size of an ulp of the argument. An ulp of a
- * double
value is the positive distance between this
- * floating-point value and the double
value next
+ * {@code double} value is the positive distance between this
+ * floating-point value and the {@code double} value next
* larger in magnitude. Note that for non-NaN x,
* ulp(-x) == ulp(x)
.
*
@@ -1089,8 +1083,8 @@
* Double.MIN_VALUE
.
- * Double.MAX_VALUE
, then
+ * {@code Double.MIN_VALUE}.
+ * float
value is the positive distance between this
- * floating-point value and the float
value next
+ * {@code float} value is the positive distance between this
+ * floating-point value and the {@code float} value next
* larger in magnitude. Note that for non-NaN x,
* ulp(-x) == ulp(x)
.
*
@@ -1143,8 +1134,8 @@
* Float.MIN_VALUE
.
- * Float.MAX_VALUE
, then
+ * {@code Float.MIN_VALUE}.
+ *