ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMathPhpAdapter Class Reference

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

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

Public Member Functions

 add ($left_operand, $right_operand, int $scale=null)
 
 sub ($left_operand, $right_operand, int $scale=null)
 
 mul ($left_operand, $right_operand, int $scale=null)
 
 div ($left_operand, $right_operand, int $scale=null)
 
 mod ($left_operand, $right_operand)
 
 pow ($left_operand, $right_operand, int $scale=null)
 
 sqrt ($operand, int $scale=null)
 
 comp ($left_operand, $right_operand, int $scale=null)
 
- Public Member Functions inherited from ilMathBaseAdapter
 applyScale ($left_operand, int $scale=null)
 
 round ($value, int $precision=0)
 
 equals ($left_operand, $right_operand, int $scale=null)
 

Private Member Functions

 transformToNumeric (?string $operand)
 

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)
 

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 Class ilMathPhpAdapter

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

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

Member Function Documentation

◆ add()

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

Implements ilMathAdapter.

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

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

46  {
47  $res = $this->normalize($left_operand) + $this->normalize($right_operand);
48 
49  return $this->applyScale($res, $this->normalize($scale));
50  }
$res
Definition: ltiservices.php:69
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
applyScale($left_operand, int $scale=null)
+ Here is the call graph for this function:

◆ comp()

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

Implements ilMathAdapter.

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

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

155  {
156  $left_operand = $this->normalize($left_operand);
157  $right_operand = $this->normalize($right_operand);
158  $scale = $this->normalize($scale);
159 
160  if (is_numeric($scale)) {
161  $left_operand = $this->applyScale($left_operand, $scale);
162  $right_operand = $this->applyScale($right_operand, $scale);
163  }
164 
165  if ($left_operand == $right_operand) {
166  return 0;
167  }
168 
169  if ($left_operand > $right_operand) {
170  return 1;
171  }
172 
173  return -1;
174  }
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
applyScale($left_operand, int $scale=null)
+ Here is the call graph for this function:

◆ div()

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

Implements ilMathAdapter.

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

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

92  {
93  if ($right_operand == 0) {
94  throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
95  }
96 
97  // This ensures the old PHP <= 7.0.x behaviour, see: #27785 / #26361
98  try {
99  $left_operand = $this->normalize($left_operand);
100  $right_operand = $this->normalize($right_operand);
101 
102  $left_operand = $this->transformToNumeric($left_operand);
103  $right_operand = $this->transformToNumeric($right_operand);
104 
105  $res = $left_operand / $right_operand;
106 
107  $division = $this->applyScale($res, $this->normalize($scale));
108  } catch (Throwable $e) {
109  if (strpos($e->getMessage(), 'A non-numeric value encountered') !== false) {
110  $division = 0;
111  } else {
112  throw $e;
113  }
114  }
115 
116  return $division;
117  }
$res
Definition: ltiservices.php:69
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
applyScale($left_operand, int $scale=null)
transformToNumeric(?string $operand)
+ Here is the call graph for this function:

◆ mod()

ilMathPhpAdapter::mod (   $left_operand,
  $right_operand 
)

Implements ilMathAdapter.

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

References ilMathBaseAdapter\normalize().

122  : int
123  {
124  if ($right_operand == 0) {
125  throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
126  }
127 
128  return $this->normalize($left_operand) % $this->normalize($right_operand);
129  }
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ mul()

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

Implements ilMathAdapter.

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

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

66  {
67  try {
68  $left_operand = $this->normalize($left_operand);
69  $right_operand = $this->normalize($right_operand);
70 
71  $left_operand = $this->transformToNumeric($left_operand);
72  $right_operand = $this->transformToNumeric($right_operand);
73 
74  $res = $left_operand * $right_operand;
75 
76  $multiplication = $this->applyScale($res, $this->normalize($scale));
77  } catch (Throwable $e) {
78  if (strpos($e->getMessage(), 'A non-numeric value encountered') !== false) {
79  $multiplication = 0;
80  } else {
81  throw $e;
82  }
83  }
84 
85  return $multiplication;
86  }
$res
Definition: ltiservices.php:69
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
applyScale($left_operand, int $scale=null)
transformToNumeric(?string $operand)
+ Here is the call graph for this function:

◆ pow()

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

Implements ilMathAdapter.

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

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

135  {
136  $res = pow($this->normalize($left_operand), $this->normalize($right_operand));
137 
138  return $this->applyScale($res, $this->normalize($scale));
139  }
$res
Definition: ltiservices.php:69
pow($left_operand, $right_operand, int $scale=null)
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
applyScale($left_operand, int $scale=null)
+ Here is the call graph for this function:

◆ sqrt()

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

Implements ilMathAdapter.

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

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

145  {
146  $res = sqrt($this->normalize($operand));
147 
148  return $this->applyScale($res, $this->normalize($scale));
149  }
$res
Definition: ltiservices.php:69
sqrt($operand, int $scale=null)
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
applyScale($left_operand, int $scale=null)
+ Here is the call graph for this function:

◆ sub()

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

Implements ilMathAdapter.

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

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

56  {
57  $res = $this->normalize($left_operand) - $this->normalize($right_operand);
58 
59  return $this->applyScale($res, $this->normalize($scale));
60  }
$res
Definition: ltiservices.php:69
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
applyScale($left_operand, int $scale=null)
+ Here is the call graph for this function:

◆ transformToNumeric()

ilMathPhpAdapter::transformToNumeric ( ?string  $operand)
private
Parameters
string | null$operand
Returns
float|int|string|null

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

References ILIAS\Repository\int().

Referenced by div(), and mul().

30  {
31  if (is_string($operand)) {
32  if (strpos($operand, '.') !== false) {
33  $operand = (float) $operand;
34  } else {
35  $operand = (int) $operand;
36  }
37  }
38 
39  return $operand;
40  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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