ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMath Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilMath:

Static Public Member Functions

static _add ($left_operand, $right_operand, int $scale=50)
 
static _div ($left_operand, $right_operand, int $scale=50)
 
static _mod ($operand, $modulu)
 
static _mul ($left_operand, $right_operand, int $scale=50)
 
static _pow ($left_operand, $right_operand, int $scale=50)
 
static _sqrt ($operand, int $scale=50)
 
static _sub ($left_operand, $right_operand, int $scale=50)
 
static isCoprimeFraction ($numerator, $denominator)
 
static getGreatestCommonDivisor ($a, $b)
 
static setDefaultAdapter (ilMathAdapter $adapter)
 
static getDefaultAdapter ()
 
static getInstance (?string $adapter=null)
 
static getFirstValidAdapter ()
 
static __callStatic (string $method, $args)
 Backward compatibility: Map all static calls to an equivalent instance method of the adapter. More...
 

Static Protected Attributes

static ilMathAdapter $default_adapter = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning static _round(mixed $value, int $precision) : string static _equals(mixed $left_operand, mixed $right_operand, int $scale = null) : bool

Definition at line 23 of file class.ilMath.php.

Member Function Documentation

◆ __callStatic()

static ilMath::__callStatic ( string  $method,
  $args 
)
static

Backward compatibility: Map all static calls to an equivalent instance method of the adapter.

Parameters
string$method
mixed$args
Returns
mixed

Definition at line 184 of file class.ilMath.php.

185  {
186  if (strpos($method, '_') === 0) {
187  $method = substr($method, 1);
188  }
189 
190  $adapter = static::getDefaultAdapter();
191 
192  return call_user_func_array([$adapter, $method], $args);
193  }

◆ _add()

static ilMath::_add (   $left_operand,
  $right_operand,
int  $scale = 50 
)
static
Parameters
int | float$left_operand
int | float$right_operand
Returns
mixed

Definition at line 32 of file class.ilMath.php.

Referenced by assFormulaQuestionVariable\getRandomValue(), assFormulaQuestionResult\isInTolerance(), and EvalMath\pfx().

33  {
34  return static::getDefaultAdapter()->add($left_operand, $right_operand, $scale);
35  }
+ Here is the caller graph for this function:

◆ _div()

static ilMath::_div (   $left_operand,
  $right_operand,
int  $scale = 50 
)
static
Parameters
int | float$left_operand
int | float$right_operand
Returns
mixed
Exceptions
ilMathDivisionByZeroException

Definition at line 43 of file class.ilMath.php.

Referenced by assFormulaQuestionResult\calculateFormula(), assFormulaQuestion\getBestSolution(), assFormulaQuestionVariable\getRandomValue(), assFormulaQuestionResult\getReachedPoints(), assFormulaQuestionResult\isCorrect(), assFormulaQuestionResult\isInTolerance(), EvalMath\pfx(), and assFormulaQuestionResult\suggestRange().

44  {
45  return static::getDefaultAdapter()->div($left_operand, $right_operand, $scale);
46  }
+ Here is the caller graph for this function:

◆ _mod()

static ilMath::_mod (   $operand,
  $modulu 
)
static
Parameters
int | float$operand
int | float$modulu
Exceptions
ilMathDivisionByZeroException

Definition at line 53 of file class.ilMath.php.

53  : int
54  {
55  return static::getDefaultAdapter()->mod($operand, $modulu);
56  }

◆ _mul()

static ilMath::_mul (   $left_operand,
  $right_operand,
int  $scale = 50 
)
static
Parameters
int | float$left_operand
int | float$right_operand
Returns
mixed

Definition at line 63 of file class.ilMath.php.

Referenced by assFormulaQuestionVariable\getBaseValue(), assFormulaQuestionVariable\getRandomValue(), assFormulaQuestionResult\getRangeMaxBase(), assFormulaQuestionResult\getRangeMinBase(), assFormulaQuestionResult\getReachedPoints(), assFormulaQuestionResult\getResultInfo(), assFormulaQuestionResult\isCorrect(), assFormulaQuestionResult\isInTolerance(), EvalMath\pfx(), and assFormulaQuestionResult\suggestRange().

64  {
65  return static::getDefaultAdapter()->mul($left_operand, $right_operand, $scale);
66  }
+ Here is the caller graph for this function:

◆ _pow()

static ilMath::_pow (   $left_operand,
  $right_operand,
int  $scale = 50 
)
static
Parameters
int | float$left_operand
int | float$right_operand
Returns
mixed

