use BigInteger for average chart calculations

This commit is contained in:
woodser 2025-06-29 15:10:10 -04:00 committed by woodser
parent 3546d3d931
commit 33c9628df3
2 changed files with 31 additions and 16 deletions

View file

@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.ArrayDeque;
import java.util.Deque;
@ -85,6 +86,11 @@ public class MathUtils {
return ((double) value) * factor;
}
public static BigInteger scaleUpByPowerOf10(BigInteger value, int exponent) {
BigInteger factor = BigInteger.TEN.pow(exponent);
return value.multiply(factor);
}
public static double scaleDownByPowerOf10(double value, int exponent) {
double factor = Math.pow(10, exponent);
return value / factor;
@ -95,6 +101,11 @@ public class MathUtils {
return ((double) value) / factor;
}
public static BigInteger scaleDownByPowerOf10(BigInteger value, int exponent) {
BigInteger factor = BigInteger.TEN.pow(exponent);
return value.divide(factor);
}
public static double exactMultiply(double value1, double value2) {
return BigDecimal.valueOf(value1).multiply(BigDecimal.valueOf(value2)).doubleValue();
}