Class MathUtil
java.lang.Object
org.eclipse.rdf4j.query.algebra.evaluation.util.MathUtil
A utility class for evaluation of mathematical expressions on RDF literals.
- Author:
- Jeen Broekstra
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Literal
compute
(Literal leftLit, Literal rightLit, MathExpr.MathOp op) Computes the result of applying the supplied math operator on the supplied left and right operand.static int
Returns the decimal expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion.static void
setDecimalExpansionScale
(int decimalExpansionScale) Sets the decimal expansion scale used in divisions resulting in a decimal value with non-terminating decimal expansion.
-
Field Details
-
DEFAULT_DECIMAL_EXPANSION_SCALE
public static final int DEFAULT_DECIMAL_EXPANSION_SCALEThe default expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion. The OpenRDF default is 24 digits, a value used in various other SPARQL implementations, to make comparison between these systems easy.- See Also:
-
-
Constructor Details
-
MathUtil
public MathUtil()
-
-
Method Details
-
compute
public static Literal compute(Literal leftLit, Literal rightLit, MathExpr.MathOp op) throws ValueExprEvaluationException Computes the result of applying the supplied math operator on the supplied left and right operand.- Parameters:
leftLit
- a numeric datatype literalrightLit
- a numeric datatype literalop
- a mathematical operator, as definied by MathExpr.MathOp.- Returns:
- a numeric datatype literal containing the result of the operation. The result will be datatype according to the most specific data type the two operands have in common per the SPARQL/XPath spec.
- Throws:
ValueExprEvaluationException
-
getDecimalExpansionScale
public static int getDecimalExpansionScale()Returns the decimal expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion. By default, this value is set to 24.- Returns:
- The decimal expansion scale.
-
setDecimalExpansionScale
public static void setDecimalExpansionScale(int decimalExpansionScale) Sets the decimal expansion scale used in divisions resulting in a decimal value with non-terminating decimal expansion.- Parameters:
decimalExpansionScale
- The decimal expansion scale to set. Note that a mimimum of 18 is required to stay compliant with the XPath specification of xsd:decimal operations.
-