Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Gmp.php
Go to the documentation of this file.
1 <?php
26 #require_once 'Zend/Crypt/Math/BigInteger/Interface.php';
27 
40 {
41 
48  public function init($operand, $base = 10)
49  {
50  return $operand;
51  }
52 
60  public function add($left_operand, $right_operand)
61  {
62  $result = gmp_add($left_operand, $right_operand);
63  return gmp_strval($result);
64  }
65 
73  public function subtract($left_operand, $right_operand)
74  {
75  $result = gmp_sub($left_operand, $right_operand);
76  return gmp_strval($result);
77  }
78 
88  public function compare($left_operand, $right_operand)
89  {
90  $result = gmp_cmp($left_operand, $right_operand);
91  return gmp_strval($result);
92  }
93 
102  public function divide($left_operand, $right_operand)
103  {
104  $result = gmp_div($left_operand, $right_operand);
105  return gmp_strval($result);
106  }
107 
116  public function modulus($left_operand, $modulus)
117  {
118  $result = gmp_mod($left_operand, $modulus);
119  return gmp_strval($result);
120  }
121 
129  public function multiply($left_operand, $right_operand)
130  {
131  $result = gmp_mul($left_operand, $right_operand);
132  return gmp_strval($result);
133  }
134 
142  public function pow($left_operand, $right_operand)
143  {
144  $result = gmp_pow($left_operand, $right_operand);
145  return gmp_strval($result);
146  }
147 
156  public function powmod($left_operand, $right_operand, $modulus)
157  {
158  $result = gmp_powm($left_operand, $right_operand, $modulus);
159  return gmp_strval($result);
160  }
161 
168  public function sqrt($operand)
169  {
170  $result = gmp_sqrt($operand);
171  return gmp_strval($result);
172  }
173 
178  public function binaryToInteger($operand)
179  {
180  $result = '0';
181  while (strlen($operand)) {
182  $ord = ord(substr($operand, 0, 1));
183  $result = gmp_add(gmp_mul($result, 256), $ord);
184  $operand = substr($operand, 1);
185  }
186  return gmp_strval($result);
187  }
188 
193  public function integerToBinary($operand)
194  {
195  $bigInt = gmp_strval($operand, 16);
196  if (strlen($bigInt) % 2 != 0) {
197  $bigInt = '0' . $bigInt;
198  } else if ($bigInt[0] > '7') {
199  $bigInt = '00' . $bigInt;
200  }
201  $return = pack("H*", $bigInt);
202  return $return;
203  }
204 
209  public function hexToDecimal($operand)
210  {
211  $return = '0';
212  while(strlen($hex)) {
213  $hex = hexdec(substr($operand, 0, 4));
214  $dec = gmp_add(gmp_mul($return, 65536), $hex);
215  $operand = substr($operand, 4);
216  }
217  return $return;
218  }
219 
220 }
divide($left_operand, $right_operand)
Definition: Gmp.php:102
powmod($left_operand, $right_operand, $modulus)
Definition: Gmp.php:156
compare($left_operand, $right_operand)
Definition: Gmp.php:88
modulus($left_operand, $modulus)
Definition: Gmp.php:116
pow($left_operand, $right_operand)
Definition: Gmp.php:142
add($left_operand, $right_operand)
Definition: Gmp.php:60
subtract($left_operand, $right_operand)
Definition: Gmp.php:73
init($operand, $base=10)
Definition: Gmp.php:48
multiply($left_operand, $right_operand)
Definition: Gmp.php:129