/** * Rounds at the digit with value 10<sup>decimalExponent</sup> */ public NormalisedDecimal roundUnits() { long wholePart = _wholePart; if (_fractionalPart >= FRAC_HALF) { wholePart++; } int de = _relativeDecimalExponent; if (wholePart < MAX_REP_WHOLE_PART) { return new NormalisedDecimal(wholePart, 0, de); } return new NormalisedDecimal(wholePart/10, 0, de+1); }
NormalisedDecimal ndA = edA.normaliseBaseTen().roundUnits(); NormalisedDecimal ndB = edB.normaliseBaseTen().roundUnits(); cmp = ndA.compareNormalised(ndB); if (aIsNegative) { return -cmp;
/** * Convert to an equivalent {@link ExpandedDouble} representation (binary frac and exponent). * The resulting transformed object is easily converted to a 64 bit IEEE double: * <ul> * <li>bits 2-53 of the {@link #getSignificand()} become the 52 bit 'fraction'.</li> * <li>{@link #getBinaryExponent()} is biased by 1023 to give the 'exponent'.</li> * </ul> * The sign bit must be obtained from somewhere else. * @return a new {@link NormalisedDecimal} normalised to base 2 representation. */ public ExpandedDouble normaliseBaseTwo() { MutableFPNumber cc = new MutableFPNumber(composeFrac(), 39); cc.multiplyByPowerOfTen(_relativeDecimalExponent); cc.normalise64bit(); return cc.createExpandedDouble(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(" ["); String ws = String.valueOf(_wholePart); sb.append(ws.charAt(0)); sb.append('.'); sb.append(ws.substring(1)); sb.append(' '); sb.append(getFractionalDigits()); sb.append("E"); sb.append(getDecimalExponent()); sb.append("]"); return sb.toString(); } }
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
private String getFractionalDigits() { if (_fractionalPart == 0) { return "0"; } return getFractionalPart().toString().substring(2); }
/** * Convert to an equivalent {@link NormalisedDecimal} representation having 15 decimal digits of precision in the * non-fractional bits of the significand. */ public NormalisedDecimal normaliseBaseTen() { return NormalisedDecimal.create(_significand, _binaryExponent); }
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(" ["); String ws = String.valueOf(_wholePart); sb.append(ws.charAt(0)); sb.append('.'); sb.append(ws.substring(1)); sb.append(' '); sb.append(getFractionalDigits()); sb.append("E"); sb.append(getDecimalExponent()); sb.append("]"); return sb.toString(); } }
private String getFractionalDigits() { if (_fractionalPart == 0) { return "0"; } return getFractionalPart().toString().substring(2); }
/** * Convert to an equivalent {@link NormalisedDecimal} representation having 15 decimal digits of precision in the * non-fractional bits of the significand. */ public NormalisedDecimal normaliseBaseTen() { return NormalisedDecimal.create(_significand, _binaryExponent); }
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(" ["); String ws = String.valueOf(_wholePart); sb.append(ws.charAt(0)); sb.append('.'); sb.append(ws.substring(1)); sb.append(' '); sb.append(getFractionalDigits()); sb.append("E"); sb.append(getDecimalExponent()); sb.append("]"); return sb.toString(); } }
NormalisedDecimal ndA = edA.normaliseBaseTen().roundUnits(); NormalisedDecimal ndB = edB.normaliseBaseTen().roundUnits(); cmp = ndA.compareNormalised(ndB); if (aIsNegative) { return -cmp;
public NormalisedDecimal createNormalisedDecimal(int pow10) { // missingUnderBits is (0..3) int missingUnderBits = _binaryExponent-39; int fracPart = (_significand.intValue() << missingUnderBits) & 0xFFFF80; long wholePart = _significand.shiftRight(C_64-_binaryExponent-1).longValue(); return new NormalisedDecimal(wholePart, fracPart, pow10); } public void multiplyByPowerOfTen(int pow10) {
private String getFractionalDigits() { if (_fractionalPart == 0) { return "0"; } return getFractionalPart().toString().substring(2); }
/** * Convert to an equivalent {@link NormalisedDecimal} representation having 15 decimal digits of precision in the * non-fractional bits of the significand. */ public NormalisedDecimal normaliseBaseTen() { return NormalisedDecimal.create(_significand, _binaryExponent); }
/** * Convert to an equivalent {@link ExpandedDouble} representation (binary frac and exponent). * The resulting transformed object is easily converted to a 64 bit IEEE double: * <ul> * <li>bits 2-53 of the {@link #getSignificand()} become the 52 bit 'fraction'.</li> * <li>{@link #getBinaryExponent()} is biased by 1023 to give the 'exponent'.</li> * </ul> * The sign bit must be obtained from somewhere else. * @return a new {@link NormalisedDecimal} normalised to base 2 representation. */ public ExpandedDouble normaliseBaseTwo() { MutableFPNumber cc = new MutableFPNumber(composeFrac(), 39); cc.multiplyByPowerOfTen(_relativeDecimalExponent); cc.normalise64bit(); return cc.createExpandedDouble(); }
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(" ["); String ws = String.valueOf(_wholePart); sb.append(ws.charAt(0)); sb.append('.'); sb.append(ws.substring(1)); sb.append(' '); sb.append(getFractionalDigits()); sb.append("E"); sb.append(getDecimalExponent()); sb.append("]"); return sb.toString(); } }