Definition at line 73 of file class.ilMath.php.

Referenced by assFormulaQuestionVariable\getRandomValue(), and EvalMath\pfx().

74  {
75  return static::getDefaultAdapter()->pow($left_operand, $right_operand, $scale);
76  }
+ Here is the caller graph for this function:

◆ _sqrt()

static ilMath::_sqrt (   $operand,
int  $scale = 50 
)
static
Parameters
int | float$operand
Returns
mixed

Definition at line 82 of file class.ilMath.php.

83  {
84  return static::getDefaultAdapter()->sqrt($operand, $scale);
85  }

◆ _sub()

static ilMath::_sub (   $left_operand,
  $right_operand,
int  $scale = 50 
)
static
Parameters
int | float$left_operand
int | float$right_operand
Returns
mixed

Definition at line 92 of file class.ilMath.php.

Referenced by assFormulaQuestionVariable\getRandomValue(), assFormulaQuestionResult\isInTolerance(), and EvalMath\pfx().

93  {
94  return static::getDefaultAdapter()->sub($left_operand, $right_operand, $scale);
95  }
+ Here is the caller graph for this function:

◆ getDefaultAdapter()

static ilMath::getDefaultAdapter ( )
static

Definition at line 127 of file class.ilMath.php.

References null.

127  : ilMathAdapter
128  {
129  if (null === static::$default_adapter) {
130  static::$default_adapter = static::getFirstValidAdapter();
131  }
132 
133  return static::$default_adapter;
134  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getFirstValidAdapter()

static ilMath::getFirstValidAdapter ( )
static
Exceptions
ilMathException

Definition at line 169 of file class.ilMath.php.

169  : ilMathAdapter
170  {
171  if (extension_loaded('bcmath')) {
172  return static::getInstance('BCMath');
173  }
174 
175  return static::getInstance('Php');
176  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getGreatestCommonDivisor()

static ilMath::getGreatestCommonDivisor (   $a,
  $b 
)
static
Parameters
int | float$a
int | float$b
Returns
int|float

Definition at line 113 of file class.ilMath.php.

References Vendor\Package\$a, and Vendor\Package\$b.

Referenced by ilMathTest\testGcd().

114  {
115  if ($b > 0) {
116  return self::getGreatestCommonDivisor($b, $a % $b);
117  }
118 
119  return $a;
120  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the caller graph for this function:

◆ getInstance()

static ilMath::getInstance ( ?string  $adapter = null)
static
Exceptions
ilMathException

Definition at line 139 of file class.ilMath.php.

References null.

140  {
141  if (null === $adapter) {
142  return static::getFirstValidAdapter();
143  }
144 
145  $class_name = 'ilMath' . $adapter . 'Adapter';
146  $path_to_class = __DIR__ . '/class.' . $class_name . '.php';
147 
148  if (!is_file($path_to_class) || !is_readable($path_to_class)) {
149  throw new ilMathException(sprintf(
150  'The math adapter %s is not valid, please refer to a class implementing %s',
151  $adapter,
152  ilMathAdapter::class
153  ));
154  }
155  if (!class_exists($class_name) || !is_subclass_of($class_name, ilMathAdapter::class)) {
156  throw new ilMathException(sprintf(
157  'The math adapter class %s is not valid, please refer to a class implementing %s',
158  $class_name,
159  ilMathAdapter::class
160  ));
161  }
162 
163  return new $class_name();
164  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMathException.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ isCoprimeFraction()

static ilMath::isCoprimeFraction (   $numerator,
  $denominator 
)
static
Parameters
int | float$numerator
int | float$denominator

Definition at line 101 of file class.ilMath.php.

101  : bool
102  {
103  $gcd = self::getGreatestCommonDivisor(abs($numerator), abs($denominator));
104 
105  return $gcd == 1;
106  }

◆ setDefaultAdapter()

static ilMath::setDefaultAdapter ( ilMathAdapter  $adapter)
static

Definition at line 122 of file class.ilMath.php.

Referenced by ilMathBaseAdapterTestCase\setUp().

122  : void
123  {
124  static::$default_adapter = $adapter;
125  }
+ Here is the caller graph for this function:

Field Documentation

◆ $default_adapter

ilMathAdapter ilMath::$default_adapter = null
staticprotected

Definition at line 25 of file class.ilMath.php.


The documentation for this class was generated from the following file: