Debian Codegraph @

net/sf/saxon/functions/Round.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
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 * This class implements the fn:round() function
19 */
20
21 public final class Round extends SystemFunction {
22
23 /**
24 * Determine the cardinality of the function.
25 */
26
27 public int getCardinality(Expression[] arguments) {
28 return arguments[0].getCardinality();
29 }
30
31 /**
32 * Evaluate the expression
33 *
34 * @param context the dynamic evaluation context
35 * @param arguments the values of the arguments, supplied as Sequences
36 * @return the result of the evaluation, in the form of a Sequence
37 * @throws net.sf.saxon.trans.XPathException
38 * if a dynamic error occurs during the evaluation of the expression
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