3406 tmp[v.length] = '.'; 3407 start++; 3408 } 3409 3410 // Add zeros. 3411 for (int j = start; j < tmp.length; j++) 3412 tmp[j] = '0'; 3413 3414 return tmp; 3415 } 3416 3417 // Method assumes that d > 0. 3418 private String hexDouble(double d, int prec) { 3419 // Let Double.toHexString handle simple cases 3420 if(!FpUtils.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13) 3421 // remove "0x" 3422 return Double.toHexString(d).substring(2); 3423 else { 3424 assert(prec >= 1 && prec <= 12); 3425 3426 int exponent = FpUtils.getExponent(d); 3427 boolean subnormal 3428 = (exponent == DoubleConsts.MIN_EXPONENT - 1); 3429 3430 // If this is subnormal input so normalize (could be faster to 3431 // do as integer operation). 3432 if (subnormal) { 3433 scaleUp = FpUtils.scalb(1.0, 54); 3434 d *= scaleUp; 3435 // Calculate the exponent. This is not just exponent + 54 3436 // since the former is not the normalized exponent. 3437 exponent = FpUtils.getExponent(d); 3438 assert exponent >= DoubleConsts.MIN_EXPONENT && 3439 exponent <= DoubleConsts.MAX_EXPONENT: exponent; 3440 } 3441 3442 int precision = 1 + prec*4; 3443 int shiftDistance 3444 = DoubleConsts.SIGNIFICAND_WIDTH - precision; 3445 assert(shiftDistance >= 1 && shiftDistance < DoubleConsts.SIGNIFICAND_WIDTH); 3446 3447 long doppel = Double.doubleToLongBits(d); 3448 // Deterime the number of bits to keep. 3449 long newSignif 3450 = (doppel & (DoubleConsts.EXP_BIT_MASK 3451 | DoubleConsts.SIGNIF_BIT_MASK)) 3452 >> shiftDistance; 3453 // Bits to round away. 3454 long roundingBits = doppel & ~(~0L << shiftDistance); 3455 3456 // To decide how to round, look at the low-order bit of the 3457 // working significand, the highest order discarded bit (the | 3406 tmp[v.length] = '.'; 3407 start++; 3408 } 3409 3410 // Add zeros. 3411 for (int j = start; j < tmp.length; j++) 3412 tmp[j] = '0'; 3413 3414 return tmp; 3415 } 3416 3417 // Method assumes that d > 0. 3418 private String hexDouble(double d, int prec) { 3419 // Let Double.toHexString handle simple cases 3420 if(!FpUtils.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13) 3421 // remove "0x" 3422 return Double.toHexString(d).substring(2); 3423 else { 3424 assert(prec >= 1 && prec <= 12); 3425 3426 int exponent = Math.getExponent(d); 3427 boolean subnormal 3428 = (exponent == DoubleConsts.MIN_EXPONENT - 1); 3429 3430 // If this is subnormal input so normalize (could be faster to 3431 // do as integer operation). 3432 if (subnormal) { 3433 scaleUp = Math.scalb(1.0, 54); 3434 d *= scaleUp; 3435 // Calculate the exponent. This is not just exponent + 54 3436 // since the former is not the normalized exponent. 3437 exponent = Math.getExponent(d); 3438 assert exponent >= DoubleConsts.MIN_EXPONENT && 3439 exponent <= DoubleConsts.MAX_EXPONENT: exponent; 3440 } 3441 3442 int precision = 1 + prec*4; 3443 int shiftDistance 3444 = DoubleConsts.SIGNIFICAND_WIDTH - precision; 3445 assert(shiftDistance >= 1 && shiftDistance < DoubleConsts.SIGNIFICAND_WIDTH); 3446 3447 long doppel = Double.doubleToLongBits(d); 3448 // Deterime the number of bits to keep. 3449 long newSignif 3450 = (doppel & (DoubleConsts.EXP_BIT_MASK 3451 | DoubleConsts.SIGNIF_BIT_MASK)) 3452 >> shiftDistance; 3453 // Bits to round away. 3454 long roundingBits = doppel & ~(~0L << shiftDistance); 3455 3456 // To decide how to round, look at the low-order bit of the 3457 // working significand, the highest order discarded bit (the |