| 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.Sequence; |
| 13 |
import net.sf.saxon.om.ZeroOrOne; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.value.NumericValue; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public final class Round extends SystemFunction { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public int getCardinality(Expression[] arguments) { |
| 28 |
return arguments[0].getCardinality(); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public ZeroOrOne<NumericValue> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 41 |
NumericValue val0 = (NumericValue) arguments[0].head(); |
| 42 |
if (val0 == null) { |
| 43 |
return ZeroOrOne.empty(); |
| 44 |
} |
| 45 |
|
| 46 |
int scaleRnd = 0; |
| 47 |
if (arguments.length == 2) { |
| 48 |
NumericValue scaleVal = (NumericValue) arguments[1].head(); |
| 49 |
scaleRnd = (int) scaleVal.longValue(); |
| 50 |
} |
| 51 |
return new ZeroOrOne<>(val0.round(scaleRnd)); |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
public String getCompilerName() { |
| 56 |
return "RoundingCompiler"; |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|