ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMathBCMathAdapter 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 ilMathBCMathAdapter:
+ Collaboration diagram for ilMathBCMathAdapter:

Public Member Functions

 __construct ($scale=0)
 ilMathBcMathAdapter constructor. More...
 
 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)
 

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 ilMathBCMathAdapter

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

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

Constructor & Destructor Documentation

◆ __construct()

ilMathBCMathAdapter::__construct (   $scale = 0)

ilMathBcMathAdapter constructor.

Parameters
int$scale

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

30  {
31  bcscale($scale);
32  }

Member Function Documentation

◆ add()

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

Implements ilMathAdapter.

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

References ilMathBaseAdapter\normalize().

38  {
39  return bcadd($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
40  }
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
+ Here is the call graph for this function:

◆ comp()

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

Implements ilMathAdapter.

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

116  : int
117  {
118  return bccomp($left_operand, $right_operand, $scale);
119  }

◆ div()

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

Implements ilMathAdapter.

Definition at line 61 of file class.ilMathBCMathAdapter.php.

References ilMathBaseAdapter\normalize().

62  {
63  if ($right_operand == 0) {
64  throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
65  }
66 
67  return bcdiv($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
68  }
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
+ Here is the call graph for this function:

◆ mod()

ilMathBCMathAdapter::mod (   $left_operand,
  $right_operand 
)

Implements ilMathAdapter.

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

References ilMathBaseAdapter\normalize().

74  {
75  if ($right_operand == 0) {
76  throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
77  }
78 
79  return bcmod($this->normalize($left_operand), $this->normalize($right_operand));
80  }
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
+ Here is the call graph for this function:

◆ mul()

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

Implements ilMathAdapter.

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

References ilMathBaseAdapter\normalize().

54  {
55  return bcmul($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
56  }
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
+ Here is the call graph for this function:

◆ pow()

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

Implements ilMathAdapter.

Definition at line 85 of file class.ilMathBCMathAdapter.php.

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

86  {
87  $left_operand = $this->normalize($left_operand);
88  $right_operand = $this->normalize($right_operand);
89  $scale = $this->normalize($scale);
90 
91  // bcpow() only supports exponents less than or equal to 2^31-1.
92  // Also, bcpow() does not support decimal numbers.
93  // If you have scale set to 0, then the exponent is converted to an integer; otherwise an error is generated.
94  $left_operand_dec = $this->exp2dec($left_operand);
95  $right_operand_dec = $this->exp2dec($right_operand);
96 
97  // bcpow does NOT support decimal exponents
98  if (strpos($right_operand_dec, '.') === false) {
99  return bcpow($left_operand_dec, $right_operand_dec, $scale);
100  }
101 
102  return $this->applyScale($left_operand ** $right_operand, $scale);
103  }
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()

ilMathBCMathAdapter::sqrt (   $operand,
?int  $scale = null 
)

Implements ilMathAdapter.

Definition at line 108 of file class.ilMathBCMathAdapter.php.

109  {
110  return bcsqrt($operand, $scale);
111  }

◆ sub()

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

Implements ilMathAdapter.

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

References ilMathBaseAdapter\normalize().

46  {
47  return bcsub($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
48  }
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
+ Here is the call graph for this function:

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