Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 1520 lines (42 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

MathTrig:: (74 methods):
  ARABIC()
  ATAN2()
  BASE()
  CEILING()
  COMBIN()
  EVEN()
  getEven()
  FACT()
  FACTDOUBLE()
  FLOOR()
  FLOORMATH()
  FLOORPRECISE()
  INT()
  GCD()
  LCM()
  logBase()
  MDETERM()
  MINVERSE()
  MMULT()
  MOD()
  MROUND()
  MULTINOMIAL()
  ODD()
  POWER()
  PRODUCT()
  QUOTIENT()
  RAND()
  ROMAN()
  ROUNDUP()
  ROUNDDOWN()
  SERIESSUM()
  SIGN()
  returnSign()
  SQRTPI()
  SUBTOTAL()
  SUM()
  SUMIF()
  SUMIFS()
  SUMPRODUCT()
  SUMSQ()
  SUMX2MY2()
  SUMX2PY2()
  SUMXMY2()
  TRUNC()
  SEC()
  SECH()
  CSC()
  CSCH()
  COT()
  COTH()
  ACOT()
  numberOrNan()
  ACOTH()
  builtinROUND()
  builtinABS()
  builtinACOS()
  builtinACOSH()
  builtinASIN()
  builtinASINH()
  builtinATAN()
  builtinATANH()
  builtinCOS()
  builtinCOSH()
  builtinDEGREES()
  builtinEXP()
  builtinLN()
  builtinLOG10()
  builtinRADIANS()
  builtinSIN()
  builtinSINH()
  builtinSQRT()
  builtinTAN()
  builtinTANH()
  nullFalseTrueToNumber()


Class: MathTrig  - X-Ref


ARABIC($roman)   X-Ref
ARABIC.

Converts a Roman numeral to an Arabic numeral.

Excel Function:
ARABIC(text)

param: array|string $roman
return: array|int|string the arabic numberal contrived from the roman numeral

ATAN2($xCoordinate = null, $yCoordinate = null)   X-Ref
ATAN2.

This function calculates the arc tangent of the two variables x and y. It is similar to
calculating the arc tangent of y รท x, except that the signs of both arguments are used
to determine the quadrant of the result.
The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a
point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between
-pi and pi, excluding -pi.

Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard
PHP atan2() function, so we need to reverse them here before calling the PHP atan() function.

Excel Function:
ATAN2(xCoordinate,yCoordinate)

param: array|float $xCoordinate the x-coordinate of the point
param: array|float $yCoordinate the y-coordinate of the point
return: array|float|string the inverse tangent of the specified x- and y-coordinates, or a string containing an error

BASE($number, $radix, $minLength = null)   X-Ref
BASE.

Converts a number into a text representation with the given radix (base).

Excel Function:
BASE(Number, Radix [Min_length])

param: float $number
param: float $radix
param: int $minLength
return: array|string the text representation with the given radix (base)

CEILING($number, $significance = null)   X-Ref
CEILING.

Returns number rounded up, away from zero, to the nearest multiple of significance.
For example, if you want to avoid using pennies in your prices and your product is
priced at $4.42, use the formula =CEILING(4.42,0.05) to round prices up to the
nearest nickel.

Excel Function:
CEILING(number[,significance])

param: float $number the number you want to round
param: float $significance the multiple to which you want to round
return: array|float|string Rounded Number, or a string containing an error

COMBIN($numObjs, $numInSet)   X-Ref
COMBIN.

Returns the number of combinations for a given number of items. Use COMBIN to
determine the total possible number of groups for a given number of items.

Excel Function:
COMBIN(numObjs,numInSet)

param: array|int $numObjs Number of different objects
param: array|int $numInSet Number of objects in each combination
return: array|float|int|string Number of combinations, or a string containing an error

EVEN($number)   X-Ref
EVEN.

Returns number rounded up to the nearest even integer.
You can use this function for processing items that come in twos. For example,
a packing crate accepts rows of one or two items. The crate is full when
the number of items, rounded up to the nearest two, matches the crate's
capacity.

Excel Function:
EVEN(number)

param: array|float $number Number to round
return: array|float|int|string Rounded Number, or a string containing an error

getEven(float $number)   X-Ref
Helper function for Even.


FACT($factVal)   X-Ref
FACT.

Returns the factorial of a number.
The factorial of a number is equal to 1*2*3*...* number.

Excel Function:
FACT(factVal)

param: array|float $factVal Factorial Value
return: array|float|int|string Factorial, or a string containing an error

FACTDOUBLE($factVal)   X-Ref
FACTDOUBLE.

Returns the double factorial of a number.

Excel Function:
FACTDOUBLE(factVal)

param: array|float $factVal Factorial Value
return: array|float|int|string Double Factorial, or a string containing an error

FLOOR($number, $significance = null)   X-Ref
FLOOR.

Rounds number down, toward zero, to the nearest multiple of significance.

Excel Function:
FLOOR(number[,significance])

param: float $number Number to round
param: float $significance Significance
return: array|float|string Rounded Number, or a string containing an error

FLOORMATH($number, $significance = null, $mode = 0)   X-Ref
FLOOR.MATH.

Round a number down to the nearest integer or to the nearest multiple of significance.

Excel Function:
FLOOR.MATH(number[,significance[,mode]])

param: float $number Number to round
param: float $significance Significance
param: int $mode direction to round negative numbers
return: array|float|string Rounded Number, or a string containing an error

FLOORPRECISE($number, $significance = 1)   X-Ref
FLOOR.PRECISE.

Rounds number down, toward zero, to the nearest multiple of significance.

Excel Function:
FLOOR.PRECISE(number[,significance])

param: float $number Number to round
param: float $significance Significance
return: array|float|string Rounded Number, or a string containing an error

INT($number)   X-Ref
INT.

Casts a floating point value to an integer

Excel Function:
INT(number)

param: array|float $number Number to cast to an integer
return: array|int|string Integer value, or a string containing an error

GCD(...$args)   X-Ref
GCD.

Returns the greatest common divisor of a series of numbers.
The greatest common divisor is the largest integer that divides both
number1 and number2 without a remainder.

Excel Function:
GCD(number1[,number2[, ...]])

param: mixed ...$args Data values
return: int|mixed|string Greatest Common Divisor, or a string containing an error

LCM(...$args)   X-Ref
LCM.

Returns the lowest common multiplier of a series of numbers
The least common multiple is the smallest positive integer that is a multiple
of all integer arguments number1, number2, and so on. Use LCM to add fractions
with different denominators.

Excel Function:
LCM(number1[,number2[, ...]])

param: mixed ...$args Data values
return: int|string Lowest Common Multiplier, or a string containing an error

logBase($number, $base = 10)   X-Ref
LOG_BASE.

Returns the logarithm of a number to a specified base. The default base is 10.

Excel Function:
LOG(number[,base])

param: float $number The positive real number for which you want the logarithm
param: float $base The base of the logarithm. If base is omitted, it is assumed to be 10.
return: array|float|string The result, or a string containing an error

MDETERM($matrixValues)   X-Ref
MDETERM.

Returns the matrix determinant of an array.

Excel Function:
MDETERM(array)

param: array $matrixValues A matrix of values
return: float|string The result, or a string containing an error

MINVERSE($matrixValues)   X-Ref
MINVERSE.

Returns the inverse matrix for the matrix stored in an array.

Excel Function:
MINVERSE(array)

param: array $matrixValues A matrix of values
return: array|string The result, or a string containing an error

MMULT($matrixData1, $matrixData2)   X-Ref
MMULT.

param: array $matrixData1 A matrix of values
param: array $matrixData2 A matrix of values
return: array|string The result, or a string containing an error

MOD($a = 1, $b = 1)   X-Ref
MOD.

param: int $a Dividend
param: int $b Divisor
return: array|float|int|string Remainder, or a string containing an error

MROUND($number, $multiple)   X-Ref
MROUND.

Rounds a number to the nearest multiple of a specified value

param: float $number Number to round
param: array|int $multiple Multiple to which you want to round $number
return: array|float|string Rounded Number, or a string containing an error

MULTINOMIAL(...$args)   X-Ref
MULTINOMIAL.

Returns the ratio of the factorial of a sum of values to the product of factorials.

param: mixed[] $args An array of mixed values for the Data Series
return: float|string The result, or a string containing an error

ODD($number)   X-Ref
ODD.

Returns number rounded up to the nearest odd integer.

param: array|float $number Number to round
return: array|float|int|string Rounded Number, or a string containing an error

POWER($x = 0, $y = 2)   X-Ref
POWER.

Computes x raised to the power y.

param: float $x
param: float $y
return: array|float|int|string The result, or a string containing an error

PRODUCT(...$args)   X-Ref
PRODUCT.

PRODUCT returns the product of all the values and cells referenced in the argument list.

param: mixed ...$args Data values
return: float|string

QUOTIENT($numerator, $denominator)   X-Ref
QUOTIENT.

QUOTIENT function returns the integer portion of a division. Numerator is the divided number
and denominator is the divisor.

param: mixed $numerator
param: mixed $denominator
return: array|int|string

RAND($min = 0, $max = 0)   X-Ref
RAND/RANDBETWEEN.

param: int $min Minimal value
param: int $max Maximal value
return: array|float|int|string Random number

ROMAN($aValue, $style = 0)   X-Ref
ROMAN.

Converts a number to Roman numeral

param: mixed $aValue Number to convert
param: mixed $style Number indicating one of five possible forms
return: array|string Roman numeral, or a string containing an error

ROUNDUP($number, $digits)   X-Ref
ROUNDUP.

Rounds a number up to a specified number of decimal places

param: array|float $number Number to round
param: array|int $digits Number of digits to which you want to round $number
return: array|float|string Rounded Number, or a string containing an error

ROUNDDOWN($number, $digits)   X-Ref
ROUNDDOWN.

Rounds a number down to a specified number of decimal places

param: array|float $number Number to round
param: array|int $digits Number of digits to which you want to round $number
return: array|float|string Rounded Number, or a string containing an error

SERIESSUM($x, $n, $m, ...$args)   X-Ref
SERIESSUM.

Returns the sum of a power series

param: mixed $x Input value
param: mixed $n Initial power
param: mixed $m Step
param: mixed[] $args An array of coefficients for the Data Series
return: array|float|string The result, or a string containing an error

SIGN($number)   X-Ref
SIGN.

Determines the sign of a number. Returns 1 if the number is positive, zero (0)
if the number is 0, and -1 if the number is negative.

param: array|float $number Number to round
return: array|int|string sign value, or a string containing an error

returnSign(float $number)   X-Ref
returnSign = returns 0/-1/+1.


SQRTPI($number)   X-Ref
SQRTPI.

Returns the square root of (number * pi).

param: array|float $number Number
return: array|float|string Square Root of Number * Pi, or a string containing an error

SUBTOTAL($functionType, ...$args)   X-Ref
SUBTOTAL.

Returns a subtotal in a list or database.

param: int $functionType
param: mixed[] $args A mixed data series of values
return: float|string

SUM(...$args)   X-Ref
SUM.

SUM computes the sum of all the values and cells referenced in the argument list.

param: mixed ...$args Data values
return: float|string

SUMIF($range, $criteria, $sumRange = [])   X-Ref
SUMIF.

Totals the values of cells that contain numbers within the list of arguments

Excel Function:
SUMIF(range, criteria, [sum_range])

param: mixed $range Data values
param: string $criteria the criteria that defines which cells will be summed
param: mixed $sumRange
return: float|string

SUMIFS(...$args)   X-Ref
SUMIFS.

Totals the values of cells that contain numbers within the list of arguments

Excel Function:
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

param: mixed $args Data values
return: null|float|string

SUMPRODUCT(...$args)   X-Ref
SUMPRODUCT.

Excel Function:
SUMPRODUCT(value1[,value2[, ...]])

param: mixed ...$args Data values
return: float|string The result, or a string containing an error

SUMSQ(...$args)   X-Ref
SUMSQ.

SUMSQ returns the sum of the squares of the arguments

param: mixed ...$args Data values
return: float|string

SUMX2MY2($matrixData1, $matrixData2)   X-Ref
SUMX2MY2.

param: mixed[] $matrixData1 Matrix #1
param: mixed[] $matrixData2 Matrix #2
return: float|string

SUMX2PY2($matrixData1, $matrixData2)   X-Ref
SUMX2PY2.

param: mixed[] $matrixData1 Matrix #1
param: mixed[] $matrixData2 Matrix #2
return: float|string

SUMXMY2($matrixData1, $matrixData2)   X-Ref
SUMXMY2.

param: mixed[] $matrixData1 Matrix #1
param: mixed[] $matrixData2 Matrix #2
return: float|string

TRUNC($value = 0, $digits = 0)   X-Ref
TRUNC.

Truncates value to the number of fractional digits by number_digits.

param: float $value
param: int $digits
return: array|float|string Truncated value, or a string containing an error

SEC($angle)   X-Ref
SEC.

Returns the secant of an angle.

param: array|float $angle Number
return: array|float|string The secant of the angle

SECH($angle)   X-Ref
SECH.

Returns the hyperbolic secant of an angle.

param: array|float $angle Number
return: array|float|string The hyperbolic secant of the angle

CSC($angle)   X-Ref
CSC.

Returns the cosecant of an angle.

param: array|float $angle Number
return: array|float|string The cosecant of the angle

CSCH($angle)   X-Ref
CSCH.

Returns the hyperbolic cosecant of an angle.

param: array|float $angle Number
return: array|float|string The hyperbolic cosecant of the angle

COT($angle)   X-Ref
COT.

Returns the cotangent of an angle.

param: array|float $angle Number
return: array|float|string The cotangent of the angle

COTH($angle)   X-Ref
COTH.

Returns the hyperbolic cotangent of an angle.

param: array|float $angle Number
return: array|float|string The hyperbolic cotangent of the angle

ACOT($number)   X-Ref
ACOT.

Returns the arccotangent of a number.

param: array|float $number Number
return: array|float|string The arccotangent of the number

numberOrNan($result)   X-Ref
Return NAN or value depending on argument.

param: float $result Number
return: float|string

ACOTH($number)   X-Ref
ACOTH.

Returns the hyperbolic arccotangent of a number.

param: array|float $number Number
return: array|float|string The hyperbolic arccotangent of the number

builtinROUND($number, $precision)   X-Ref
ROUND.

Returns the result of builtin function round after validating args.

param: array|mixed $number Should be numeric
param: array|mixed $precision Should be int
return: array|float|string Rounded number

builtinABS($number)   X-Ref
ABS.

Returns the result of builtin function abs after validating args.

param: array|mixed $number Should be numeric
return: array|float|int|string Rounded number

builtinACOS($number)   X-Ref
ACOS.

param: array|float $number Should be numeric
return: array|float|string Rounded number

builtinACOSH($number)   X-Ref
ACOSH.

Returns the result of builtin function acosh after validating args.

param: array|float $number Should be numeric
return: array|float|string Rounded number

builtinASIN($number)   X-Ref
ASIN.

Returns the result of builtin function asin after validating args.

param: array|float $number Should be numeric
return: array|float|string Rounded number

builtinASINH($number)   X-Ref
ASINH.

Returns the result of builtin function asinh after validating args.

param: array|float $number Should be numeric
return: array|float|string Rounded number

builtinATAN($number)   X-Ref
ATAN.

Returns the result of builtin function atan after validating args.

param: array|float $number Should be numeric
return: array|float|string Rounded number

builtinATANH($number)   X-Ref
ATANH.

Returns the result of builtin function atanh after validating args.

param: array|float $number Should be numeric
return: array|float|string Rounded number

builtinCOS($number)   X-Ref
COS.

Returns the result of builtin function cos after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinCOSH($number)   X-Ref
COSH.

Returns the result of builtin function cos after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinDEGREES($number)   X-Ref
DEGREES.

Returns the result of builtin function rad2deg after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinEXP($number)   X-Ref
EXP.

Returns the result of builtin function exp after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinLN($number)   X-Ref
LN.

Returns the result of builtin function log after validating args.

param: mixed $number Should be numeric
return: array|float|string Rounded number

builtinLOG10($number)   X-Ref
LOG10.

Returns the result of builtin function log after validating args.

param: mixed $number Should be numeric
return: array|float|string Rounded number

builtinRADIANS($number)   X-Ref
RADIANS.

Returns the result of builtin function deg2rad after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinSIN($number)   X-Ref
SIN.

Returns the result of builtin function sin after validating args.

param: array|mixed $number Should be numeric
return: array|float|string sine

builtinSINH($number)   X-Ref
SINH.

Returns the result of builtin function sinh after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinSQRT($number)   X-Ref
SQRT.

Returns the result of builtin function sqrt after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinTAN($number)   X-Ref
TAN.

Returns the result of builtin function tan after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

builtinTANH($number)   X-Ref
TANH.

Returns the result of builtin function sinh after validating args.

param: array|mixed $number Should be numeric
return: array|float|string Rounded number

nullFalseTrueToNumber(&$number)   X-Ref
Many functions accept null/false/true argument treated as 0/0/1.

param: mixed $number