ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMath Class Reference

Class ilMath Wrapper for mathematical operations. More...

+ Collaboration diagram for ilMath:

Static Public Member Functions

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...
 

Static Protected Attributes

static $default_adapter = null
 

Detailed Description

Class ilMath Wrapper for mathematical operations.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de $Id$

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

Member Function Documentation

◆ __callStatic()

static ilMath::__callStatic (   $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 202 of file class.ilMath.php.

203 {
204 if (strpos($method, '_') === 0) {
205 $method = substr($method, 1);
206 }
207
208 $adapter = static::getDefaultAdapter();
209
210 return call_user_func_array([$adapter, $method], $args);
211 }

References $adapter.

◆ _add()

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

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

25 {
26 $adapter = static::getDefaultAdapter();
27
28 return $adapter->add($left_operand, $right_operand, $scale);
29 }

References $adapter.

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

+ Here is the caller graph for this function:

◆ _div()

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

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

38 {
39 $adapter = static::getDefaultAdapter();
40
41 return $adapter->div($left_operand, $right_operand, $scale);
42 }

References $adapter.

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

+ Here is the caller graph for this function:

◆ _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.

50 {
51 $adapter = static::getDefaultAdapter();
52
53 return $adapter->mod($operand, $modulu);
54 }

References $adapter.

◆ _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.

63 {
64 $adapter = static::getDefaultAdapter();
65
66 return $adapter->mul($left_operand, $right_operand, $scale);
67 }

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().

+ Here is the caller graph for this function:

◆ _pow()

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

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

76 {
77 $adapter = static::getDefaultAdapter();
78
79 return $adapter->pow($left_operand, $right_operand, $scale);
80 }

References $adapter.

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

+ Here is the caller graph for this function:

◆ _sqrt()

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

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

88 {
89 $adapter = static::getDefaultAdapter();
90
91 return $adapter->sqrt($operand, $scale);
92 }

References $adapter.

◆ _sub()

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

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

101 {
102 $adapter = static::getDefaultAdapter();
103
104 return $adapter->sub($left_operand, $right_operand, $scale);
105 }

References $adapter.

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

+ Here is the caller graph for this function:

◆ getDefaultAdapter()

static ilMath::getDefaultAdapter ( )
static
Returns
ilMathAdapter

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

140 {
141 if (null === static::$default_adapter) {
142 static::$default_adapter = static::getFirstValidAdapter();
143 }
144
145 return static::$default_adapter;
146 }

◆ getFirstValidAdapter()

static ilMath::getFirstValidAdapter ( )
static
Returns
ilMathAdapter

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

188 {
189 if (extension_loaded('bcmath')) {
190 return static::getInstance('BCMath');
191 }
192
193 return static::getInstance('Php');
194 }

◆ getGreatestCommonDivisor()

static ilMath::getGreatestCommonDivisor (   $a,
  $b 
)
static
Parameters
mixed$a
mixed$b
Returns
mixed

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

120 {
121 if ($b > 0) {
122 return self::getGreatestCommonDivisor($b, $a % $b);
123 } else {
124 return $a;
125 }
126 }
static getGreatestCommonDivisor($a, $b)

References getGreatestCommonDivisor().

Referenced by getGreatestCommonDivisor(), isCoprimeFraction(), and ilMathTest\testGcd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstance()

static ilMath::getInstance (   $adapter = null)
static
Parameters
null | string$adapter
Returns
ilMathAdapter
Exceptions
ilMathException

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

154 {
155 if (null === $adapter) {
156 return static::getFirstValidAdapter();
157 }
158
159 $class_name = 'ilMath' . $adapter . 'Adapter';
160 $path_to_class = realpath('Services/Math/classes/class.' . $class_name . '.php');
161
162 if (!is_file($path_to_class) || !is_readable($path_to_class)) {
163 require_once 'Services/Math/exceptions/class.ilMathException.php';
164 throw new ilMathException(sprintf(
165 'The math adapter %s is not valid, please refer to a class implementing %s',
166 $adapter,
167 ilMathAdapter::class
168 ));
169 }
170
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';
174 throw new ilMathException(sprintf(
175 'The math adapter class %s is not valid, please refer to a class implementing %s',
176 $class_name,
177 ilMathAdapter::class
178 ));
179 }
180
181 return new $class_name();
182 }
sprintf('%.4f', $callTime)
Class ilMathException.

References $adapter, and sprintf.

◆ isCoprimeFraction()

static ilMath::isCoprimeFraction (   $numerator,
  $denominator 
)
static

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

108 {
109 $gcd = self::getGreatestCommonDivisor(abs($numerator), abs($denominator));
110
111 return $gcd == 1 ? true : false;
112 }

References getGreatestCommonDivisor().

+ Here is the call graph for this function:

◆ setDefaultAdapter()

static ilMath::setDefaultAdapter ( ilMathAdapter  $adapter)
static
Parameters
ilMathAdapter$adapter

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

132 {
133 static::$default_adapter = $adapter;
134 }

References $adapter.

Referenced by ilMathBaseAdapterTest\setUp().

+ Here is the caller graph for this function:

Field Documentation

◆ $default_adapter

ilMath::$default_adapter = null
staticprotected

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


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