提交 c572cd1b authored 作者: Thomas Mueller's avatar Thomas Mueller

Version 1.2.136 could not be converted to Java 1.4 (because the Retrotranslator…

Version 1.2.136 could not be converted to Java 1.4 (because the Retrotranslator doesn't support BigDecimal.precision).
上级 fab92cf1
......@@ -30,6 +30,8 @@ public class MathUtils {
*/
static volatile boolean seeded;
private static boolean usePrecisionWorkaround;
private static final Random RANDOM = new Random();
/**
......@@ -304,6 +306,24 @@ public class MathUtils {
return (reverseInt((int) (x >>> 32L)) & 0xffffffffL) ^ (((long) reverseInt((int) x)) << 32L);
}
/**
* Compatibility for BigDecimal.precision() which is not available in Java 1.4.
*
* @param x the value
* @return the precision
*/
public static int precision(BigDecimal x) {
if (!usePrecisionWorkaround) {
try {
return x.precision();
} catch (Exception e) {
// NoSuchMethodError
usePrecisionWorkaround = true;
}
}
return x.unscaledValue().abs().toString().length();
}
/**
* Compare two values. Returns -1 if the first value is smaller, 1 if bigger,
* and 0 if equal.
......
......@@ -134,7 +134,7 @@ public class ValueDecimal extends Value {
public long getPrecision() {
if (precision == 0) {
precision = value.precision();
precision = MathUtils.precision(value);
}
return precision;
}
......@@ -211,7 +211,7 @@ public class ValueDecimal extends Value {
}
public int getMemory() {
return value.precision() * 3 + 120;
return MathUtils.precision(value) * 3 + 120;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论