Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8268224: Cleanup references to "strictfp" in core lib comments
Reviewed-by: jrose
  • Loading branch information
jddarcy committed Jun 4, 2021
1 parent 516e60a commit 05df172
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 97 deletions.
81 changes: 25 additions & 56 deletions src/java.base/share/classes/java/lang/Math.java
Expand Up @@ -1794,9 +1794,6 @@ public static double fma(double a, double b, double c) {
infiniteB && a == 0.0 ) {
return Double.NaN;
}
// Store product in a double field to cause an
// overflow even if non-strictfp evaluation is being
// used.
double product = a * b;
if (Double.isInfinite(product) && !infiniteA && !infiniteB) {
// Intermediate overflow; might cause a
Expand Down Expand Up @@ -2662,20 +2659,17 @@ public static float nextDown(float f) {
}

/**
* Returns {@code d} ×
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
* by a single correctly rounded floating-point multiply to a
* member of the double value set. See the Java
* Language Specification for a discussion of floating-point
* value sets. If the exponent of the result is between {@link
* Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
* answer is calculated exactly. If the exponent of the result
* would be larger than {@code Double.MAX_EXPONENT}, an
* infinity is returned. Note that if the result is subnormal,
* precision may be lost; that is, when {@code scalb(x, n)}
* is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
* <i>x</i>. When the result is non-NaN, the result has the same
* sign as {@code d}.
* Returns {@code d} &times; 2<sup>{@code scaleFactor}</sup>
* rounded as if performed by a single correctly rounded
* floating-point multiply. If the exponent of the result is
* between {@link Double#MIN_EXPONENT} and {@link
* Double#MAX_EXPONENT}, the answer is calculated exactly. If the
* exponent of the result would be larger than {@code
* Double.MAX_EXPONENT}, an infinity is returned. Note that if
* the result is subnormal, precision may be lost; that is, when
* {@code scalb(x, n)} is subnormal, {@code scalb(scalb(x, n),
* -n)} may not equal <i>x</i>. When the result is non-NaN, the
* result has the same sign as {@code d}.
*
* <p>Special cases:
* <ul>
Expand All @@ -2693,9 +2687,7 @@ public static float nextDown(float f) {
*/
public static double scalb(double d, int scaleFactor) {
/*
* This method does not need to be declared strictfp to
* compute the same correct result on all platforms. When
* scaling up, it does not matter what order the
* When scaling up, it does not matter what order the
* multiply-store operations are done; the result will be
* finite or overflow regardless of the operation ordering.
* However, to get the correct result when scaling down, a
Expand All @@ -2709,25 +2701,7 @@ public static double scalb(double d, int scaleFactor) {
* by 2 ^ (scaleFactor % n) and then multiplying several
* times by 2^n as needed where n is the exponent of number
* that is a convenient power of two. In this way, at most one
* real rounding error occurs. If the double value set is
* being used exclusively, the rounding will occur on a
* multiply. If the double-extended-exponent value set is
* being used, the products will (perhaps) be exact but the
* stores to d are guaranteed to round to the double value
* set.
*
* It is _not_ a valid implementation to first multiply d by
* 2^MIN_EXPONENT and then by 2 ^ (scaleFactor %
* MIN_EXPONENT) since even in a strictfp program double
* rounding on underflow could occur; e.g. if the scaleFactor
* argument was (MIN_EXPONENT - n) and the exponent of d was a
* little less than -(MIN_EXPONENT - n), meaning the final
* result would be subnormal.
*
* Since exact reproducibility of this method can be achieved
* without any undue performance burden, there is no
* compelling reason to allow double rounding on underflow in
* scalb.
* real rounding error occurs.
*/

// magnitude of a power of two so large that scaling a finite
Expand Down Expand Up @@ -2769,20 +2743,17 @@ public static double scalb(double d, int scaleFactor) {
}

/**
* Returns {@code f} &times;
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
* by a single correctly rounded floating-point multiply to a
* member of the float value set. See the Java
* Language Specification for a discussion of floating-point
* value sets. If the exponent of the result is between {@link
* Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
* answer is calculated exactly. If the exponent of the result
* would be larger than {@code Float.MAX_EXPONENT}, an
* infinity is returned. Note that if the result is subnormal,
* precision may be lost; that is, when {@code scalb(x, n)}
* is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
* <i>x</i>. When the result is non-NaN, the result has the same
* sign as {@code f}.
* Returns {@code f} &times; 2<sup>{@code scaleFactor}</sup>
* rounded as if performed by a single correctly rounded
* floating-point multiply. If the exponent of the result is
* between {@link Float#MIN_EXPONENT} and {@link
* Float#MAX_EXPONENT}, the answer is calculated exactly. If the
* exponent of the result would be larger than {@code
* Float.MAX_EXPONENT}, an infinity is returned. Note that if the
* result is subnormal, precision may be lost; that is, when
* {@code scalb(x, n)} is subnormal, {@code scalb(scalb(x, n),
* -n)} may not equal <i>x</i>. When the result is non-NaN, the
* result has the same sign as {@code f}.
*
* <p>Special cases:
* <ul>
Expand Down Expand Up @@ -2814,9 +2785,7 @@ public static float scalb(float f, int scaleFactor) {
* exponent range and + float -> double conversion is exact
* the multiplication below will be exact. Therefore, the
* rounding that occurs when the double product is cast to
* float will be the correctly rounded float result. Since
* all operations other than the final multiply will be exact,
* it is not necessary to declare this method strictfp.
* float will be the correctly rounded float result.
*/
return (float)((double)f*powerOfTwoD(scaleFactor));
}
Expand Down
63 changes: 22 additions & 41 deletions src/java.base/share/classes/java/lang/StrictMath.java
Expand Up @@ -469,19 +469,6 @@ public static double rint(double a) {
* away any fractional portion of a since ulp(twoToThe52) ==
* 1.0; subtracting out twoToThe52 from this sum will then be
* exact and leave the rounded integer portion of a.
*
* This method does *not* need to be declared strictfp to get
* fully reproducible results. Whether or not a method is
* declared strictfp can only make a difference in the
* returned result if some operation would overflow or
* underflow with strictfp semantics. The operation
* (twoToThe52 + a ) cannot overflow since large values of a
* are screened out; the add cannot underflow since twoToThe52
* is too large. The subtraction ((twoToThe52 + a ) -
* twoToThe52) will be exact as discussed above and thus
* cannot overflow or meaningfully underflow. Finally, the
* last multiply in the return statement is by plus or minus
* 1.0, which is exact too.
*/
double twoToThe52 = (double)(1L << 52); // 2^52
double sign = Math.copySign(1.0, a); // preserve sign info
Expand Down Expand Up @@ -2060,20 +2047,17 @@ public static float nextDown(float f) {
}

/**
* Returns {@code d} &times;
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
* by a single correctly rounded floating-point multiply to a
* member of the double value set. See the Java
* Language Specification for a discussion of floating-point
* value sets. If the exponent of the result is between {@link
* Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
* answer is calculated exactly. If the exponent of the result
* would be larger than {@code Double.MAX_EXPONENT}, an
* infinity is returned. Note that if the result is subnormal,
* precision may be lost; that is, when {@code scalb(x, n)}
* is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
* <i>x</i>. When the result is non-NaN, the result has the same
* sign as {@code d}.
* Returns {@code d} &times; 2<sup>{@code scaleFactor}</sup>
* rounded as if performed by a single correctly rounded
* floating-point multiply. If the exponent of the result is
* between {@link Double#MIN_EXPONENT} and {@link
* Double#MAX_EXPONENT}, the answer is calculated exactly. If the
* exponent of the result would be larger than {@code
* Double.MAX_EXPONENT}, an infinity is returned. Note that if
* the result is subnormal, precision may be lost; that is, when
* {@code scalb(x, n)} is subnormal, {@code scalb(scalb(x, n),
* -n)} may not equal <i>x</i>. When the result is non-NaN, the
* result has the same sign as {@code d}.
*
* <p>Special cases:
* <ul>
Expand All @@ -2094,20 +2078,17 @@ public static double scalb(double d, int scaleFactor) {
}

/**
* Returns {@code f} &times;
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
* by a single correctly rounded floating-point multiply to a
* member of the float value set. See the Java
* Language Specification for a discussion of floating-point
* value sets. If the exponent of the result is between {@link
* Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
* answer is calculated exactly. If the exponent of the result
* would be larger than {@code Float.MAX_EXPONENT}, an
* infinity is returned. Note that if the result is subnormal,
* precision may be lost; that is, when {@code scalb(x, n)}
* is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
* <i>x</i>. When the result is non-NaN, the result has the same
* sign as {@code f}.
* Returns {@code f} &times; 2<sup>{@code scaleFactor}</sup>
* rounded as if performed by a single correctly rounded
* floating-point multiply. If the exponent of the result is
* between {@link Float#MIN_EXPONENT} and {@link
* Float#MAX_EXPONENT}, the answer is calculated exactly. If the
* exponent of the result would be larger than {@code
* Float.MAX_EXPONENT}, an infinity is returned. Note that if the
* result is subnormal, precision may be lost; that is, when
* {@code scalb(x, n)} is subnormal, {@code scalb(scalb(x, n),
* -n)} may not equal <i>x</i>. When the result is non-NaN, the
* result has the same sign as {@code f}.
*
* <p>Special cases:
* <ul>
Expand Down

1 comment on commit 05df172

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.