ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 @inheritDoc More...
 
 sub ($left_operand, $right_operand, ?int $scale=null)
 @inheritDoc More...
 
 mul ($left_operand, $right_operand, ?int $scale=null)
 @inheritDoc More...
 
 div ($left_operand, $right_operand, ?int $scale=null)
 @inheritDoc More...
 
 mod ($left_operand, $right_operand)
 @inheritDoc More...
 
 pow ($left_operand, $right_operand, ?int $scale=null)
 @inheritDoc More...
 
 sqrt ($operand, ?int $scale=null)
 @inheritDoc More...
 
 comp ($left_operand, $right_operand, ?int $scale=null)
 @inheritDoc More...
 
- Public Member Functions inherited from ilMathBaseAdapter
 applyScale ($left_operand, ?int $scale=null)
 @inheritDoc More...
 
 round ($value, int $precision=0)
 @inheritDoc More...
 
 equals ($left_operand, $right_operand, ?int $scale=null)
 @inheritDoc More...
 
 add ($left_operand, $right_operand, ?int $scale=null)
 Adds two numbers. More...
 
 sub ($left_operand, $right_operand, ?int $scale=null)
 Subtracts two numbers. More...
 
 mul ($left_operand, $right_operand, ?int $scale=null)
 Multiplies two numbers. More...
 
 div ($left_operand, $right_operand, ?int $scale=null)
 Divides two numbers. More...
 
 mod ($left_operand, $right_operand)
 Gets modulus of two numbers. More...
 
 pow ($left_operand, $right_operand, ?int $scale=null)
 Raises a number to another. More...
 
 sqrt ($operand, ?int $scale=null)
 Gets the square root of a number. More...
 
 comp ($left_operand, $right_operand, ?int $scale=null)
 Compares two numbers. More...
 
 equals ($left_operand, $right_operand, ?int $scale=null)
 Checks whether or not two numbers are identical. More...
 
 applyScale ($left_operand, ?int $scale=null)
 This method adapts the behaviour of bcscale() More...
 
 round ($value, int $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)
 

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 
)

@inheritDoc

Implements ilMathAdapter.

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

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

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ comp()

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

@inheritDoc

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 
)

@inheritDoc

Implements ilMathAdapter.

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

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 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ mod()

ilMathBCMathAdapter::mod (   $left_operand,
  $right_operand 
)

@inheritDoc

Implements ilMathAdapter.

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

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 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ mul()

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

@inheritDoc

Implements ilMathAdapter.

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

54 {
55 return bcmul($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
56 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ pow()

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

@inheritDoc

Implements ilMathAdapter.

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

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 }
applyScale($left_operand, ?int $scale=null)
@inheritDoc

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

+ Here is the call graph for this function:

◆ sqrt()

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

@inheritDoc

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 
)

@inheritDoc

Implements ilMathAdapter.

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

46 {
47 return bcsub($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
48 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

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