ILIAS  release_7 Revision v7.30-3-g800a261c036
ilMathPhpAdapter Class Reference

Class ilMathPhpAdapter. More...

+ Inheritance diagram for ilMathPhpAdapter:
+ Collaboration diagram for ilMathPhpAdapter:

Public Member Functions

 add ($left_operand, $right_operand, $scale=null)
 {Adds two numbers.
Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
} More...
 
 sub ($left_operand, $right_operand, $scale=null)
 {Subtracts two numbers.
Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
} More...
 
 mul ($left_operand, $right_operand, $scale=null)
 {Multiplies two numbers.
Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
} More...
 
 div ($left_operand, $right_operand, $scale=null)
 {Divides two numbers.
Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
Exceptions
ilMathDivisionByZeroException
} More...
 
 mod ($left_operand, $right_operand)
 {Gets modulus of two numbers.
Parameters
mixed$left_operand
mixed$right_operand
Returns
mixed
Exceptions
ilMathDivisionByZeroException
} More...
 
 pow ($left_operand, $right_operand, $scale=null)
 {Raises a number to another.
Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
} More...
 
 sqrt ($operand, $scale=null)
 {Gets the square root of a number.
Parameters
mixed$operand
int$scale
Returns
mixed
} More...
 
 comp ($left_operand, $right_operand, $scale=null)
 {Compares two numbers.
Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
} More...
 
- Public Member Functions inherited from ilMathBaseAdapter
 applyScale ($number, $scale=null)
 This method adapts the behaviour of bcscale() More...
 
 round ($value, $precision=0)
 
Parameters
mixed$value
int$precision
Returns
string
More...
 
 equals ($left_operand, $right_operand, $scale=null)
 {Checks whether or not two numbers are identical.
Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
bool
} More...
 
 add ($left_operand, $right_operand, $scale=null)
 Adds two numbers. More...
 
 sub ($left_operand, $right_operand, $scale=null)
 Subtracts two numbers. More...
 
 mul ($left_operand, $right_operand, $scale=null)
 Multiplies two numbers. More...
 
 div ($left_operand, $right_operand, $scale=null)
 Divides two numbers. More...
 
 mod ($left_operand, $right_operand)
 Gets modulus of two numbers. More...
 
 pow ($left_operand, $right_operand, $scale=null)
 Raises a number to another. More...
 
 sqrt ($operand, $scale=null)
 Gets the square root of a number. More...
 
 comp ($left_operand, $right_operand, $scale=null)
 Compares two numbers. More...
 
 equals ($left_operand, $right_operand, $scale=null)
 Checks whether or not two numbers are identical. More...
 
 applyScale ($left_operand, $scale=null)
 
 round ($value, $precision=0)
 

Additional Inherited Members

- Protected Member Functions inherited from ilMathBaseAdapter
 normalize ($number)
 This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings. More...
 
 exp2dec ($float_str)
 Moved from ilMath... Converts numbers in the form "1.5e4" into decimal notation. More...
 

Detailed Description

Class ilMathPhpAdapter.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 10 of file class.ilMathPhpAdapter.php.

Member Function Documentation

◆ add()

ilMathPhpAdapter::add (   $left_operand,
  $right_operand,
  $scale = null 
)

{Adds two numbers.

Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
}

Implements ilMathAdapter.

Definition at line 15 of file class.ilMathPhpAdapter.php.

16 {
17 $res = $this->normalize($left_operand) + $this->normalize($right_operand);
18
19 return $this->applyScale($res, $this->normalize($scale));
20 }
applyScale($number, $scale=null)
This method adapts the behaviour of bcscale()
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example,...
foreach($_POST as $key=> $value) $res

References $res, ilMathBaseAdapter\applyScale(), and ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ comp()

ilMathPhpAdapter::comp (   $left_operand,
  $right_operand,
  $scale = null 
)

{Compares two numbers.

Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
}

Implements ilMathAdapter.

Definition at line 116 of file class.ilMathPhpAdapter.php.

117 {
118 $left_operand = $this->normalize($left_operand);
119 $right_operand = $this->normalize($right_operand);
120 $scale = $this->normalize($scale);
121
122 if (is_numeric($scale)) {
123 $left_operand = $this->applyScale($left_operand, $scale);
124 $right_operand = $this->applyScale($right_operand, $scale);
125 }
126
127 if ($left_operand == $right_operand) {
128 return 0;
129 } elseif ($left_operand > $right_operand) {
130 return 1;
131 } else {
132 return -1;
133 }
134 }

