function bcadd($a, $b) { return bi_to_str(bi_add($a, $b)); }
/** * Add two arbitrary precision numbers * * @param string $a The left operand, as a string. * @param string $b The right operand, as a string. * @access public * @return string The sum of the two operands, as a string */ public function add($a, $b) { return bi_add($a, $b); }
echo 'hex value of $str = [', $str, "]<br/>\n"; $b = bi_from_str($str, 16); echo 'decimal value of $b = [', bi_to_str($b), "]<br/>\n"; echo 'binary value of $b = [', bi_to_str($b, 2), "]<br/>\n"; /* string bi_base_convert(string $num, int $base_from, int $base_to) Converts string representation of $num from base $base_from to $base_to */ $num = '-12345678900987654321'; echo 'Decimal number [', $num, '] equals to [', bi_base_convert($num, 10, 36), '] by base 36', "<br/>\n"; /* basic functions */ echo '<h3>basic functions</h3>' . "\n"; $c = bi_add($a, $b); echo '$a + $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_sub($a, $b); echo '$a - $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_mul($a, $b); echo '$a * $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_div($a, $b); echo '$a / $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_mod($a, $b); echo '$a % $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_abs($a); echo 'abs($a) = [', bi_to_str($c), "]<br/>\n"; $c = bi_neg($a); echo 'neg($a) = [', bi_to_str($c), "]<br/>\n"; $c = bi_inc($a); echo 'inc($a) = [', bi_to_str($c), "]<br/>\n";
<?php $two = bi_from_str('2'); $four = bi_add($two, $two); // Use bi_to_str() to get strings from big_int resources print bi_to_str($four); // prints 4 // Computing large factorials very quickly $factorial = bi_fact(20);