Navigation
Synopsis Mathematical functions.
Usage import util::Math;
Description The Math library provides the following functions:

  • abs: Absolute value of a number.
  • arbInt: Generate a random integer value.
  • arbRat: Generate an arbitrary rational value.
  • arbReal: Generate a random real value in the interval [0.0,1.0).
  • arbSeed: Define the seed for the generation of arbitrary values.
  • ceil: Compute the smallest integer that is larger than a given number.
  • cos: Calculate the cosine of a numeric value.
  • denominator: Return the denominator of a rational value.
  • E: The constant E.
  • exp: Compute exp(x).
  • floor: Compute the largest integer that is smaller than a given number.
  • ln: Calculate the natural log of a numeric value.
  • log: Calculate the logbase of a numeric value.
  • log10: Compute the 10 based log(x).
  • log2: Compute the 2 based log(x).
  • max: Determine the largest of two numeric values.
  • min: Determine the smallest of two numeric values.
  • nroot: Calculate the nth root of a numeric value.
  • numerator: Return the numerator of a rational value.
  • percent: Compute the ratio between two numbers as a percentage.
  • PI: The constant pi.
  • pow: Calculate an arbitrary power of a numeric value.
  • precision: Return the precision of a real number.
  • primes: generate prime numbers up to a maximum
  • remainder: Return the remainder of dividing the numerator by the denominator.
  • round: Round a number to the nearest multiple of a given number (default 1).
  • scale: Return the scale of a real number.
  • setPrecision: Define the precision for numeric calculations; returns the previous precision.
  • sin: Calculate the sine of a numeric value.
  • sqrt: Calculate the square root of a numeric value.
  • tan: Calculate the tangent of a numeric value.
  • toInt: Convert a numeric value to an integer.
  • toRat: Convert two numbers to a rational value (not supported on reals).
  • toReal: Convert a numeric value to a real.
  • toString: Convert a numeric value to a string.
  • unscaled: Return the unscaled integer of a real.
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.