java.lang.Object
org.eclipse.rdf4j.query.algebra.evaluation.util.MathUtil

public class MathUtil extends Object
A utility class for evaluation of mathematical expressions on RDF literals.
Author:
Jeen Broekstra
  • Field Details

    • DEFAULT_DECIMAL_EXPANSION_SCALE

      public static final int DEFAULT_DECIMAL_EXPANSION_SCALE
      The 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
      Throws:
      ValueExprEvaluationException
    • compute

      public static Literal compute(Literal leftLit, Literal rightLit, MathExpr.MathOp op, ValueFactory vf) throws ValueExprEvaluationException
      Computes the result of applying the supplied math operator on the supplied left and right operand.
      Parameters:
      leftLit - a numeric datatype literal
      rightLit - a numeric datatype literal
      op - a mathematical operator, as definied by MathExpr.MathOp.
      vf - a ValueFactory used to create the result
      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.