src/share/classes/sun/misc/FpUtils.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 27,39 **** import sun.misc.FloatConsts; import sun.misc.DoubleConsts; /** ! * The class <code>FpUtils</code> contains static utility methods for ! * manipulating and inspecting <code>float</code> and ! * <code>double</code> floating-point numbers. These methods include * functionality recommended or required by the IEEE 754 * floating-point standard. * * @author Joseph D. Darcy */ --- 27,39 ---- import sun.misc.FloatConsts; import sun.misc.DoubleConsts; /** ! * 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. * * @author Joseph D. Darcy */
*** 134,144 **** // The following helper methods are used in the implementation of // the public recommended functions; they generally omit certain // tests for exception cases. /** ! * Returns unbiased exponent of a <code>double</code>. */ public static int getExponent(double d){ /* * Bitwise convert d to long, mask out exponent bits, shift * to the right and then subtract out double's bias adjust to --- 134,144 ---- // The following helper methods are used in the implementation of // the public recommended functions; they generally omit certain // tests for exception cases. /** ! * Returns unbiased exponent of a {@code double}. */ public static int getExponent(double d){ /* * Bitwise convert d to long, mask out exponent bits, shift * to the right and then subtract out double's bias adjust to
*** 147,157 **** return (int)(((Double.doubleToRawLongBits(d) & DoubleConsts.EXP_BIT_MASK) >> (DoubleConsts.SIGNIFICAND_WIDTH - 1)) - DoubleConsts.EXP_BIAS); } /** ! * Returns unbiased exponent of a <code>float</code>. */ public static int getExponent(float f){ /* * Bitwise convert f to integer, mask out exponent bits, shift * to the right and then subtract out float's bias adjust to --- 147,157 ---- return (int)(((Double.doubleToRawLongBits(d) & DoubleConsts.EXP_BIT_MASK) >> (DoubleConsts.SIGNIFICAND_WIDTH - 1)) - DoubleConsts.EXP_BIAS); } /** ! * Returns unbiased exponent of a {@code float}. */ public static int getExponent(float f){ /* * Bitwise convert f to integer, mask out exponent bits, shift * to the right and then subtract out float's bias adjust to
*** 183,201 **** /** * 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 <code>sign</code> 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 <code>magnitude</code> ! * and the sign of <code>sign</code>. * @author Joseph D. Darcy */ public static double rawCopySign(double magnitude, double sign) { return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) & (DoubleConsts.SIGN_BIT_MASK)) | --- 183,201 ---- /** * 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 {@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 {@code magnitude} ! * and the sign of {@code sign}. * @author Joseph D. Darcy */ public static double rawCopySign(double magnitude, double sign) { return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) & (DoubleConsts.SIGN_BIT_MASK)) |
*** 206,224 **** /** * 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 <code>sign</code> 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 <code>magnitude</code> ! * and the sign of <code>sign</code>. * @author Joseph D. Darcy */ public static float rawCopySign(float magnitude, float sign) { return Float.intBitsToFloat((Float.floatToRawIntBits(sign) & (FloatConsts.SIGN_BIT_MASK)) | --- 206,224 ---- /** * 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 {@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 {@code magnitude} ! * and the sign of {@code sign}. * @author Joseph D. Darcy */ public static float rawCopySign(float magnitude, float sign) { return Float.intBitsToFloat((Float.floatToRawIntBits(sign) & (FloatConsts.SIGN_BIT_MASK)) |
*** 228,360 **** } /* ***************************************************************** */ /** ! * Returns <code>true</code> if the argument is a finite ! * floating-point value; returns <code>false</code> otherwise (for * NaN and infinity arguments). * ! * @param d the <code>double</code> value to be tested ! * @return <code>true</code> if the argument is a finite ! * floating-point value, <code>false</code> otherwise. */ public static boolean isFinite(double d) { return Math.abs(d) <= DoubleConsts.MAX_VALUE; } /** ! * Returns <code>true</code> if the argument is a finite ! * floating-point value; returns <code>false</code> otherwise (for * NaN and infinity arguments). * ! * @param f the <code>float</code> value to be tested ! * @return <code>true</code> if the argument is a finite ! * floating-point value, <code>false</code> otherwise. */ public static boolean isFinite(float f) { return Math.abs(f) <= FloatConsts.MAX_VALUE; } /** ! * Returns <code>true</code> if the specified number is infinitely ! * large in magnitude, <code>false</code> otherwise. * * <p>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 <code>true</code> if the value of the argument is positive ! * infinity or negative infinity; <code>false</code> otherwise. */ public static boolean isInfinite(double d) { return Double.isInfinite(d); } /** ! * Returns <code>true</code> if the specified number is infinitely ! * large in magnitude, <code>false</code> otherwise. * * <p>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 <code>true</code> if the argument is positive infinity or ! * negative infinity; <code>false</code> otherwise. */ public static boolean isInfinite(float f) { return Float.isInfinite(f); } /** ! * Returns <code>true</code> if the specified number is a ! * Not-a-Number (NaN) value, <code>false</code> otherwise. * * <p>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 <code>true</code> if the value of the argument is NaN; ! * <code>false</code> otherwise. */ public static boolean isNaN(double d) { return Double.isNaN(d); } /** ! * Returns <code>true</code> if the specified number is a ! * Not-a-Number (NaN) value, <code>false</code> otherwise. * * <p>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 <code>true</code> if the argument is NaN; ! * <code>false</code> otherwise. */ public static boolean isNaN(float f) { return Float.isNaN(f); } /** ! * Returns <code>true</code> 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</code>. * * @param arg1 the first argument * @param arg2 the second argument ! * @return <code>true</code> if at least one argument is a NaN, ! * <code>false</code> otherwise. */ public static boolean isUnordered(double arg1, double arg2) { return isNaN(arg1) || isNaN(arg2); } /** ! * Returns <code>true</code> 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</code>. * * @param arg1 the first argument * @param arg2 the second argument ! * @return <code>true</code> if at least one argument is a NaN, ! * <code>false</code> otherwise. */ public static boolean isUnordered(float arg1, float arg2) { return isNaN(arg1) || isNaN(arg2); } /** ! * Returns unbiased exponent of a <code>double</code>; for * subnormal values, the number is treated as if it were * normalized. That is for all finite, non-zero, positive numbers * <i>x</i>, <code>scalb(<i>x</i>, -ilogb(<i>x</i>))</code> is * always in the range [1, 2). * <p> --- 228,360 ---- } /* ***************************************************************** */ /** ! * 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. */ public static boolean isFinite(double d) { return Math.abs(d) <= DoubleConsts.MAX_VALUE; } /** ! * 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. */ public static boolean isFinite(float f) { return Math.abs(f) <= FloatConsts.MAX_VALUE; } /** ! * Returns {@code true} if the specified number is infinitely ! * large in magnitude, {@code false} otherwise. * * <p>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 {@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 {@code true} if the specified number is infinitely ! * large in magnitude, {@code false} otherwise. * * <p>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 {@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 {@code true} if the specified number is a ! * Not-a-Number (NaN) value, {@code false} otherwise. * * <p>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 {@code true} if the value of the argument is NaN; ! * {@code false} otherwise. */ public static boolean isNaN(double d) { return Double.isNaN(d); } /** ! * Returns {@code true} if the specified number is a ! * Not-a-Number (NaN) value, {@code false} otherwise. * * <p>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 {@code true} if the argument is NaN; ! * {@code false} otherwise. */ public static boolean isNaN(float f) { return Float.isNaN(f); } /** ! * 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}. * * @param arg1 the first argument * @param arg2 the second argument ! * @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 {@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}. * * @param arg1 the first argument * @param arg2 the second argument ! * @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 {@code double}; for * subnormal values, the number is treated as if it were * normalized. That is for all finite, non-zero, positive numbers * <i>x</i>, <code>scalb(<i>x</i>, -ilogb(<i>x</i>))</code> is * always in the range [1, 2). * <p>
*** 376,386 **** case DoubleConsts.MAX_EXPONENT+1: // NaN or infinity if( isNaN(d) ) 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) { return -(1<<28); // -(2^28) } --- 376,385 ----
*** 412,433 **** assert( exponent >= DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1) && 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 <code>float</code>; for * subnormal values, the number is treated as if it were * normalized. That is for all finite, non-zero, positive numbers * <i>x</i>, <code>scalb(<i>x</i>, -ilogb(<i>x</i>))</code> is * always in the range [1, 2). * <p> --- 411,430 ---- assert( exponent >= DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1) && exponent < DoubleConsts.MIN_EXPONENT); return exponent; } default: assert( exponent >= DoubleConsts.MIN_EXPONENT && exponent <= DoubleConsts.MAX_EXPONENT); return exponent; } } /** ! * 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 * <i>x</i>, <code>scalb(<i>x</i>, -ilogb(<i>x</i>))</code> is * always in the range [1, 2). * <p>
*** 449,459 **** case FloatConsts.MAX_EXPONENT+1: // NaN or infinity if( isNaN(f) ) 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) { return -(1<<28); // -(2^28) } --- 446,455 ----
*** 485,501 **** assert( exponent >= FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1) && exponent < FloatConsts.MIN_EXPONENT); return exponent; } - // break; default: assert( exponent >= FloatConsts.MIN_EXPONENT && exponent <= FloatConsts.MAX_EXPONENT); return exponent; - // break; } } /* --- 481,495 ----
*** 532,557 **** * version of scalb to avoid having to recompute the needed * scaling factors for each floating-point value. */ /** ! * Return <code>d</code> &times; ! * 2<sup><code>scale_factor</code></sup> rounded as if performed * by a single correctly rounded floating-point multiply to a * member of the double value set. See <a * href="http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html#9208">&sect;4.2.3</a> * of the <a href="http://java.sun.com/docs/books/jls/html/">Java * Language Specification</a> for a discussion of floating-point * value sets. If the exponent of the result is between the ! * <code>double</code>'s minimum exponent and maximum exponent, * the answer is calculated exactly. If the exponent of the ! * result would be larger than <code>doubles</code>'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)</code> is subnormal, <code>scalb(scalb(x, n), -n)</code> may * not equal <i>x</i>. When the result is non-NaN, the result has ! * the same sign as <code>d</code>. * *<p> * Special cases: * <ul> * <li> If the first argument is NaN, NaN is returned. --- 526,551 ---- * version of scalb to avoid having to recompute the needed * scaling factors for each floating-point value. */ /** ! * Return {@code d} &times; ! * 2<sup>{@code scale_factor}</sup> rounded as if performed * by a single correctly rounded floating-point multiply to a * member of the double value set. See <a * href="http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html#9208">&sect;4.2.3</a> * of the <a href="http://java.sun.com/docs/books/jls/html/">Java * Language Specification</a> 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 <i>x</i>. When the result is non-NaN, the result has ! * the same sign as {@code d}. * *<p> * Special cases: * <ul> * <li> If the first argument is NaN, NaN is returned.
*** 560,571 **** * <li> If the first argument is zero, then a zero of the same * sign is returned. * </ul> * * @param d number to be scaled by a power of two. ! * @param scale_factor power of 2 used to scale <code>d</code> ! * @return <code>d * </code>2<sup><code>scale_factor</code></sup> * @author Joseph D. Darcy */ public static double scalb(double d, int scale_factor) { /* * This method does not need to be declared strictfp to --- 554,565 ---- * <li> If the first argument is zero, then a zero of the same * sign is returned. * </ul> * * @param d number to be scaled by a power of two. ! * @param scale_factor power of 2 used to scale {@code d} ! * @return {@code d * }2<sup>{@code scale_factor}</sup> * @author Joseph D. Darcy */ public static double scalb(double d, int scale_factor) { /* * This method does not need to be declared strictfp to
*** 642,667 **** } return d; } /** ! * Return <code>f </code>&times; ! * 2<sup><code>scale_factor</code></sup> rounded as if performed * by a single correctly rounded floating-point multiply to a * member of the float value set. See <a * href="http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html#9208">&sect;4.2.3</a> * of the <a href="http://java.sun.com/docs/books/jls/html/">Java * Language Specification</a> for a discussion of floating-point * value set. If the exponent of the result is between the ! * <code>float</code>'s minimum exponent and maximum exponent, the * answer is calculated exactly. If the exponent of the result ! * would be larger than <code>float</code>'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)</code> ! * is subnormal, <code>scalb(scalb(x, n), -n)</code> may not equal * <i>x</i>. When the result is non-NaN, the result has the same ! * sign as <code>f</code>. * *<p> * Special cases: * <ul> * <li> If the first argument is NaN, NaN is returned. --- 636,661 ---- } return d; } /** ! * Return {@code f} &times; ! * 2<sup>{@code scale_factor}</sup> rounded as if performed * by a single correctly rounded floating-point multiply to a * member of the float value set. See <a * href="http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html#9208">&sect;4.2.3</a> * of the <a href="http://java.sun.com/docs/books/jls/html/">Java * Language Specification</a> for a discussion of floating-point * value set. 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 * <i>x</i>. When the result is non-NaN, the result has the same ! * sign as {@code f}. * *<p> * Special cases: * <ul> * <li> If the first argument is NaN, NaN is returned.
*** 670,681 **** * <li> If the first argument is zero, then a zero of the same * sign is returned. * </ul> * * @param f number to be scaled by a power of two. ! * @param scale_factor power of 2 used to scale <code>f</code> ! * @return <code>f * </code>2<sup><code>scale_factor</code></sup> * @author Joseph D. Darcy */ public static float scalb(float f, int scale_factor) { // magnitude of a power of two so large that scaling a finite // nonzero value by it would be guaranteed to over or --- 664,675 ---- * <li> If the first argument is zero, then a zero of the same * sign is returned. * </ul> * * @param f number to be scaled by a power of two. ! * @param scale_factor power of 2 used to scale {@code f} ! * @return {@code f * }2<sup>{@code scale_factor}</sup> * @author Joseph D. Darcy */ public static float scalb(float f, int scale_factor) { // magnitude of a power of two so large that scaling a finite // nonzero value by it would be guaranteed to over or
*** 707,744 **** * <p> * Special cases: * <ul> * <li> If either argument is a NaN, then NaN is returned. * ! * <li> If both arguments are signed zeros, <code>direction</code> * is returned unchanged (as implied by the requirement of * returning the second argument if the arguments compare as * equal). * ! * <li> If <code>start</code> is ! * &plusmn;<code>Double.MIN_VALUE</code> and <code>direction</code> * has a value such that the result should have a smaller ! * magnitude, then a zero with the same sign as <code>start</code> * is returned. * ! * <li> If <code>start</code> is infinite and ! * <code>direction</code> has a value such that the result should ! * have a smaller magnitude, <code>Double.MAX_VALUE</code> with the ! * same sign as <code>start</code> is returned. * ! * <li> If <code>start</code> is equal to &plusmn; ! * <code>Double.MAX_VALUE</code> and <code>direction</code> has a * value such that the result should have a larger magnitude, an ! * infinity with same sign as <code>start</code> is returned. * </ul> * * @param start starting floating-point value * @param direction value indicating which of ! * <code>start</code>'s neighbors or <code>start</code> should * be returned ! * @return The floating-point number adjacent to <code>start</code> in the ! * direction of <code>direction</code>. * @author Joseph D. Darcy */ public static double nextAfter(double start, double direction) { /* * The cases: --- 701,738 ---- * <p> * Special cases: * <ul> * <li> If either argument is a NaN, then NaN is returned. * ! * <li> 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). * ! * <li> If {@code start} is ! * &plusmn;{@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. * ! * <li> 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. * ! * <li> If {@code start} is equal to &plusmn; ! * {@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. * </ul> * * @param start starting floating-point value * @param direction value indicating which of ! * {@code start}'s neighbors or {@code start} should * be returned ! * @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) { /* * The cases:
*** 807,844 **** * <p> * Special cases: * <ul> * <li> If either argument is a NaN, then NaN is returned. * ! * <li> If both arguments are signed zeros, a <code>float</code> ! * zero with the same sign as <code>direction</code> is returned * (as implied by the requirement of returning the second argument * if the arguments compare as equal). * ! * <li> If <code>start</code> is ! * &plusmn;<code>Float.MIN_VALUE</code> and <code>direction</code> * has a value such that the result should have a smaller ! * magnitude, then a zero with the same sign as <code>start</code> * is returned. * ! * <li> If <code>start</code> is infinite and ! * <code>direction</code> has a value such that the result should ! * have a smaller magnitude, <code>Float.MAX_VALUE</code> with the ! * same sign as <code>start</code> is returned. * ! * <li> If <code>start</code> is equal to &plusmn; ! * <code>Float.MAX_VALUE</code> and <code>direction</code> has a * value such that the result should have a larger magnitude, an ! * infinity with same sign as <code>start</code> is returned. * </ul> * * @param start starting floating-point value * @param direction value indicating which of ! * <code>start</code>'s neighbors or <code>start</code> should * be returned ! * @return The floating-point number adjacent to <code>start</code> in the ! * direction of <code>direction</code>. * @author Joseph D. Darcy */ public static float nextAfter(float start, double direction) { /* * The cases: --- 801,838 ---- * <p> * Special cases: * <ul> * <li> If either argument is a NaN, then NaN is returned. * ! * <li> 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). * ! * <li> If {@code start} is ! * &plusmn;{@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. * ! * <li> 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. * ! * <li> If {@code start} is equal to &plusmn; ! * {@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. * </ul> * * @param start starting floating-point value * @param direction value indicating which of ! * {@code start}'s neighbors or {@code start} should * be returned ! * @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) { /* * The cases:
*** 898,923 **** return Float.intBitsToFloat(transducer); } } /** ! * Returns the floating-point value adjacent to <code>d</code> in * the direction of positive infinity. This method is ! * semantically equivalent to <code>nextAfter(d, ! * Double.POSITIVE_INFINITY)</code>; however, a <code>nextUp</code> * implementation may run faster than its equivalent ! * <code>nextAfter</code> call. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is positive infinity, the result is * positive infinity. * * <li> If the argument is zero, the result is ! * <code>Double.MIN_VALUE</code> * * </ul> * * @param d starting floating-point value * @return The adjacent floating-point value closer to positive --- 892,917 ---- return Float.intBitsToFloat(transducer); } } /** ! * 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. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is positive infinity, the result is * positive 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 positive
*** 933,958 **** ((d >= 0.0d)?+1L:-1L)); } } /** ! * Returns the floating-point value adjacent to <code>f</code> in * the direction of positive infinity. This method is ! * semantically equivalent to <code>nextAfter(f, ! * Double.POSITIVE_INFINITY)</code>; however, a <code>nextUp</code> * implementation may run faster than its equivalent ! * <code>nextAfter</code> call. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is positive infinity, the result is * positive infinity. * * <li> If the argument is zero, the result is ! * <code>Float.MIN_VALUE</code> * * </ul> * * @param f starting floating-point value * @return The adjacent floating-point value closer to positive --- 927,952 ---- ((d >= 0.0d)?+1L:-1L)); } } /** ! * 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. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is positive infinity, the result is * positive 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 positive
*** 968,993 **** ((f >= 0.0f)?+1:-1)); } } /** ! * Returns the floating-point value adjacent to <code>d</code> in * the direction of negative infinity. This method is ! * semantically equivalent to <code>nextAfter(d, ! * Double.NEGATIVE_INFINITY)</code>; however, a ! * <code>nextDown</code> implementation may run faster than its ! * equivalent <code>nextAfter</code> 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</code> * * </ul> * * @param d starting floating-point value * @return The adjacent floating-point value closer to negative --- 962,987 ---- ((f >= 0.0f)?+1:-1)); } } /** ! * 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
*** 1005,1030 **** ((d > 0.0d)?-1L:+1L)); } } /** ! * Returns the floating-point value adjacent to <code>f</code> in * the direction of negative infinity. This method is ! * semantically equivalent to <code>nextAfter(f, ! * Float.NEGATIVE_INFINITY)</code>; however, a ! * <code>nextDown</code> implementation may run faster than its ! * equivalent <code>nextAfter</code> 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</code> * * </ul> * * @param f starting floating-point value * @return The adjacent floating-point value closer to negative --- 999,1024 ---- ((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
*** 1044,1098 **** } /** * Returns the first floating-point argument with the sign of the * second floating-point argument. For this method, a NaN ! * <code>sign</code> 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 <code>magnitude</code> ! * and the sign of <code>sign</code>. * @author Joseph D. Darcy * @since 1.5 */ public static double copySign(double magnitude, double sign) { return rawCopySign(magnitude, (isNaN(sign)?1.0d:sign)); } /** * Returns the first floating-point argument with the sign of the * second floating-point argument. For this method, a NaN ! * <code>sign</code> 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 <code>magnitude</code> ! * and the sign of <code>sign</code>. * @author Joseph D. Darcy */ public static float copySign(float magnitude, float sign) { return rawCopySign(magnitude, (isNaN(sign)?1.0f:sign)); } /** * Returns the size of an ulp of the argument. An ulp of a ! * <code>double</code> value is the positive distance between this ! * floating-point value and the <code>double</code> value next * larger in magnitude. Note that for non-NaN <i>x</i>, * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, then the result is NaN. * <li> If the argument is positive or negative infinity, then the * result is positive infinity. * <li> If the argument is positive or negative zero, then the result is ! * <code>Double.MIN_VALUE</code>. ! * <li> If the argument is &plusmn;<code>Double.MAX_VALUE</code>, then * the result is equal to 2<sup>971</sup>. * </ul> * * @param d the floating-point value whose ulp is to be returned * @return the size of an ulp of the argument --- 1038,1092 ---- } /** * 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. * * @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 {@code magnitude} ! * and the sign of {@code sign}. * @author Joseph D. Darcy * @since 1.5 */ public static double copySign(double magnitude, double sign) { return rawCopySign(magnitude, (isNaN(sign)?1.0d: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. * * @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 {@code magnitude} ! * and the sign of {@code sign}. * @author Joseph D. Darcy */ public static float copySign(float magnitude, float sign) { return rawCopySign(magnitude, (isNaN(sign)?1.0f:sign)); } /** * 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 <i>x</i>, * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, then the result is NaN. * <li> If the argument is positive or negative infinity, then the * result is positive infinity. * <li> If the argument is positive or negative zero, then the result is ! * {@code Double.MIN_VALUE}. ! * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then * the result is equal to 2<sup>971</sup>. * </ul> * * @param d the floating-point value whose ulp is to be returned * @return the size of an ulp of the argument
*** 1103,1117 **** int exp = getExponent(d); switch(exp) { case DoubleConsts.MAX_EXPONENT+1: // NaN or infinity return Math.abs(d); - // break; case DoubleConsts.MIN_EXPONENT-1: // zero or subnormal return Double.MIN_VALUE; - // break default: assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT; // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x)) --- 1097,1109 ----
*** 1124,1152 **** // representation of Double.MIN_VALUE appropriate // number of positions return Double.longBitsToDouble(1L << (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) )); } - // break } } /** * Returns the size of an ulp of the argument. An ulp of a ! * <code>float</code> value is the positive distance between this ! * floating-point value and the <code>float</code> value next * larger in magnitude. Note that for non-NaN <i>x</i>, * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, then the result is NaN. * <li> If the argument is positive or negative infinity, then the * result is positive infinity. * <li> If the argument is positive or negative zero, then the result is ! * <code>Float.MIN_VALUE</code>. ! * <li> If the argument is &plusmn;<code>Float.MAX_VALUE</code>, then * the result is equal to 2<sup>104</sup>. * </ul> * * @param f the floating-point value whose ulp is to be returned * @return the size of an ulp of the argument --- 1116,1143 ---- // representation of Double.MIN_VALUE appropriate // number of positions return Double.longBitsToDouble(1L << (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) )); } } } /** * 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 <i>x</i>, * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>. * * <p>Special Cases: * <ul> * <li> If the argument is NaN, then the result is NaN. * <li> If the argument is positive or negative infinity, then the * result is positive infinity. * <li> If the argument is positive or negative zero, then the result is ! * {@code Float.MIN_VALUE}. ! * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then * the result is equal to 2<sup>104</sup>. * </ul> * * @param f the floating-point value whose ulp is to be returned * @return the size of an ulp of the argument
*** 1157,1171 **** int exp = getExponent(f); switch(exp) { case FloatConsts.MAX_EXPONENT+1: // NaN or infinity return Math.abs(f); - // break; case FloatConsts.MIN_EXPONENT-1: // zero or subnormal return FloatConsts.MIN_VALUE; - // break default: assert exp <= FloatConsts.MAX_EXPONENT && exp >= FloatConsts.MIN_EXPONENT; // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x)) --- 1148,1160 ----
*** 1178,1188 **** // representation of FloatConsts.MIN_VALUE appropriate // number of positions return Float.intBitsToFloat(1 << (exp - (FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1)) )); } - // break } } /** * Returns the signum function of the argument; zero if the argument --- 1167,1176 ----