if (Double.isInfinite (num) || Double.isNaN (num)) throw new NumberFormatException ("invalid argument: " + num);     final int mantissaBits = 52; final int exponentBits = 11; final long mantMask = (1L << mantissaBits) - 1; final long expMask = (1L << exponentBits) - 1;  long bits = Double.doubleToLongBits (num); long mantissa = bits & mantMask; long exponent = (bits >>> mantissaBits) & expMask; boolean denormal = exponent == 0;  exponent -= denormal ? 1022 : 1023;   exponent -= mantissaBits;  if (! denormal) mantissa |= (1L << mantissaBits);   while (exponent < 0 && (mantissa & 1) == 0) { ++exponent; mantissa >>= 1; }  intVal = BigInteger.valueOf (bits < 0 ? - mantissa : mantissa); if (exponent < 0) {    scale = (int) (- exponent); BigInteger mult = BigInteger.valueOf (5).pow (scale); intVal = intVal.multiply (mult); } else { intVal = intVal.shiftLeft ((int) exponent); scale = 0; }
this (num, 0);
  public BigDecimal (double num) throws NumberFormatException   {    if (Double.isInfinite (num) || Double.isNaN (num))      throw new NumberFormatException ("invalid argument: " + num);    // Note we can't convert NUM to a String and then use the    // String-based constructor.  The BigDecimal documentation makes    // it clear that the two constructors work differently.    final int mantissaBits = 52;    final int exponentBits = 11;    final long mantMask = (1L << mantissaBits) - 1;    final long expMask = (1L << exponentBits) - 1;    long bits = Double.doubleToLongBits (num);    long mantissa = bits & mantMask;    long exponent = (bits >>> mantissaBits) & expMask;    boolean denormal = exponent == 0;    // Correct the exponent for the bias.    exponent -= denormal ? 1022 : 1023;    // Now correct the exponent to account for the bits to the right    // of the decimal.    exponent -= mantissaBits;    // Ordinary numbers have an implied leading `1' bit.    if (! denormal)      mantissa |= (1L << mantissaBits);    // Shave off factors of 10.    while (exponent < 0 && (mantissa & 1) == 0)      {	++exponent;	mantissa >>= 1;      }    intVal = BigInteger.valueOf (bits < 0 ? - mantissa : mantissa);    if (exponent < 0)      {	// We have MANTISSA * 2 ^ (EXPONENT).	// Since (1/2)^N == 5^N * 10^-N we can easily convert this	// into a power of 10.	scale = (int) (- exponent);	BigInteger mult = BigInteger.valueOf (5).pow (scale);	intVal = intVal.multiply (mult);      }    else      {	intVal = intVal.shiftLeft ((int) exponent);	scale = 0;      }  }