Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Bcmath.php
Go to the documentation of this file.
1 <?php
26 #require_once 'Zend/Crypt/Math/BigInteger/Interface.php';
27 
40 {
41 
50  public function init($operand, $base = 10)
51  {
52  return $operand;
53  }
54 
62  public function add($left_operand, $right_operand)
63  {
64  return bcadd($left_operand, $right_operand);
65  }
66 
74  public function subtract($left_operand, $right_operand)
75  {
76  return bcsub($left_operand, $right_operand);
77  }
78 
88  public function compare($left_operand, $right_operand)
89  {
90  return bccomp($left_operand, $right_operand);
91  }
92 
101  public function divide($left_operand, $right_operand)
102  {
103  return bcdiv($left_operand, $right_operand);
104  }
105 
113  public function modulus($left_operand, $modulus)
114  {
115  return bcmod($left_operand, $modulus);
116  }
117 
125  public function multiply($left_operand, $right_operand)
126  {
127  return bcmul($left_operand, $right_operand);
128  }
129 
137  public function pow($left_operand, $right_operand)
138  {
139  return bcpow($left_operand, $right_operand);
140  }
141 
151  public function powmod($left_operand, $right_operand, $modulus)
152  {
153  return bcpowmod($left_operand, $right_operand, $modulus);
154  }
155 
162  public function sqrt($operand)
163  {
164  return bcsqrt($operand);
165  }
166 
171  public function binaryToInteger($operand)
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  }
181 
186  public function integerToBinary($operand)
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  }
202  // Prior version for referenced offset
212 
217  public function hexToDecimal($operand)
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  }
227 }
compare($left_operand, $right_operand)
Definition: Bcmath.php:88
pow($left_operand, $right_operand)
Definition: Bcmath.php:137
powmod($left_operand, $right_operand, $modulus)
Definition: Bcmath.php:151
add($left_operand, $right_operand)
Definition: Bcmath.php:62
multiply($left_operand, $right_operand)
Definition: Bcmath.php:125
modulus($left_operand, $modulus)
Definition: Bcmath.php:113
init($operand, $base=10)
Definition: Bcmath.php:50
divide($left_operand, $right_operand)
Definition: Bcmath.php:101
subtract($left_operand, $right_operand)
Definition: Bcmath.php:74