8149896: Remove unnecessary values in FloatConsts and DoubleConsts

Reviewed-by: shade, psandoz, lbourges, mduigou
This commit is contained in:
Joe Darcy 2016-02-16 09:09:31 -08:00
parent e4e9015254
commit a188f9045f
9 changed files with 59 additions and 131 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2016, 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
@ -301,7 +301,7 @@ public final class Double extends Number implements Comparable<Double> {
if(d == 0.0) {
answer.append("0.0p0");
} else {
boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
boolean subnormal = (d < Double.MIN_NORMAL);
// Isolate significand bits and OR in a high-order bit
// so that the string representation has a known
@ -329,7 +329,7 @@ public final class Double extends Number implements Comparable<Double> {
// exponent (the representation of a subnormal uses
// E_min -1).
answer.append(subnormal ?
DoubleConsts.MIN_EXPONENT:
Double.MIN_EXPONENT:
Math.getExponent(d));
}
return answer.toString();
@ -574,7 +574,7 @@ public final class Double extends Number implements Comparable<Double> {
* @since 1.8
*/
public static boolean isFinite(double d) {
return Math.abs(d) <= DoubleConsts.MAX_VALUE;
return Math.abs(d) <= Double.MAX_VALUE;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2016, 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
@ -26,8 +26,6 @@
package java.lang;
import jdk.internal.math.FloatingDecimal;
import jdk.internal.math.FloatConsts;
import jdk.internal.math.DoubleConsts;
import jdk.internal.HotSpotIntrinsicCandidate;
/**
@ -282,15 +280,15 @@ public final class Float extends Number implements Comparable<Float> {
* @author Joseph D. Darcy
*/
public static String toHexString(float f) {
if (Math.abs(f) < FloatConsts.MIN_NORMAL
if (Math.abs(f) < Float.MIN_NORMAL
&& f != 0.0f ) {// float subnormal
// Adjust exponent to create subnormal double, then
// replace subnormal double exponent with subnormal float
// exponent
String s = Double.toHexString(Math.scalb((double)f,
/* -1022+126 */
DoubleConsts.MIN_EXPONENT-
FloatConsts.MIN_EXPONENT));
Double.MIN_EXPONENT-
Float.MIN_EXPONENT));
return s.replaceFirst("p-1022$", "p-126");
}
else // double string will be the same as float string
@ -489,7 +487,7 @@ public final class Float extends Number implements Comparable<Float> {
* @since 1.8
*/
public static boolean isFinite(float f) {
return Math.abs(f) <= FloatConsts.MAX_VALUE;
return Math.abs(f) <= Float.MAX_VALUE;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2016, 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
@ -1476,18 +1476,18 @@ public final class Math {
int exp = getExponent(d);
switch(exp) {
case DoubleConsts.MAX_EXPONENT+1: // NaN or infinity
case Double.MAX_EXPONENT + 1: // NaN or infinity
return Math.abs(d);
case DoubleConsts.MIN_EXPONENT-1: // zero or subnormal
case Double.MIN_EXPONENT - 1: // zero or subnormal
return Double.MIN_VALUE;
default:
assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT;
assert exp <= Double.MAX_EXPONENT && exp >= Double.MIN_EXPONENT;
// ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
exp = exp - (DoubleConsts.SIGNIFICAND_WIDTH-1);
if (exp >= DoubleConsts.MIN_EXPONENT) {
if (exp >= Double.MIN_EXPONENT) {
return powerOfTwoD(exp);
}
else {
@ -1495,7 +1495,7 @@ public final class Math {
// representation of Double.MIN_VALUE appropriate
// number of positions
return Double.longBitsToDouble(1L <<
(exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) ));
(exp - (Double.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) ));
}
}
}
@ -1527,26 +1527,25 @@ public final class Math {
int exp = getExponent(f);
switch(exp) {
case FloatConsts.MAX_EXPONENT+1: // NaN or infinity
case Float.MAX_EXPONENT+1: // NaN or infinity
return Math.abs(f);
case FloatConsts.MIN_EXPONENT-1: // zero or subnormal
return FloatConsts.MIN_VALUE;
case Float.MIN_EXPONENT-1: // zero or subnormal
return Float.MIN_VALUE;
default:
assert exp <= FloatConsts.MAX_EXPONENT && exp >= FloatConsts.MIN_EXPONENT;
assert exp <= Float.MAX_EXPONENT && exp >= Float.MIN_EXPONENT;
// ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
exp = exp - (FloatConsts.SIGNIFICAND_WIDTH-1);
if (exp >= FloatConsts.MIN_EXPONENT) {
if (exp >= Float.MIN_EXPONENT) {
return powerOfTwoF(exp);
}
else {
} else {
// return a subnormal result; left shift integer
// representation of FloatConsts.MIN_VALUE appropriate
// number of positions
return Float.intBitsToFloat(1 <<
(exp - (FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1)) ));
(exp - (Float.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1)) ));
}
}
}
@ -2276,7 +2275,7 @@ public final class Math {
// nonzero value by it would be guaranteed to over or
// underflow; due to rounding, scaling down takes an
// additional power of two which is reflected here
final int MAX_SCALE = DoubleConsts.MAX_EXPONENT + -DoubleConsts.MIN_EXPONENT +
final int MAX_SCALE = Double.MAX_EXPONENT + -Double.MIN_EXPONENT +
DoubleConsts.SIGNIFICAND_WIDTH + 1;
int exp_adjust = 0;
int scale_increment = 0;
@ -2345,7 +2344,7 @@ public final class Math {
// nonzero value by it would be guaranteed to over or
// underflow; due to rounding, scaling down takes an
// additional power of two which is reflected here
final int MAX_SCALE = FloatConsts.MAX_EXPONENT + -FloatConsts.MIN_EXPONENT +
final int MAX_SCALE = Float.MAX_EXPONENT + -Float.MIN_EXPONENT +
FloatConsts.SIGNIFICAND_WIDTH + 1;
// Make sure scaling factor is in a reasonable range
@ -2371,7 +2370,7 @@ public final class Math {
* Returns a floating-point power of two in the normal range.
*/
static double powerOfTwoD(int n) {
assert(n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT);
assert(n >= Double.MIN_EXPONENT && n <= Double.MAX_EXPONENT);
return Double.longBitsToDouble((((long)n + (long)DoubleConsts.EXP_BIAS) <<
(DoubleConsts.SIGNIFICAND_WIDTH-1))
& DoubleConsts.EXP_BIT_MASK);
@ -2381,7 +2380,7 @@ public final class Math {
* Returns a floating-point power of two in the normal range.
*/
static float powerOfTwoF(int n) {
assert(n >= FloatConsts.MIN_EXPONENT && n <= FloatConsts.MAX_EXPONENT);
assert(n >= Float.MIN_EXPONENT && n <= Float.MAX_EXPONENT);
return Float.intBitsToFloat(((n + FloatConsts.EXP_BIAS) <<
(FloatConsts.SIGNIFICAND_WIDTH-1))
& FloatConsts.EXP_BIT_MASK);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2016, 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
@ -3440,7 +3440,7 @@ public final class Formatter implements Closeable, Flushable {
int exponent = Math.getExponent(d);
boolean subnormal
= (exponent == DoubleConsts.MIN_EXPONENT - 1);
= (exponent == Double.MIN_EXPONENT - 1);
// If this is subnormal input so normalize (could be faster to
// do as integer operation).
@ -3450,8 +3450,8 @@ public final class Formatter implements Closeable, Flushable {
// Calculate the exponent. This is not just exponent + 54
// since the former is not the normalized exponent.
exponent = Math.getExponent(d);
assert exponent >= DoubleConsts.MIN_EXPONENT &&
exponent <= DoubleConsts.MAX_EXPONENT: exponent;
assert exponent >= Double.MIN_EXPONENT &&
exponent <= Double.MAX_EXPONENT: exponent;
}
int precision = 1 + prec*4;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2016, 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,7 @@ package jdk.internal.math;
/**
* This class contains additional constants documenting limits of the
* <code>double</code> type.
* {@code double} type.
*
* @author Joseph D. Darcy
*/
@ -38,69 +38,38 @@ public class DoubleConsts {
*/
private DoubleConsts() {}
public static final double POSITIVE_INFINITY = java.lang.Double.POSITIVE_INFINITY;
public static final double NEGATIVE_INFINITY = java.lang.Double.NEGATIVE_INFINITY;
public static final double NaN = java.lang.Double.NaN;
public static final double MAX_VALUE = java.lang.Double.MAX_VALUE;
public static final double MIN_VALUE = java.lang.Double.MIN_VALUE;
/**
* A constant holding the smallest positive normal value of type
* <code>double</code>, 2<sup>-1022</sup>. It is equal to the
* value returned by
* <code>Double.longBitsToDouble(0x0010000000000000L)</code>.
*
* @since 1.5
*/
public static final double MIN_NORMAL = 2.2250738585072014E-308;
/**
* The number of logical bits in the significand of a
* <code>double</code> number, including the implicit bit.
* {@code double} number, including the implicit bit.
*/
public static final int SIGNIFICAND_WIDTH = 53;
/**
* Maximum exponent a finite <code>double</code> number may have.
* It is equal to the value returned by
* <code>Math.ilogb(Double.MAX_VALUE)</code>.
*/
public static final int MAX_EXPONENT = 1023;
/**
* Minimum exponent a normalized <code>double</code> number may
* have. It is equal to the value returned by
* <code>Math.ilogb(Double.MIN_NORMAL)</code>.
*/
public static final int MIN_EXPONENT = -1022;
/**
* The exponent the smallest positive <code>double</code>
* The exponent the smallest positive {@code double}
* subnormal value would have if it could be normalized..
*/
public static final int MIN_SUB_EXPONENT = MIN_EXPONENT -
public static final int MIN_SUB_EXPONENT = Double.MIN_EXPONENT -
(SIGNIFICAND_WIDTH - 1);
/**
* Bias used in representing a <code>double</code> exponent.
* Bias used in representing a {@code double} exponent.
*/
public static final int EXP_BIAS = 1023;
/**
* Bit mask to isolate the sign bit of a <code>double</code>.
* Bit mask to isolate the sign bit of a {@code double}.
*/
public static final long SIGN_BIT_MASK = 0x8000000000000000L;
/**
* Bit mask to isolate the exponent field of a
* <code>double</code>.
* {@code double}.
*/
public static final long EXP_BIT_MASK = 0x7FF0000000000000L;
/**
* Bit mask to isolate the significand field of a
* <code>double</code>.
* {@code double}.
*/
public static final long SIGNIF_BIT_MASK = 0x000FFFFFFFFFFFFFL;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2016, 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,7 @@ package jdk.internal.math;
/**
* This class contains additional constants documenting limits of the
* <code>float</code> type.
* {@code float} type.
*
* @author Joseph D. Darcy
*/
@ -38,65 +38,38 @@ public class FloatConsts {
*/
private FloatConsts() {}
public static final float POSITIVE_INFINITY = java.lang.Float.POSITIVE_INFINITY;
public static final float NEGATIVE_INFINITY = java.lang.Float.NEGATIVE_INFINITY;
public static final float NaN = java.lang.Float.NaN;
public static final float MAX_VALUE = java.lang.Float.MAX_VALUE;
public static final float MIN_VALUE = java.lang.Float.MIN_VALUE;
/**
* A constant holding the smallest positive normal value of type
* <code>float</code>, 2<sup>-126</sup>. It is equal to the value
* returned by <code>Float.intBitsToFloat(0x00800000)</code>.
*/
public static final float MIN_NORMAL = 1.17549435E-38f;
/**
* The number of logical bits in the significand of a
* <code>float</code> number, including the implicit bit.
* {@code float} number, including the implicit bit.
*/
public static final int SIGNIFICAND_WIDTH = 24;
/**
* Maximum exponent a finite <code>float</code> number may have.
* It is equal to the value returned by
* <code>Math.ilogb(Float.MAX_VALUE)</code>.
*/
public static final int MAX_EXPONENT = 127;
/**
* Minimum exponent a normalized <code>float</code> number may
* have. It is equal to the value returned by
* <code>Math.ilogb(Float.MIN_NORMAL)</code>.
*/
public static final int MIN_EXPONENT = -126;
/**
* The exponent the smallest positive <code>float</code> subnormal
* The exponent the smallest positive {@code float} subnormal
* value would have if it could be normalized.
*/
public static final int MIN_SUB_EXPONENT = MIN_EXPONENT -
public static final int MIN_SUB_EXPONENT = Float.MIN_EXPONENT -
(SIGNIFICAND_WIDTH - 1);
/**
* Bias used in representing a <code>float</code> exponent.
* Bias used in representing a {@code float} exponent.
*/
public static final int EXP_BIAS = 127;
/**
* Bit mask to isolate the sign bit of a <code>float</code>.
* Bit mask to isolate the sign bit of a {@code float}.
*/
public static final int SIGN_BIT_MASK = 0x80000000;
/**
* Bit mask to isolate the exponent field of a
* <code>float</code>.
* {@code float}.
*/
public static final int EXP_BIT_MASK = 0x7F800000;
/**
* Bit mask to isolate the significand field of a
* <code>float</code>.
* {@code float}.
*/
public static final int SIGNIF_BIT_MASK = 0x007FFFFF;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2016, 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
@ -2377,8 +2377,8 @@ public class FloatingDecimal{
// Float calculations
int floatBits = isNegative ? FloatConsts.SIGN_BIT_MASK : 0;
if (exponent >= FloatConsts.MIN_EXPONENT) {
if (exponent > FloatConsts.MAX_EXPONENT) {
if (exponent >= Float.MIN_EXPONENT) {
if (exponent > Float.MAX_EXPONENT) {
// Float.POSITIVE_INFINITY
floatBits |= FloatConsts.EXP_BIT_MASK;
} else {
@ -2409,12 +2409,12 @@ public class FloatingDecimal{
float fValue = Float.intBitsToFloat(floatBits);
// Check for overflow and update exponent accordingly.
if (exponent > DoubleConsts.MAX_EXPONENT) { // Infinite result
if (exponent > Double.MAX_EXPONENT) { // Infinite result
// overflow to properly signed infinity
return isNegative ? A2BC_NEGATIVE_INFINITY : A2BC_POSITIVE_INFINITY;
} else { // Finite return value
if (exponent <= DoubleConsts.MAX_EXPONENT && // (Usually) normal result
exponent >= DoubleConsts.MIN_EXPONENT) {
if (exponent <= Double.MAX_EXPONENT && // (Usually) normal result
exponent >= Double.MIN_EXPONENT) {
// The result returned in this block cannot be a
// zero or subnormal; however after the
@ -2434,7 +2434,7 @@ public class FloatingDecimal{
(DoubleConsts.SIGNIF_BIT_MASK & significand);
} else { // Subnormal or zero
// (exponent < DoubleConsts.MIN_EXPONENT)
// (exponent < Double.MIN_EXPONENT)
if (exponent < (DoubleConsts.MIN_SUB_EXPONENT - 1)) {
// No way to round back to nonzero value
@ -2474,7 +2474,7 @@ public class FloatingDecimal{
// Now, discard the bits
significand = significand >> bitsDiscarded;
significand = ((((long) (DoubleConsts.MIN_EXPONENT - 1) + // subnorm exp.
significand = ((((long) (Double.MIN_EXPONENT - 1) + // subnorm exp.
(long) DoubleConsts.EXP_BIAS) <<
(DoubleConsts.SIGNIFICAND_WIDTH - 1))
& DoubleConsts.EXP_BIT_MASK) |

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, 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
@ -24,7 +24,6 @@
*/
package sun.java2d.marlin;
import jdk.internal.math.DoubleConsts;
import jdk.internal.math.FloatConsts;
/**
@ -210,14 +209,4 @@ public final class FloatMath implements MarlinConst {
}
return intpart - 1;
}
/**
* Returns a floating-point power of two in the normal range.
*/
static double powerOfTwoD(int n) {
assert (n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT);
return Double.longBitsToDouble((((long) n + (long) DoubleConsts.EXP_BIAS)
<< (DoubleConsts.SIGNIFICAND_WIDTH - 1))
& DoubleConsts.EXP_BIT_MASK);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2016, 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
@ -40,7 +40,7 @@ final class Renderer implements PathConsumer2D, MarlinConst {
private static final int ALL_BUT_LSB = 0xfffffffe;
private static final int ERR_STEP_MAX = 0x7fffffff; // = 2^31 - 1
private static final double POWER_2_TO_32 = FloatMath.powerOfTwoD(32);
private static final double POWER_2_TO_32 = 0x1.0p32;
// use float to make tosubpix methods faster (no int to float conversion)
public static final float f_SUBPIXEL_POSITIONS_X