ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilMathBCMathAdapter Class Reference

Class ilMathBCMathAdapter. More...

+ Inheritance diagram for ilMathBCMathAdapter:
+ Collaboration diagram for ilMathBCMathAdapter:

Public Member Functions

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

Constructor & Destructor Documentation

◆ __construct()

ilMathBCMathAdapter::__construct (   $scale = 0)

ilMathBcMathAdapter constructor.

Parameters
int$scale

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

17 {
18 bcscale($scale);
19 }

Member Function Documentation

◆ add()

ilMathBCMathAdapter::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 24 of file class.ilMathBCMathAdapter.php.

25 {
26 return bcadd($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
27 }
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,
  $scale = null 
)

{Compares two numbers.

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

Implements ilMathAdapter.

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

106 {
107 return bccomp($left_operand, $right_operand, $scale);
108 }

◆ div()

ilMathBCMathAdapter::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 48 of file class.ilMathBCMathAdapter.php.

49 {
50 if ($right_operand == 0) {
51 require_once 'Services/Math/exceptions/class.ilMathDivisionByZeroException.php';
52 throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
53 }
54
55 return bcdiv($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
56 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ mod()

ilMathBCMathAdapter::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 61 of file class.ilMathBCMathAdapter.php.

62 {
63 if ($right_operand == 0) {
64 require_once 'Services/Math/exceptions/class.ilMathDivisionByZeroException.php';
65 throw new ilMathDivisionByZeroException(sprintf("Division of %s by %s not possible!", $left_operand, $right_operand));
66 }
67
68 return bcmod($this->normalize($left_operand), $this->normalize($right_operand));
69 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ mul()

ilMathBCMathAdapter::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 40 of file class.ilMathBCMathAdapter.php.

41 {
42 return bcmul($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
43 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

◆ pow()

ilMathBCMathAdapter::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 74 of file class.ilMathBCMathAdapter.php.

75 {
76 $left_operand = $this->normalize($left_operand);
77 $right_operand = $this->normalize($right_operand);
78 $scale = $this->normalize($scale);
79
80 // bcpow() only supports exponents less than or equal to 2^31-1.
81 // Also, bcpow() does not support decimal numbers.
82 // If you have scale set to 0, then the exponent is converted to an integer; otherwise an error is generated.
83 $left_operand_dec = $this->exp2dec($left_operand);
84 $right_operand_dec = $this->exp2dec($right_operand);
85
86 // bcpow does NOT support decimal exponents
87 if (strpos($right_operand_dec, '.') === false) {
88 return bcpow($left_operand_dec, $right_operand_dec, $scale);
89 }
90
91 return $this->applyScale(pow($left_operand, $right_operand), $scale);
92 }
pow($left_operand, $right_operand, $scale=null)
{Raises a number to another.mixed}
exp2dec($float_str)
Moved from ilMath... Converts numbers in the form "1.5e4" into decimal notation.
applyScale($number, $scale=null)
This method adapts the behaviour of bcscale()

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

Referenced by pow().

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

◆ sqrt()

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

{Gets the square root of a number.

Parameters
mixed$operand
int$scale
Returns
mixed
}

Implements ilMathAdapter.

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

98 {
99 return bcsqrt($operand, $scale);
100 }

◆ sub()

ilMathBCMathAdapter::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 32 of file class.ilMathBCMathAdapter.php.

33 {
34 return bcsub($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
35 }

References ilMathBaseAdapter\normalize().

+ Here is the call graph for this function:

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