/** * Returns a BigDecimal whose numerical value is equal to * ({@code this} * 10<sup>n</sup>). The scale of * the result is {@code (this.scale() - n)}. * * @throws ArithmeticException if the scale would be * outside the range of a 32-bit integer. * * @since 1.5 */ public BigDecimal scaleByPowerOfTen(int n) { return new BigDecimal(intVal, intCompact, checkScale((long)scale - n), precision); }
/** * Returns a BigDecimal whose numerical value is equal to * ({@code this} * 10<sup>n</sup>). The scale of * the result is {@code (this.scale() - n)}. * * @throws ArithmeticException if the scale would be * outside the range of a 32-bit integer. * * @since 1.5 */ public BigDecimal scaleByPowerOfTen(int n) { return new BigDecimal(intVal, intCompact, checkScale((long)scale - n), precision); }
/** * Returns a {@code BigDecimal} which is equivalent to this one * with the decimal point moved {@code n} places to the right. * If {@code n} is non-negative, the call merely subtracts * {@code n} from the scale. If {@code n} is negative, the call * is equivalent to {@code movePointLeft(-n)}. The * {@code BigDecimal} returned by this call has value <tt>(this * × 10<sup>n</sup>)</tt> and scale {@code max(this.scale()-n, * 0)}. * * @param n number of places to move the decimal point to the right. * @return a {@code BigDecimal} which is equivalent to this one * with the decimal point moved {@code n} places to the right. * @throws ArithmeticException if scale overflows. */ public BigDecimal movePointRight(int n) { // Cannot use movePointLeft(-n) in case of n==Integer.MIN_VALUE int newScale = checkScale((long)scale - n); BigDecimal num = new BigDecimal(intVal, intCompact, newScale, 0); return num.scale < 0 ? num.setScale(0, ROUND_UNNECESSARY) : num; }
/** * Returns a {@code BigDecimal} which is equivalent to this one * with the decimal point moved {@code n} places to the left. If * {@code n} is non-negative, the call merely adds {@code n} to * the scale. If {@code n} is negative, the call is equivalent * to {@code movePointRight(-n)}. The {@code BigDecimal} * returned by this call has value <tt>(this × * 10<sup>-n</sup>)</tt> and scale {@code max(this.scale()+n, * 0)}. * * @param n number of places to move the decimal point to the left. * @return a {@code BigDecimal} which is equivalent to this one with the * decimal point moved {@code n} places to the left. * @throws ArithmeticException if scale overflows. */ public BigDecimal movePointLeft(int n) { // Cannot use movePointRight(-n) in case of n==Integer.MIN_VALUE int newScale = checkScale((long)scale + n); BigDecimal num = new BigDecimal(intVal, intCompact, newScale, 0); return num.scale < 0 ? num.setScale(0, ROUND_UNNECESSARY) : num; }
/** * Returns a {@code BigDecimal} which is equivalent to this one * with the decimal point moved {@code n} places to the left. If * {@code n} is non-negative, the call merely adds {@code n} to * the scale. If {@code n} is negative, the call is equivalent * to {@code movePointRight(-n)}. The {@code BigDecimal} * returned by this call has value <tt>(this × * 10<sup>-n</sup>)</tt> and scale {@code max(this.scale()+n, * 0)}. * * @param n number of places to move the decimal point to the left. * @return a {@code BigDecimal} which is equivalent to this one with the * decimal point moved {@code n} places to the left. * @throws ArithmeticException if scale overflows. */ public BigDecimal movePointLeft(int n) { // Cannot use movePointRight(-n) in case of n==Integer.MIN_VALUE int newScale = checkScale((long)scale + n); BigDecimal num = new BigDecimal(intVal, intCompact, newScale, 0); return num.scale < 0 ? num.setScale(0, ROUND_UNNECESSARY) : num; }
/** * Returns a {@code BigDecimal} which is equivalent to this one * with the decimal point moved {@code n} places to the right. * If {@code n} is non-negative, the call merely subtracts * {@code n} from the scale. If {@code n} is negative, the call * is equivalent to {@code movePointLeft(-n)}. The * {@code BigDecimal} returned by this call has value <tt>(this * × 10<sup>n</sup>)</tt> and scale {@code max(this.scale()-n, * 0)}. * * @param n number of places to move the decimal point to the right. * @return a {@code BigDecimal} which is equivalent to this one * with the decimal point moved {@code n} places to the right. * @throws ArithmeticException if scale overflows. */ public BigDecimal movePointRight(int n) { // Cannot use movePointLeft(-n) in case of n==Integer.MIN_VALUE int newScale = checkScale((long)scale - n); BigDecimal num = new BigDecimal(intVal, intCompact, newScale, 0); return num.scale < 0 ? num.setScale(0, ROUND_UNNECESSARY) : num; }
/** * Returns a {@code BigDecimal} whose value is * <tt>(this<sup>n</sup>)</tt>, The power is computed exactly, to * unlimited precision. * * <p>The parameter {@code n} must be in the range 0 through * 999999999, inclusive. {@code ZERO.pow(0)} returns {@link * #ONE}. * * Note that future releases may expand the allowable exponent * range of this method. * * @param n power to raise this {@code BigDecimal} to. * @return <tt>this<sup>n</sup></tt> * @throws ArithmeticException if {@code n} is out of range. * @since 1.5 */ public BigDecimal pow(int n) { if (n < 0 || n > 999999999) throw new ArithmeticException("Invalid operation"); // No need to calculate pow(n) if result will over/underflow. // Don't attempt to support "supernormal" numbers. int newScale = checkScale((long)scale * n); this.inflate(); return new BigDecimal(intVal.pow(n), newScale); }
/** * Returns a {@code BigDecimal} whose value is * <tt>(this<sup>n</sup>)</tt>, The power is computed exactly, to * unlimited precision. * * <p>The parameter {@code n} must be in the range 0 through * 999999999, inclusive. {@code ZERO.pow(0)} returns {@link * #ONE}. * * Note that future releases may expand the allowable exponent * range of this method. * * @param n power to raise this {@code BigDecimal} to. * @return <tt>this<sup>n</sup></tt> * @throws ArithmeticException if {@code n} is out of range. * @since 1.5 */ public BigDecimal pow(int n) { if (n < 0 || n > 999999999) throw new ArithmeticException("Invalid operation"); // No need to calculate pow(n) if result will over/underflow. // Don't attempt to support "supernormal" numbers. int newScale = checkScale((long)scale * n); this.inflate(); return new BigDecimal(intVal.pow(n), newScale); }
if (checkScale((long)scale + divisor.scale) > this.scale) dividend = this.setScale(scale + divisor.scale, ROUND_UNNECESSARY); else divisor = divisor.setScale(checkScale((long)this.scale - scale), ROUND_UNNECESSARY); return divideAndRound(dividend.intCompact, dividend.intVal,
long x = this.intCompact; long y = multiplicand.intCompact; int productScale = checkScale((long)scale + multiplicand.scale);
if (checkScale((long)scale + divisor.scale) > this.scale) dividend = this.setScale(scale + divisor.scale, ROUND_UNNECESSARY); else divisor = divisor.setScale(checkScale((long)this.scale - scale), ROUND_UNNECESSARY); return divideAndRound(dividend.intCompact, dividend.intVal,
long x = this.intCompact; long y = multiplicand.intCompact; int productScale = checkScale((long)scale + multiplicand.scale);
smallHighDigitPos > estResultUlpScale + 2) { // small digits not visible small = BigDecimal.valueOf(small.signum(), this.checkScale(Math.max(big.scale, estResultUlpScale) + 3));
int scl = checkScale(preferredScale + yscale - xscale + mcp); if (checkScale((long)mcp + yscale) > xscale) dividend = dividend.setScale(mcp + yscale, ROUND_UNNECESSARY); else divisor = divisor.setScale(checkScale((long)xscale - mcp), ROUND_UNNECESSARY); quotient = divideAndRound(dividend.intCompact, dividend.intVal, divisor.intCompact, divisor.intVal, scl, mc.roundingMode.oldMode, checkScale(preferredScale));
if (sdiff != 0) { if (sdiff < 0) { int raise = checkScale(-sdiff); rscale = augend.scale; if (xs == INFLATED || fst = bigMultiplyPowerTen(raise); } else { int raise = augend.checkScale(sdiff); if (ys == INFLATED || (ys = longMultiplyPowerTen(ys, raise)) == INFLATED)
if (sdiff != 0) { if (sdiff < 0) { int raise = checkScale(-sdiff); rscale = augend.scale; if (xs == INFLATED || fst = bigMultiplyPowerTen(raise); } else { int raise = augend.checkScale(sdiff); if (ys == INFLATED || (ys = longMultiplyPowerTen(ys, raise)) == INFLATED)
int newScale = d.checkScale((long)d.scale - drop); int mode = mc.roundingMode.oldMode; if (drop < LONG_TEN_POWERS_TABLE.length)
int newScale = d.checkScale((long)d.scale - drop); int mode = mc.roundingMode.oldMode; if (drop < LONG_TEN_POWERS_TABLE.length)
break; // non-0 remainder intVal=qr[0]; scale = checkScale((long)scale-1); // could Overflow if (precision > 0) // adjust precision if known precision--;
break; // non-0 remainder intVal=qr[0]; scale = checkScale((long)scale-1); // could Overflow if (precision > 0) // adjust precision if known precision--;