| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Expression; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.om.One; |
| 13 |
import net.sf.saxon.om.Sequence; |
| 14 |
import net.sf.saxon.om.ZeroOrOne; |
| 15 |
import net.sf.saxon.trans.XPathException; |
| 16 |
import net.sf.saxon.value.NumericValue; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public final class RoundHalfToEven extends SystemFunction { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public int getCardinality(Expression[] arguments) { |
| 29 |
return arguments[0].getCardinality(); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public ZeroOrOne<NumericValue> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 42 |
NumericValue val0 = (NumericValue) arguments[0].head(); |
| 43 |
if (val0 == null) { |
| 44 |
return ZeroOrOne.empty(); |
| 45 |
} |
| 46 |
|
| 47 |
int scale = 0; |
| 48 |
if (arguments.length == 2) { |
| 49 |
NumericValue scaleVal = (NumericValue) arguments[1].head(); |
| 50 |
if (scaleVal.compareTo(Integer.MAX_VALUE) > 0) { |
| 51 |
return new ZeroOrOne<>(val0); |
| 52 |
} else if (scaleVal.compareTo(Integer.MIN_VALUE) < 0) { |
| 53 |
scale = Integer.MIN_VALUE; |
| 54 |
} else { |
| 55 |
scale = (int) scaleVal.longValue(); |
| 56 |
} |
| 57 |
} |
| 58 |
return new One<>(val0.roundHalfToEven(scale)); |
| 59 |
} |
| 60 |
|
| 61 |
public String getCompilerName() { |
| 62 |
return "RoundingCompiler"; |
| 63 |
} |
| 64 |
|
| 65 |
} |
| 66 |
|