Java Code Examples for sun.misc.DoubleConsts#MAX_EXPONENT

The following examples show how to use sun.misc.DoubleConsts#MAX_EXPONENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FpUtils.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 2
Source File: FpUtils.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 3
Source File: FpUtils.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 4
Source File: FpUtils.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    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)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 5
Source File: FpUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 6
Source File: FpUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 7
Source File: FpUtils.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    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)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 8
Source File: FpUtils.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 9
Source File: FpUtils.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 10
Source File: FpUtils.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 11
Source File: FpUtils.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 12
Source File: FpUtils.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 13
Source File: FpUtils.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 14
Source File: FpUtils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}
 
Example 15
Source File: FpUtils.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * 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>
 * Special cases:
 * <ul>
 * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
 * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
 * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
 * </ul>
 *
 * @param d floating-point number whose exponent is to be extracted
 * @return unbiased exponent of the argument.
 * @author Joseph D. Darcy
 */
public static int ilogb(double d) {
    int exponent = getExponent(d);

    switch (exponent) {
    case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
        if( isNaN(d) )
            return (1<<30);         // 2^30
        else // infinite value
            return (1<<28);         // 2^28

    case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
        if(d == 0.0) {
            return -(1<<28);        // -(2^28)
        }
        else {
            long transducer = Double.doubleToRawLongBits(d);

            /*
             * To avoid causing slow arithmetic on subnormals,
             * the scaling to determine when d's significand
             * is normalized is done in integer arithmetic.
             * (there must be at least one "1" bit in the
             * significand since zero has been screened out.
             */

            // isolate significand bits
            transducer &= DoubleConsts.SIGNIF_BIT_MASK;
            assert(transducer != 0L);

            // This loop is simple and functional. We might be
            // able to do something more clever that was faster;
            // e.g. number of leading zero detection on
            // (transducer << (# exponent and sign bits).
            while (transducer <
                   (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
                transducer *= 2;
                exponent--;
            }
            exponent++;
            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;
    }
}