Save This Page
Home » openjdk-7 » sun » misc » [javadoc | source]
sun.misc
public class: FpUtils [javadoc | source]
java.lang.Object
   sun.misc.FpUtils
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.
Field Summary
static  double twoToTheDoubleScaleUp     
static  double twoToTheDoubleScaleDown     
Method from sun.misc.FpUtils Summary:
copySign,   copySign,   getExponent,   getExponent,   ilogb,   ilogb,   isFinite,   isFinite,   isInfinite,   isInfinite,   isNaN,   isNaN,   isUnordered,   isUnordered,   nextAfter,   nextAfter,   nextDown,   nextDown,   nextUp,   nextUp,   powerOfTwoD,   powerOfTwoF,   rawCopySign,   rawCopySign,   scalb,   scalb,   signum,   signum,   ulp,   ulp
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from sun.misc.FpUtils Detail:
 public static double copySign(double magnitude,
    double sign) 
    Returns the first floating-point argument with the sign of the second floating-point argument. For this method, a NaN {@code sign} argument is always treated as if it were positive.
 public static float copySign(float magnitude,
    float sign) 
    Returns the first floating-point argument with the sign of the second floating-point argument. For this method, a NaN {@code sign} argument is always treated as if it were positive.
 public static int getExponent(double d) 
    Returns unbiased exponent of a {@code double}.
 public static int getExponent(float f) 
    Returns unbiased exponent of a {@code float}.
 public static int ilogb(double d) 
    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 always in the range [1, 2).

    Special cases:

    • If the argument is NaN, then the result is 230.
    • If the argument is infinite, then the result is 228.
    • If the argument is zero, then the result is -(228).
 public static int ilogb(float f) 
    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 always in the range [1, 2).

    Special cases:

    • If the argument is NaN, then the result is 230.
    • If the argument is infinite, then the result is 228.
    • If the argument is zero, then the result is -(228).
 public static boolean isFinite(double d) 
    Returns {@code true} if the argument is a finite floating-point value; returns {@code false} otherwise (for NaN and infinity arguments).
 public static boolean isFinite(float f) 
    Returns {@code true} if the argument is a finite floating-point value; returns {@code false} otherwise (for NaN and infinity arguments).
 public static boolean isInfinite(double d) 
    Returns {@code true} if the specified number is infinitely large in magnitude, {@code false} otherwise.

    Note that this method is equivalent to the Double.isInfinite method; the functionality is included in this class for convenience.

 public static boolean isInfinite(float f) 
    Returns {@code true} if the specified number is infinitely large in magnitude, {@code false} otherwise.

    Note that this method is equivalent to the Float.isInfinite method; the functionality is included in this class for convenience.

 public static boolean isNaN(double d) 
    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 Double.isNaN method; the functionality is included in this class for convenience.

 public static boolean isNaN(float f) 
    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 Float.isNaN method; the functionality is included in this class for convenience.

 public static boolean isUnordered(double arg1,
    double arg2) 
    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 {@code NaN}.
 public static boolean isUnordered(float arg1,
    float arg2) 
    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 {@code NaN}.
 public static double nextAfter(double start,
    double direction) 
    Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal the second argument is returned.

    Special cases:

    • If either argument is a NaN, then NaN is returned.
    • If both arguments are signed zeros, {@code direction} is returned unchanged (as implied by the requirement of returning the second argument if the arguments compare as equal).
    • If {@code start} is ±{@code Double.MIN_VALUE} and {@code direction} has a value such that the result should have a smaller magnitude, then a zero with the same sign as {@code start} is returned.
    • If {@code start} is infinite and {@code direction} has a value such that the result should have a smaller magnitude, {@code Double.MAX_VALUE} with the same sign as {@code start} is returned.
    • If {@code start} is equal to ± {@code Double.MAX_VALUE} and {@code direction} has a value such that the result should have a larger magnitude, an infinity with same sign as {@code start} is returned.
 public static float nextAfter(float start,
    double direction) 
    Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal, the second argument is returned.

    Special cases:

    • If either argument is a NaN, then NaN is returned.
    • If both arguments are signed zeros, a {@code float} zero with the same sign as {@code direction} is returned (as implied by the requirement of returning the second argument if the arguments compare as equal).
    • If {@code start} is ±{@code Float.MIN_VALUE} and {@code direction} has a value such that the result should have a smaller magnitude, then a zero with the same sign as {@code start} is returned.
    • If {@code start} is infinite and {@code direction} has a value such that the result should have a smaller magnitude, {@code Float.MAX_VALUE} with the same sign as {@code start} is returned.
    • If {@code start} is equal to ± {@code Float.MAX_VALUE} and {@code direction} has a value such that the result should have a larger magnitude, an infinity with same sign as {@code start} is returned.
 public static double nextDown(double d) 
    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.

    Special Cases:

    • If the argument is NaN, the result is NaN.
    • If the argument is negative infinity, the result is negative infinity.
    • If the argument is zero, the result is {@code -Double.MIN_VALUE}
 public static double nextDown(float f) 
    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.

    Special Cases:

    • If the argument is NaN, the result is NaN.
    • If the argument is negative infinity, the result is negative infinity.
    • If the argument is zero, the result is {@code -Float.MIN_VALUE}
 public static double nextUp(double d) 
    Returns the floating-point value adjacent to {@code d} in the direction of positive infinity. This method is semantically equivalent to {@code nextAfter(d, Double.POSITIVE_INFINITY)}; however, a {@code nextUp} implementation may run faster than its equivalent {@code nextAfter} call.

    Special Cases:

    • If the argument is NaN, the result is NaN.
    • If the argument is positive infinity, the result is positive infinity.
    • If the argument is zero, the result is {@code Double.MIN_VALUE}
 public static float nextUp(float f) 
    Returns the floating-point value adjacent to {@code f} in the direction of positive infinity. This method is semantically equivalent to {@code nextAfter(f, Double.POSITIVE_INFINITY)}; however, a {@code nextUp} implementation may run faster than its equivalent {@code nextAfter} call.

    Special Cases:

    • If the argument is NaN, the result is NaN.
    • If the argument is positive infinity, the result is positive infinity.
    • If the argument is zero, the result is {@code Float.MIN_VALUE}
 static double powerOfTwoD(int n) 
    Returns a floating-point power of two in the normal range.
 static float powerOfTwoF(int n) 
    Returns a floating-point power of two in the normal range.
 public static double rawCopySign(double magnitude,
    double sign) 
    Returns the first floating-point argument with the sign of the second floating-point argument. Note that unlike the copySign method, this method 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.
 public static float rawCopySign(float magnitude,
    float sign) 
    Returns the first floating-point argument with the sign of the second floating-point argument. Note that unlike the copySign method, this method 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.
 public static double scalb(double d,
    int scale_factor) 
    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 section 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 {@code double}'s minimum exponent and maximum exponent, the answer is calculated exactly. If the exponent of the 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 {@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 {@code d}.

    Special cases:

    • If the first argument is NaN, NaN is returned.
    • If the first argument is infinite, then an infinity of the same sign is returned.
    • If the first argument is zero, then a zero of the same sign is returned.
 public static float scalb(float f,
    int scale_factor) 
    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 section 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 {@code float}'s minimum exponent and maximum exponent, the answer is calculated exactly. If the exponent of the result 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 {@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 {@code f}.

    Special cases:

    • If the first argument is NaN, NaN is returned.
    • If the first argument is infinite, then an infinity of the same sign is returned.
    • If the first argument is zero, then a zero of the same sign is returned.
 public static double signum(double d) 
    Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

    Special Cases:

    • If the argument is NaN, then the result is NaN.
    • If the argument is positive zero or negative zero, then the result is the same as the argument.
 public static float signum(float f) 
    Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.

    Special Cases:

    • If the argument is NaN, then the result is NaN.
    • If the argument is positive zero or negative zero, then the result is the same as the argument.
 public static double ulp(double d) 
    Returns the size of an ulp of the argument. An ulp of a {@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).

    Special Cases:

    • If the argument is NaN, then the result is NaN.
    • If the argument is positive or negative infinity, then the result is positive infinity.
    • If the argument is positive or negative zero, then the result is {@code Double.MIN_VALUE}.
    • If the argument is ±{@code Double.MAX_VALUE}, then the result is equal to 2971.
 public static float ulp(float f) 
    Returns the size of an ulp of the argument. An ulp of a {@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).

    Special Cases:

    • If the argument is NaN, then the result is NaN.
    • If the argument is positive or negative infinity, then the result is positive infinity.
    • If the argument is positive or negative zero, then the result is {@code Float.MIN_VALUE}.
    • If the argument is ±{@code Float.MAX_VALUE}, then the result is equal to 2104.