Skip to content

Commit f964611

Browse files
committed
Store log5(2) in BigDecimal
1 parent 439012d commit f964611

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/java.base/share/classes/java/math/BigDecimal.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5239,6 +5239,8 @@ private static BigInteger fiveToTwoToThe(int n) {
52395239
return pow;
52405240
}
52415241

5242+
private static final double LOG_5_OF_2 = Math.log(2.0) / Math.log(5.0);
5243+
52425244
/**
52435245
* Remove insignificant trailing zeros from this
52445246
* {@code BigInteger} value until the preferred scale is reached or no
@@ -5265,7 +5267,7 @@ private static BigDecimal createAndStripZerosToMatchScale(BigInteger intVal, int
52655267

52665268
intVal = intVal.shiftRight(powsOf2); // remove powers of 2
52675269
// maxPowsOf5 == ceil(log5(intVal)) roughly
5268-
long maxPowsOf5 = (long) Math.ceil(intVal.bitLength() * BigInteger.LOG_TWO / BigInteger.logCache[5]);
5270+
long maxPowsOf5 = (long) Math.ceil(intVal.bitLength() * LOG_5_OF_2);
52695271
remainingZeros = Math.min(remainingZeros, maxPowsOf5);
52705272

52715273
BigInteger[] qr; // quotient-remainder pair

src/java.base/share/classes/java/math/BigInteger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,10 +1296,10 @@ private static BigInteger valueOf(int[] val) {
12961296
private static volatile BigInteger[][] powerCache;
12971297

12981298
/** The cache of logarithms of radices for base conversion. */
1299-
static final double[] logCache;
1299+
private static final double[] logCache;
13001300

13011301
/** The natural log of 2. This is used in computing cache indices. */
1302-
static final double LOG_TWO = Math.log(2.0);
1302+
private static final double LOG_TWO = Math.log(2.0);
13031303

13041304
static {
13051305
assert 0 < KARATSUBA_THRESHOLD

0 commit comments

Comments
 (0)