References ilMathBaseAdapter\applyScale(), and ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ div()

ilMathPhpAdapter::div (   $left_operand,
  $right_operand,
  $scale = null 
)

{Divides two numbers.

Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
Exceptions
ilMathDivisionByZeroException
}

Implements ilMathAdapter.

Definition at line 55 of file class.ilMathPhpAdapter.php.

56 {
57 if ($right_operand == 0) {
58 require_once 'Services/Math/exceptions/class.ilMathDivisionByZeroException.php';
59 throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
60 }
61
62 // This ensures the old PHP <= 7.0.x behaviour, see: #27785 / #26361
63 try {
64 $res = $this->normalize($left_operand) / $this->normalize($right_operand);
65
66 $division = $this->applyScale($res, $this->normalize($scale));
67 } catch (Throwable $e) {
68 if (strpos($e->getMessage(), 'A non-numeric value encountered') !== false) {
69 $division = 0;
70 } else {
71 throw $e;
72 }
73 }
74
75 return $division;
76 }

References Vendor\Package\$e, $res, ilMathBaseAdapter\applyScale(), and ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ mod()

ilMathPhpAdapter::mod (   $left_operand,
  $right_operand 
)

{Gets modulus of two numbers.

Parameters
mixed$left_operand
mixed$right_operand
Returns
mixed
Exceptions
ilMathDivisionByZeroException
}

Implements ilMathAdapter.

Definition at line 81 of file class.ilMathPhpAdapter.php.

82 {
83 if ($right_operand == 0) {
84 require_once 'Services/Math/exceptions/class.ilMathDivisionByZeroException.php';
85 throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
86 }
87
88 $res = $this->normalize($left_operand) % $this->normalize($right_operand);
89
90 return $res;
91 }

References $res, and ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ mul()

ilMathPhpAdapter::mul (   $left_operand,
  $right_operand,
  $scale = null 
)

{Multiplies two numbers.

Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
}

Implements ilMathAdapter.

Definition at line 35 of file class.ilMathPhpAdapter.php.

36 {
37 try {
38 $res = $this->normalize($left_operand) * $this->normalize($right_operand);
39
40 $multiplication = $this->applyScale($res, $this->normalize($scale));
41 } catch (Throwable $e) {
42 if (strpos($e->getMessage(), 'A non-numeric value encountered') !== false) {
43 $multiplication = 0;
44 } else {
45 throw $e;
46 }
47 }
48
49 return $multiplication;
50 }

References Vendor\Package\$e, $res, ilMathBaseAdapter\applyScale(), and ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ pow()

ilMathPhpAdapter::pow (   $left_operand,
  $right_operand,
  $scale = null 
)

{Raises a number to another.

Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
}

Implements ilMathAdapter.

Definition at line 96 of file class.ilMathPhpAdapter.php.

97 {
98 $res = pow($this->normalize($left_operand), $this->normalize($right_operand));
99
100 return $this->applyScale($res, $this->normalize($scale));
101 }
pow($left_operand, $right_operand, $scale=null)
{Raises a number to another.mixed}

References $res, ilMathBaseAdapter\applyScale(), ilMathBaseAdapter\normalize(), and pow().

Referenced by pow().

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

◆ sqrt()

ilMathPhpAdapter::sqrt (   $operand,
  $scale = null 
)

{Gets the square root of a number.

Parameters
mixed$operand
int$scale
Returns
mixed
}

Implements ilMathAdapter.

Definition at line 106 of file class.ilMathPhpAdapter.php.

107 {
108 $res = sqrt($this->normalize($operand));
109
110 return $this->applyScale($res, $this->normalize($scale));
111 }
sqrt($operand, $scale=null)
{Gets the square root of a number.mixed}

References $res, ilMathBaseAdapter\applyScale(), ilMathBaseAdapter\normalize(), and sqrt().

Referenced by sqrt().

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

◆ sub()

ilMathPhpAdapter::sub (   $left_operand,
  $right_operand,
  $scale = null 
)

{Subtracts two numbers.

Parameters
mixed$left_operand
mixed$right_operand
int$scale
Returns
mixed
}

Implements ilMathAdapter.

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

26 {
27 $res = $this->normalize($left_operand) - $this->normalize($right_operand);
28
29 return $this->applyScale($res, $this->normalize($scale));
30 }

References $res, ilMathBaseAdapter\applyScale(), and ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

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