24 public static function _add($left_operand, $right_operand, $scale = 50)
26 $adapter = static::getDefaultAdapter();
28 return $adapter->add($left_operand, $right_operand, $scale);
37 public static function _div($left_operand, $right_operand, $scale = 50)
39 $adapter = static::getDefaultAdapter();
41 return $adapter->div($left_operand, $right_operand, $scale);
49 public static function _mod($operand, $modulu)
51 $adapter = static::getDefaultAdapter();
53 return $adapter->mod($operand, $modulu);
62 public static function _mul($left_operand, $right_operand, $scale = 50)
64 $adapter = static::getDefaultAdapter();
66 return $adapter->mul($left_operand, $right_operand, $scale);
75 public static function _pow($left_operand, $right_operand, $scale = 50)
77 $adapter = static::getDefaultAdapter();
79 return $adapter->pow($left_operand, $right_operand, $scale);
87 public static function _sqrt($operand, $scale = 50)
89 $adapter = static::getDefaultAdapter();
91 return $adapter->sqrt($operand, $scale);
100 public static function _sub($left_operand, $right_operand, $scale = 50)
102 $adapter = static::getDefaultAdapter();
104 return $adapter->sub($left_operand, $right_operand, $scale);
109 $gcd = self::getGreatestCommonDivisor(abs($numerator), abs($denominator));
111 return $gcd == 1 ? true :
false;
122 return self::getGreatestCommonDivisor($b, $a % $b);
133 static::$default_adapter =
$adapter;
141 if (null === static::$default_adapter) {
142 static::$default_adapter = static::getFirstValidAdapter();
145 return static::$default_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();
189 if (extension_loaded(
'bcmath')) {
190 return static::getInstance(
'BCMath');
193 return static::getInstance(
'Php');
204 if (strpos($method,
'_') === 0) {
205 $method = substr($method, 1);
208 $adapter = static::getDefaultAdapter();
210 return call_user_func_array([
$adapter, $method], $args);
Class ilMath Wrapper for mathematical operations.
static _mod($operand, $modulu)
static _div($left_operand, $right_operand, $scale=50)
static _pow($left_operand, $right_operand, $scale=50)
static getInstance($adapter=null)
static isCoprimeFraction($numerator, $denominator)
static _add($left_operand, $right_operand, $scale=50)
static getFirstValidAdapter()
static __callStatic($method, $args)
Backward compatibility: Map all static calls to an equivalent instance method of the adapter...
static setDefaultAdapter(ilMathAdapter $adapter)
static _mul($left_operand, $right_operand, $scale=50)
static getDefaultAdapter()
static _sub($left_operand, $right_operand, $scale=50)
static getGreatestCommonDivisor($a, $b)
static _sqrt($operand, $scale=50)