32
32
import java .lang .reflect .Method ;
33
33
import java .math .BigDecimal ;
34
34
import java .math .BigInteger ;
35
+ import java .math .RoundingMode ;
35
36
import java .util .function .IntSupplier ;
36
37
import java .util .regex .Pattern ;
37
38
@@ -300,14 +301,14 @@ public NumericValue negate() throws XPathException {
300
301
* @see org.exist.xquery.value.NumericValue#ceiling()
301
302
*/
302
303
public NumericValue ceiling () throws XPathException {
303
- return new DecimalValue (value .setScale (0 , BigDecimal . ROUND_CEILING ));
304
+ return new DecimalValue (value .setScale (0 , RoundingMode . CEILING ));
304
305
}
305
306
306
307
/* (non-Javadoc)
307
308
* @see org.exist.xquery.value.NumericValue#floor()
308
309
*/
309
310
public NumericValue floor () throws XPathException {
310
- return new DecimalValue (value .setScale (0 , BigDecimal . ROUND_FLOOR ));
311
+ return new DecimalValue (value .setScale (0 , RoundingMode . FLOOR ));
311
312
}
312
313
313
314
/* (non-Javadoc)
@@ -316,11 +317,11 @@ public NumericValue floor() throws XPathException {
316
317
public NumericValue round () throws XPathException {
317
318
switch (value .signum ()) {
318
319
case -1 :
319
- return new DecimalValue (value .setScale (0 , BigDecimal . ROUND_HALF_DOWN ));
320
+ return new DecimalValue (value .setScale (0 , RoundingMode . HALF_DOWN ));
320
321
case 0 :
321
322
return this ;
322
323
case 1 :
323
- return new DecimalValue (value .setScale (0 , BigDecimal . ROUND_HALF_UP ));
324
+ return new DecimalValue (value .setScale (0 , RoundingMode . HALF_UP ));
324
325
default :
325
326
return this ;
326
327
}
@@ -342,11 +343,11 @@ public NumericValue round(IntegerValue precision) throws XPathException {
342
343
}
343
344
344
345
if (pre >= 0 ) {
345
- return new DecimalValue (value .setScale (pre , BigDecimal . ROUND_HALF_EVEN ));
346
+ return new DecimalValue (value .setScale (pre , RoundingMode . HALF_EVEN ));
346
347
} else {
347
348
return new DecimalValue (
348
349
value .movePointRight (pre ).
349
- setScale (0 , BigDecimal . ROUND_HALF_EVEN ).
350
+ setScale (0 , RoundingMode . HALF_EVEN ).
350
351
movePointLeft (pre ));
351
352
}
352
353
}
@@ -416,7 +417,7 @@ public ComputableValue div(ComputableValue other) throws XPathException {
416
417
417
418
//Copied from Saxon 8.6.1
418
419
final int scale = Math .max (DIVIDE_PRECISION , Math .max (value .scale (), ((DecimalValue ) other ).value .scale ()));
419
- final BigDecimal result = value .divide (((DecimalValue ) other ).value , scale , BigDecimal . ROUND_HALF_DOWN );
420
+ final BigDecimal result = value .divide (((DecimalValue ) other ).value , scale , RoundingMode . HALF_DOWN );
420
421
return new DecimalValue (result );
421
422
//End of copy
422
423
}
@@ -428,7 +429,7 @@ public IntegerValue idiv(NumericValue other) throws XPathException {
428
429
}
429
430
430
431
final DecimalValue dv = (DecimalValue ) other .convertTo (Type .DECIMAL );
431
- final BigInteger quot = value .divide (dv .value , 0 , BigDecimal . ROUND_DOWN ).toBigInteger ();
432
+ final BigInteger quot = value .divide (dv .value , 0 , RoundingMode . DOWN ).toBigInteger ();
432
433
return new IntegerValue (quot );
433
434
}
434
435
@@ -441,8 +442,8 @@ public NumericValue mod(NumericValue other) throws XPathException {
441
442
throw new XPathException (ErrorCodes .FOAR0001 , "division by zero" );
442
443
}
443
444
444
- final BigDecimal quotient = value .divide (((DecimalValue ) other ).value , 0 , BigDecimal . ROUND_DOWN );
445
- final BigDecimal remainder = value .subtract (quotient .setScale (0 , BigDecimal . ROUND_DOWN ).multiply (((DecimalValue ) other ).value ));
445
+ final BigDecimal quotient = value .divide (((DecimalValue ) other ).value , 0 , RoundingMode . DOWN );
446
+ final BigDecimal remainder = value .subtract (quotient .setScale (0 , RoundingMode . DOWN ).multiply (((DecimalValue ) other ).value ));
446
447
return new DecimalValue (remainder );
447
448
} else {
448
449
return ((NumericValue ) convertTo (other .getType ())).mod (other );
0 commit comments