Class ilMath Wrapper for mathematical operations.
More...
|
static | _add ($left_operand, $right_operand, $scale=50) |
|
static | _div ($left_operand, $right_operand, $scale=50) |
|
static | _mod ($operand, $modulu) |
|
static | _mul ($left_operand, $right_operand, $scale=50) |
|
static | _pow ($left_operand, $right_operand, $scale=50) |
|
static | _sqrt ($operand, $scale=50) |
|
static | _sub ($left_operand, $right_operand, $scale=50) |
|
static | isCoprimeFraction ($numerator, $denominator) |
|
static | getGreatestCommonDivisor ($a, $b) |
|
static | setDefaultAdapter (ilMathAdapter $adapter) |
|
static | getDefaultAdapter () |
|
static | getInstance ($adapter=null) |
|
static | getFirstValidAdapter () |
|
static | __callStatic ($method, $args) |
| Backward compatibility: Map all static calls to an equivalent instance method of the adapter. More...
|
|
◆ __callStatic()
static ilMath::__callStatic |
( |
|
$method, |
|
|
|
$args |
|
) |
| |
|
static |
Backward compatibility: Map all static calls to an equivalent instance method of the adapter.
- Parameters
-
- Returns
- mixed
Definition at line 202 of file class.ilMath.php.
References $adapter.
204 if (strpos($method,
'_') === 0) {
205 $method = substr($method, 1);
208 $adapter = static::getDefaultAdapter();
210 return call_user_func_array([
$adapter, $method], $args);
◆ _add()
static ilMath::_add |
( |
|
$left_operand, |
|
|
|
$right_operand, |
|
|
|
$scale = 50 |
|
) |
| |
|
static |
◆ _div()
static ilMath::_div |
( |
|
$left_operand, |
|
|
|
$right_operand, |
|
|
|
$scale = 50 |
|
) |
| |
|
static |
◆ _mod()
static ilMath::_mod |
( |
|
$operand, |
|
|
|
$modulu |
|
) |
| |
|
static |
- Parameters
-
int | float | $operand | |
int | float | $modulu | |
- Returns
- int
Definition at line 49 of file class.ilMath.php.
References $adapter.
51 $adapter = static::getDefaultAdapter();
53 return $adapter->mod($operand, $modulu);
◆ _mul()
static ilMath::_mul |
( |
|
$left_operand, |
|
|
|
$right_operand, |
|
|
|
$scale = 50 |
|
) |
| |
|
static |
- Parameters
-
int | float | $left_operand | |
int | float | $right_operand | |
int | $scale | |
- Returns
- mixed
Definition at line 62 of file class.ilMath.php.
References $adapter.
Referenced by assFormulaQuestionVariable\getBaseValue(), assFormulaQuestionVariable\getRandomValue(), assFormulaQuestionResult\getRangeMaxBase(), assFormulaQuestionResult\getRangeMinBase(), assFormulaQuestionResult\getReachedPoints(), assFormulaQuestionResult\getResultInfo(), assFormulaQuestionResult\isCorrect(), assFormulaQuestionResult\isInTolerance(), EvalMath\pfx(), and assFormulaQuestionResult\suggestRange().
64 $adapter = static::getDefaultAdapter();
66 return $adapter->mul($left_operand, $right_operand, $scale);
◆ _pow()
static ilMath::_pow |
( |
|
$left_operand, |
|
|
|
$right_operand, |
|
|
|
$scale = 50 |
|
) |
| |
|
static |
◆ _sqrt()
static ilMath::_sqrt |
( |
|
$operand, |
|
|
|
$scale = 50 |
|
) |
| |
|
static |
◆ _sub()
static ilMath::_sub |
( |
|
$left_operand, |
|
|
|
$right_operand, |
|
|
|
$scale = 50 |
|
) |
| |
|
static |
◆ getDefaultAdapter()
static ilMath::getDefaultAdapter |
( |
| ) |
|
|
static |
- Returns
- ilMathAdapter
Definition at line 139 of file class.ilMath.php.
141 if (null === static::$default_adapter) {
142 static::$default_adapter = static::getFirstValidAdapter();
145 return static::$default_adapter;
◆ getFirstValidAdapter()
static ilMath::getFirstValidAdapter |
( |
| ) |
|
|
static |
- Returns
- ilMathAdapter
Definition at line 187 of file class.ilMath.php.
189 if (extension_loaded(
'bcmath')) {
190 return static::getInstance(
'BCMath');
193 return static::getInstance(
'Php');
◆ getGreatestCommonDivisor()
static ilMath::getGreatestCommonDivisor |
( |
|
$a, |
|
|
|
$b |
|
) |
| |
|
static |
◆ getInstance()
static ilMath::getInstance |
( |
|
$adapter = null | ) |
|
|
static |
- Parameters
-
- Returns
- ilMathAdapter
- Exceptions
-
Definition at line 153 of file class.ilMath.php.
References $adapter.
156 return static::getFirstValidAdapter();
159 $class_name =
'ilMath' .
$adapter .
'Adapter';
160 $path_to_class = realpath(
'Services/Math/classes/class.' . $class_name .
'.php');
162 if (!is_file($path_to_class) || !is_readable($path_to_class)) {
163 require_once
'Services/Math/exceptions/class.ilMathException.php';
165 'The math adapter %s is not valid, please refer to a class implementing %s',
171 require_once $path_to_class;
172 if (!class_exists($class_name) || !is_subclass_of($class_name, ilMathAdapter::class)) {
173 require_once
'Services/Math/exceptions/class.ilMathException.php';
175 'The math adapter class %s is not valid, please refer to a class implementing %s',
181 return new $class_name();
◆ isCoprimeFraction()
static ilMath::isCoprimeFraction |
( |
|
$numerator, |
|
|
|
$denominator |
|
) |
| |
|
static |
Definition at line 107 of file class.ilMath.php.
109 $gcd = self::getGreatestCommonDivisor(abs($numerator), abs($denominator));
111 return $gcd == 1 ? true :
false;
◆ setDefaultAdapter()
◆ $default_adapter
ilMath::$default_adapter = null |
|
staticprotected |
The documentation for this class was generated from the following file: