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.
/lib/ -> mathslib.php (source)

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

(no description)

Copyright: Petr Skoda (skodak)
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 143 lines (5 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

calc_formula:: (2 methods):
  __construct()
  calc_formula()

name:: (5 methods):
  set_params()
  evaluate()
  get_error()
  localize()
  unlocalize()


Class: calc_formula  - X-Ref

This class abstracts evaluation of spreadsheet formulas.
See unit tests in lib/tests/mathslib_test.php for sample usage.

__construct($formula, $params=false)   X-Ref
Constructor for spreadsheet formula with optional parameters

param: string $formula with leading =
param: array $params associative array of parameters used in formula. All parameter names must be lowercase!

calc_formula($formula, $params=false)   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

set_params($params)   X-Ref
Raplace parameters used in existing formula,
parameter names must contain only lowercase [a-z] letters, no other characters are allowed!

param: array $params associative array of parameters used in formula

evaluate()   X-Ref
Evaluate formula

return: mixed number if ok, false if error

get_error()   X-Ref
Get last error.
TODO: localize the strings from contructor and EvalMath library

return: mixed string with last error description or false if ok

localize($formula)   X-Ref
Similar to format_float, formats the numbers and list separators
according to locale specifics.

param: string $formula
return: string localised formula

unlocalize($formula)   X-Ref
Similar to unformat_float, converts floats and lists to PHP standards.

param: string $formula localised formula
return: string