< prev index next >
src/java.base/share/classes/java/math/BigDecimal.java
Print this page
*** 288,298 ****
return new StringBuilderHelper();
}
};
// Cache of common small BigDecimal values.
! private static final BigDecimal ZERO_THROUGH_TEN[] = {
new BigDecimal(BigInteger.ZERO, 0, 0, 1),
new BigDecimal(BigInteger.ONE, 1, 0, 1),
new BigDecimal(BigInteger.TWO, 2, 0, 1),
new BigDecimal(BigInteger.valueOf(3), 3, 0, 1),
new BigDecimal(BigInteger.valueOf(4), 4, 0, 1),
--- 288,298 ----
return new StringBuilderHelper();
}
};
// Cache of common small BigDecimal values.
! private static final BigDecimal[] ZERO_THROUGH_TEN = {
new BigDecimal(BigInteger.ZERO, 0, 0, 1),
new BigDecimal(BigInteger.ONE, 1, 0, 1),
new BigDecimal(BigInteger.TWO, 2, 0, 1),
new BigDecimal(BigInteger.valueOf(3), 3, 0, 1),
new BigDecimal(BigInteger.valueOf(4), 4, 0, 1),
*** 531,541 ****
prec = longDigitLength(rs);
drop = prec - mcp;
}
}
} else {
! char coeff[] = new char[len];
for (; len > 0; offset++, len--) {
c = in[offset];
// have digit
if ((c >= '0' && c <= '9') || Character.isDigit(c)) {
// First compact case, we need not to preserve the character
--- 531,541 ----
prec = longDigitLength(rs);
drop = prec - mcp;
}
}
} else {
! char[] coeff = new char[len];
for (; len > 0; offset++, len--) {
c = in[offset];
// have digit
if ((c >= '0' && c <= '9') || Character.isDigit(c)) {
// First compact case, we need not to preserve the character
*** 1372,1382 ****
}
}
long padding = (long) lhs.scale - augend.scale;
if (padding != 0) { // scales differ; alignment needed
! BigDecimal arg[] = preAlign(lhs, augend, padding, mc);
matchScale(arg);
lhs = arg[0];
augend = arg[1];
}
return doRound(lhs.inflated().add(augend.inflated()), lhs.scale, mc);
--- 1372,1382 ----
}
}
long padding = (long) lhs.scale - augend.scale;
if (padding != 0) { // scales differ; alignment needed
! BigDecimal[] arg = preAlign(lhs, augend, padding, mc);
matchScale(arg);
lhs = arg[0];
augend = arg[1];
}
return doRound(lhs.inflated().add(augend.inflated()), lhs.scale, mc);
*** 1911,1921 ****
* @return {@code this % divisor}.
* @throws ArithmeticException if {@code divisor==0}
* @since 1.5
*/
public BigDecimal remainder(BigDecimal divisor) {
! BigDecimal divrem[] = this.divideAndRemainder(divisor);
return divrem[1];
}
/**
--- 1911,1921 ----
* @return {@code this % divisor}.
* @throws ArithmeticException if {@code divisor==0}
* @since 1.5
*/
public BigDecimal remainder(BigDecimal divisor) {
! BigDecimal[] divrem = this.divideAndRemainder(divisor);
return divrem[1];
}
/**
*** 1941,1951 ****
* require a precision of more than {@code mc.precision} digits.
* @see #divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
* @since 1.5
*/
public BigDecimal remainder(BigDecimal divisor, MathContext mc) {
! BigDecimal divrem[] = this.divideAndRemainder(divisor, mc);
return divrem[1];
}
/**
* Returns a two-element {@code BigDecimal} array containing the
--- 1941,1951 ----
* require a precision of more than {@code mc.precision} digits.
* @see #divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
* @since 1.5
*/
public BigDecimal remainder(BigDecimal divisor, MathContext mc) {
! BigDecimal[] divrem = this.divideAndRemainder(divisor, mc);
return divrem[1];
}
/**
* Returns a two-element {@code BigDecimal} array containing the
*** 3631,3652 ****
/**
* Powers of 10 which can be represented exactly in {@code
* double}.
*/
! private static final double DOUBLE_10_POW[] = {
1.0e0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5,
1.0e6, 1.0e7, 1.0e8, 1.0e9, 1.0e10, 1.0e11,
1.0e12, 1.0e13, 1.0e14, 1.0e15, 1.0e16, 1.0e17,
1.0e18, 1.0e19, 1.0e20, 1.0e21, 1.0e22
};
/**
* Powers of 10 which can be represented exactly in {@code
* float}.
*/
! private static final float FLOAT_10_POW[] = {
1.0e0f, 1.0e1f, 1.0e2f, 1.0e3f, 1.0e4f, 1.0e5f,
1.0e6f, 1.0e7f, 1.0e8f, 1.0e9f, 1.0e10f
};
/**
--- 3631,3652 ----
/**
* Powers of 10 which can be represented exactly in {@code
* double}.
*/
! private static final double[] DOUBLE_10_POW = {
1.0e0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5,
1.0e6, 1.0e7, 1.0e8, 1.0e9, 1.0e10, 1.0e11,
1.0e12, 1.0e13, 1.0e14, 1.0e15, 1.0e16, 1.0e17,
1.0e18, 1.0e19, 1.0e20, 1.0e21, 1.0e22
};
/**
* Powers of 10 which can be represented exactly in {@code
* float}.
*/
! private static final float[] FLOAT_10_POW = {
1.0e0f, 1.0e1f, 1.0e2f, 1.0e3f, 1.0e4f, 1.0e5f,
1.0e6f, 1.0e7f, 1.0e8f, 1.0e9f, 1.0e10f
};
/**
*** 3950,3960 ****
10000000000000000L, // 16 / 10^16
100000000000000000L, // 17 / 10^17
1000000000000000000L // 18 / 10^18
};
! private static volatile BigInteger BIG_TEN_POWERS_TABLE[] = {
BigInteger.ONE,
BigInteger.valueOf(10),
BigInteger.valueOf(100),
BigInteger.valueOf(1000),
BigInteger.valueOf(10000),
--- 3950,3960 ----
10000000000000000L, // 16 / 10^16
100000000000000000L, // 17 / 10^17
1000000000000000000L // 18 / 10^18
};
! private static volatile BigInteger[] BIG_TEN_POWERS_TABLE = {
BigInteger.ONE,
BigInteger.valueOf(10),
BigInteger.valueOf(100),
BigInteger.valueOf(1000),
BigInteger.valueOf(10000),
*** 3977,3987 ****
private static final int BIG_TEN_POWERS_TABLE_INITLEN =
BIG_TEN_POWERS_TABLE.length;
private static final int BIG_TEN_POWERS_TABLE_MAX =
16 * BIG_TEN_POWERS_TABLE_INITLEN;
! private static final long THRESHOLDS_TABLE[] = {
Long.MAX_VALUE, // 0
Long.MAX_VALUE/10L, // 1
Long.MAX_VALUE/100L, // 2
Long.MAX_VALUE/1000L, // 3
Long.MAX_VALUE/10000L, // 4
--- 3977,3987 ----
private static final int BIG_TEN_POWERS_TABLE_INITLEN =
BIG_TEN_POWERS_TABLE.length;
private static final int BIG_TEN_POWERS_TABLE_MAX =
16 * BIG_TEN_POWERS_TABLE_INITLEN;
! private static final long[] THRESHOLDS_TABLE = {
Long.MAX_VALUE, // 0
Long.MAX_VALUE/10L, // 1
Long.MAX_VALUE/100L, // 2
Long.MAX_VALUE/1000L, // 3
Long.MAX_VALUE/10000L, // 4
*** 4710,4720 ****
*
* @return new {@code BigDecimal} with a scale possibly reduced
* to be closed to the preferred scale.
*/
private static BigDecimal createAndStripZerosToMatchScale(BigInteger intVal, int scale, long preferredScale) {
! BigInteger qr[]; // quotient-remainder pair
while (intVal.compareMagnitude(BigInteger.TEN) >= 0
&& scale > preferredScale) {
if (intVal.testBit(0))
break; // odd number cannot end in 0
qr = intVal.divideAndRemainder(BigInteger.TEN);
--- 4710,4720 ----
*
* @return new {@code BigDecimal} with a scale possibly reduced
* to be closed to the preferred scale.
*/
private static BigDecimal createAndStripZerosToMatchScale(BigInteger intVal, int scale, long preferredScale) {
! BigInteger[] qr; // quotient-remainder pair
while (intVal.compareMagnitude(BigInteger.TEN) >= 0
&& scale > preferredScale) {
if (intVal.testBit(0))
break; // odd number cannot end in 0
qr = intVal.divideAndRemainder(BigInteger.TEN);
< prev index next >