test/java/lang/Math/Tests.java

Print this page

        

*** 28,39 **** * success. The order of arguments to the test methods is generally * the test name, followed by the test arguments, the computed result, * and finally the expected result. */ ! import sun.misc.FloatConsts; ! import sun.misc.DoubleConsts; public class Tests { private Tests(){}; // do not instantiate public static String toHexString(float f) { --- 28,39 ---- * success. The order of arguments to the test methods is generally * the test name, followed by the test arguments, the computed result, * and finally the expected result. */ ! import jdk.testlibrary.DoubleUtils; ! import jdk.testlibrary.FloatUtils; public class Tests { private Tests(){}; // do not instantiate public static String toHexString(float f) {
*** 79,95 **** */ public static int ilogb(double d) { int exponent = Math.getExponent(d); switch (exponent) { ! case DoubleConsts.MAX_EXPONENT+1: // NaN or infinity if( Double.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); --- 79,95 ---- */ public static int ilogb(double d) { int exponent = Math.getExponent(d); switch (exponent) { ! case Double.MAX_EXPONENT+1: // NaN or infinity if( Double.isNaN(d) ) return (1<<30); // 2^30 else // infinite value return (1<<28); // 2^28 ! case Double.MIN_EXPONENT-1: // zero or subnormal if(d == 0.0) { return -(1<<28); // -(2^28) } else { long transducer = Double.doubleToRawLongBits(d);
*** 101,132 **** * (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; } } /** --- 101,132 ---- * (there must be at least one "1" bit in the * significand since zero has been screened out. */ // isolate significand bits ! transducer &= DoubleUtils.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 << (DoubleUtils.SIGNIFICAND_WIDTH - 1))) { transducer *= 2; exponent--; } exponent++; assert( exponent >= ! Double.MIN_EXPONENT - (DoubleUtils.SIGNIFICAND_WIDTH-1) && ! exponent < Double.MIN_EXPONENT); return exponent; } default: ! assert( exponent >= Double.MIN_EXPONENT && ! exponent <= Double.MAX_EXPONENT); return exponent; } } /**
*** 148,164 **** */ public static int ilogb(float f) { int exponent = Math.getExponent(f); switch (exponent) { ! case FloatConsts.MAX_EXPONENT+1: // NaN or infinity if( Float.isNaN(f) ) return (1<<30); // 2^30 else // infinite value return (1<<28); // 2^28 ! case FloatConsts.MIN_EXPONENT-1: // zero or subnormal if(f == 0.0f) { return -(1<<28); // -(2^28) } else { int transducer = Float.floatToRawIntBits(f); --- 148,164 ---- */ public static int ilogb(float f) { int exponent = Math.getExponent(f); switch (exponent) { ! case Float.MAX_EXPONENT+1: // NaN or infinity if( Float.isNaN(f) ) return (1<<30); // 2^30 else // infinite value return (1<<28); // 2^28 ! case Float.MIN_EXPONENT-1: // zero or subnormal if(f == 0.0f) { return -(1<<28); // -(2^28) } else { int transducer = Float.floatToRawIntBits(f);
*** 170,201 **** * (there must be at least one "1" bit in the * significand since zero has been screened out. */ // isolate significand bits ! transducer &= FloatConsts.SIGNIF_BIT_MASK; assert(transducer != 0); // 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 < ! (1 << (FloatConsts.SIGNIFICAND_WIDTH - 1))) { transducer *= 2; exponent--; } exponent++; assert( exponent >= ! FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1) && ! exponent < FloatConsts.MIN_EXPONENT); return exponent; } default: ! assert( exponent >= FloatConsts.MIN_EXPONENT && ! exponent <= FloatConsts.MAX_EXPONENT); return exponent; } } /** --- 170,201 ---- * (there must be at least one "1" bit in the * significand since zero has been screened out. */ // isolate significand bits ! transducer &= FloatUtils.SIGNIF_BIT_MASK; assert(transducer != 0); // 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 < ! (1 << (FloatUtils.SIGNIFICAND_WIDTH - 1))) { transducer *= 2; exponent--; } exponent++; assert( exponent >= ! Float.MIN_EXPONENT - (FloatUtils.SIGNIFICAND_WIDTH-1) && ! exponent < Float.MIN_EXPONENT); return exponent; } default: ! assert( exponent >= Float.MIN_EXPONENT && ! exponent <= Float.MAX_EXPONENT); return exponent; } } /**