/** * Returns this {@code BigDecimal} as an long value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an long, then {@code this % 2<sup>64</sup>} is returned. */ @Override public long longValue() { /* * If scale <= -64 there are at least 64 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue()); }
/** * Returns this {@code BigDecimal} as an int value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an int, then {@code this % 2<sup>32</sup>} is returned. */ @Override public int intValue() { /* * If scale <= -32 there are at least 32 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue()); }
int diffPrecision = this.approxPrecision() - val.approxPrecision(); if (diffPrecision > diffScale + 1) { return thisSign;
if (this.approxPrecision() < diffScale - 1) { larger = augend; smaller = this; } else if (augend.approxPrecision() < -diffScale - 1) { larger = this; smaller = augend; return add(augend).round(mc); if (mc.getPrecision() >= larger.approxPrecision()) {
if (subtrahend.approxPrecision() < diffScale - 1) { if (mc.getPrecision() < this.approxPrecision()) { thisSignum = this.signum(); if (thisSignum != subtrahend.signum()) {
if (approxPrecision() < mcPrecision || mcPrecision == 0) { return;
/** * Returns this {@code BigDecimal} as a big integer instance if it has no * fractional part. If this {@code BigDecimal} has a fractional part, i.e. * if rounding would be necessary, an {@code ArithmeticException} is thrown. * * @return this {@code BigDecimal} as a big integer value. * @throws ArithmeticException * if rounding is necessary. */ public BigInteger toBigIntegerExact() { if ((scale == 0) || (isZero())) { return getUnscaledValue(); } else if (scale < 0) { return getUnscaledValue().multiply(Multiplication.powerOf10(-(long)scale)); } else {// (scale > 0) BigInteger[] integerAndFraction; // An optimization before do a heavy division if ((scale > approxPrecision()) || (scale > getUnscaledValue().getLowestSetBit())) { throw new ArithmeticException("Rounding necessary"); } integerAndFraction = getUnscaledValue().divideAndRemainder(Multiplication.powerOf10(scale)); if (integerAndFraction[1].signum() != 0) { // It exists a non-zero fractional part throw new ArithmeticException("Rounding necessary"); } return integerAndFraction[0]; } }
+ divisor.approxPrecision() - approxPrecision(); long diffScale = (long)scale - divisor.scale; long newScale = diffScale; // scale of the final quotient
throw new ArithmeticException("Division by zero"); if ((divisor.approxPrecision() + newScale > this.approxPrecision() + 1L) || (this.isZero())) {
/** * Returns this {@code BigDecimal} as an int value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an int, then {@code this % 2<sup>32</sup>} is returned. */ @Override public int intValue() { /* * If scale <= -32 there are at least 32 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue()); }
/** * Returns this {@code BigDecimal} as an long value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an long, then {@code this % 2<sup>64</sup>} is returned. */ @Override public long longValue() { /* * If scale <= -64 there are at least 64 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue()); }
/** * Returns this {@code BigDecimal} as an int value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an int, then {@code this % 2<sup>32</sup>} is returned. */ @Override public int intValue() { /* * If scale <= -32 there are at least 32 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue()); }
/** * Returns this {@code BigDecimal} as an int value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an int, then {@code this % 2<sup>32</sup>} is returned. */ @Override public int intValue() { /* * If scale <= -32 there are at least 32 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue()); }
/** * Returns this {@code BigDecimal} as an long value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an long, then {@code this % 2<sup>64</sup>} is returned. */ @Override public long longValue() { /* * If scale <= -64 there are at least 64 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue()); }
/** * Returns this {@code BigDecimal} as an int value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an int, then {@code this % 2<sup>32</sup>} is returned. */ @Override public int intValue() { /* * If scale <= -32 there are at least 32 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue()); }
/** * Returns this {@code BigDecimal} as an int value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an int, then {@code this % 2<sup>32</sup>} is returned. */ @Override public int intValue() { /* * If scale <= -32 there are at least 32 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue()); }
/** * Returns this {@code BigDecimal} as an int value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an int, then {@code this % 2<sup>32</sup>} is returned. */ @Override public int intValue() { /* * If scale <= -32 there are at least 32 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue()); }
/** * Returns this {@code BigDecimal} as an long value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an long, then {@code this % 2<sup>64</sup>} is returned. */ @Override public long longValue() { /* * If scale <= -64 there are at least 64 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue()); }
/** * Returns this {@code BigDecimal} as an long value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an long, then {@code this % 2<sup>64</sup>} is returned. */ @Override public long longValue() { /* * If scale <= -64 there are at least 64 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue()); }
/** * Returns this {@code BigDecimal} as an long value. Any fractional part is * discarded. If the integral part of {@code this} is too big to be * represented as an long, then {@code this % 2<sup>64</sup>} is returned. */ @Override public long longValue() { /* * If scale <= -64 there are at least 64 trailing bits zero in * 10^(-scale). If the scale is positive and very large the long value * could be zero. */ return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue()); }