diff --git a/src/main/java/net/sf/saxon/expr/Calculator.java b/src/main/java/net/sf/saxon/expr/Calculator.java index 58d3c3c..8c84279 100644 --- a/src/main/java/net/sf/saxon/expr/Calculator.java +++ b/src/main/java/net/sf/saxon/expr/Calculator.java @@ -19,6 +19,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.math.MathContext; import java.math.RoundingMode; /** @@ -817,7 +818,7 @@ public AtomicValue compute(AtomicValue a, AtomicValue b, XPathContext c) throws return ((IntegerValue) a).times((IntegerValue) b); } else { return new BigDecimalValue( - ((NumericValue) a).getDecimalValue().multiply(((NumericValue) b).getDecimalValue())); + ((NumericValue) a).getDecimalValue().multiply(((NumericValue) b).getDecimalValue(), MathContext.DECIMAL128)); } } @@ -846,12 +847,9 @@ public AtomicType getResultType(AtomicType typeA, AtomicType typeB) { public static BigDecimalValue decimalDivide(NumericValue a, NumericValue b) throws XPathException { final BigDecimal A = a.getDecimalValue(); final BigDecimal B = b.getDecimalValue(); -// int scale = Math.max(DecimalValue.DIVIDE_PRECISION, -// Math.max(A.scale(), B.scale())); - int scale = Math.max(BigDecimalValue.DIVIDE_PRECISION, A.scale() - B.scale() + BigDecimalValue.DIVIDE_PRECISION); try { - BigDecimal result = A.divide(B, scale, RoundingMode.HALF_DOWN); + BigDecimal result = A.divide(B, MathContext.DECIMAL128); return new BigDecimalValue(result); } catch (ArithmeticException err) { if (b.compareTo(0) == 0) {