Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Zend_Crypt_Math_BigInteger_Bcmath Class Reference
Inheritance diagram for Zend_Crypt_Math_BigInteger_Bcmath:
Zend_Crypt_Math_BigInteger_Interface

Public Member Functions

 init ($operand, $base=10)
 
 add ($left_operand, $right_operand)
 
 subtract ($left_operand, $right_operand)
 
 compare ($left_operand, $right_operand)
 
 divide ($left_operand, $right_operand)
 
 modulus ($left_operand, $modulus)
 
 multiply ($left_operand, $right_operand)
 
 pow ($left_operand, $right_operand)
 
 powmod ($left_operand, $right_operand, $modulus)
 
 sqrt ($operand)
 
 binaryToInteger ($operand)
 
 integerToBinary ($operand)
 
 hexToDecimal ($operand)
 

Detailed Description

Definition at line 39 of file Bcmath.php.

Member Function Documentation

◆ add()

add (   $left_operand,
  $right_operand 
)

Adds two arbitrary precision numbers

Parameters
string$left_operand
string$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 62 of file Bcmath.php.

63  {
64  return bcadd($left_operand, $right_operand);
65  }

◆ binaryToInteger()

binaryToInteger (   $operand)
Parameters
string$operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 171 of file Bcmath.php.

172  {
173  $result = '0';
174  while (strlen($operand)) {
175  $ord = ord(substr($operand, 0, 1));
176  $result = bcadd(bcmul($result, 256), $ord);
177  $operand = substr($operand, 1);
178  }
179  return $result;
180  }

◆ compare()

compare (   $left_operand,
  $right_operand 
)

Compare two big integers and returns result as an integer where 0 means both are identical, 1 that left_operand is larger, or -1 that right_operand is larger.

Parameters
string$left_operand
string$right_operand
Returns
int

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 88 of file Bcmath.php.

89  {
90  return bccomp($left_operand, $right_operand);
91  }

◆ divide()

divide (   $left_operand,
  $right_operand 
)

Divide two big integers and return result or NULL if the denominator is zero.

Parameters
string$left_operand
string$right_operand
Returns
string|null

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 101 of file Bcmath.php.

102  {
103  return bcdiv($left_operand, $right_operand);
104  }

◆ hexToDecimal()

hexToDecimal (   $operand)

public function integerToBinary($operand) { $return = ''; while(bccomp($operand, '0')) { $return .= chr(bcmod($operand, '256')); $operand = bcdiv($operand, '256'); } return $return; }

Parameters
string$operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 217 of file Bcmath.php.

218  {
219  $return = '0';
220  while(strlen($hex)) {
221  $hex = hexdec(substr($operand, 0, 4));
222  $dec = bcadd(bcmul($return, 65536), $hex);
223  $operand = substr($operand, 4);
224  }
225  return $return;
226  }

◆ init()

init (   $operand,
  $base = 10 
)

Initialise a big integer into an extension specific type. This is not applicable to BCMath.

Parameters
string$operand
int$base
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 50 of file Bcmath.php.

51  {
52  return $operand;
53  }

◆ integerToBinary()

integerToBinary (   $operand)
Parameters
string$operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 186 of file Bcmath.php.

187  {
188  $cmp = bccomp($operand, 0);
189  $return = '';
190  if ($cmp == 0) {
191  return "\0";
192  }
193  while (bccomp($operand, 0) > 0) {
194  $return = chr(bcmod($operand, 256)) . $return;
195  $operand = bcdiv($operand, 256);
196  }
197  if (ord($return[0]) > 127) {
198  $return = "\0" . $return;
199  }
200  return $return;
201  }

◆ modulus()

modulus (   $left_operand,
  $modulus 
)

Get modulus of an arbitrary precision number

Parameters
string$left_operand
string$modulus
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 113 of file Bcmath.php.

114  {
115  return bcmod($left_operand, $modulus);
116  }

◆ multiply()

multiply (   $left_operand,
  $right_operand 
)

Multiply two arbitrary precision numbers

Parameters
string$left_operand
string$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 125 of file Bcmath.php.

126  {
127  return bcmul($left_operand, $right_operand);
128  }

◆ pow()

pow (   $left_operand,
  $right_operand 
)

Raise an arbitrary precision number to another

Parameters
string$left_operand
string$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 137 of file Bcmath.php.

138  {
139  return bcpow($left_operand, $right_operand);
140  }

◆ powmod()

powmod (   $left_operand,
  $right_operand,
  $modulus 
)

Raise an arbitrary precision number to another, reduced by a specified modulus

Parameters
string$left_operand
string$right_operand
string$modulus
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 151 of file Bcmath.php.

152  {
153  return bcpowmod($left_operand, $right_operand, $modulus);
154  }

◆ sqrt()

sqrt (   $operand)

Get the square root of an arbitrary precision number

Parameters
string$operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 162 of file Bcmath.php.

163  {
164  return bcsqrt($operand);
165  }

◆ subtract()

subtract (   $left_operand,
  $right_operand 
)

Subtract one arbitrary precision number from another

Parameters
string$left_operand
string$right_operand
Returns
string

Implements Zend_Crypt_Math_BigInteger_Interface.

Definition at line 74 of file Bcmath.php.

75  {
76  return bcsub($left_operand, $right_operand);
77  }

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