ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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...
 

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

References ilMathBaseAdapter\normalize().

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, because bc* function expecting strings.
+ 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.

References ilMathBaseAdapter\normalize().

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  }
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 
)

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

References ilMathBaseAdapter\normalize().

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

References ilMathBaseAdapter\normalize().

41  {
42  return bcmul($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
43  }
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,
  $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.

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

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}
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, because bc* function expecting strings.
exp2dec($float_str)
Moved from ilMath...
+ Here is the call 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.

References ilMathBaseAdapter\normalize().

33  {
34  return bcsub($this->normalize($left_operand), $this->normalize($right_operand), $this->normalize($scale));
35  }
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: