Source for file demo.php
Documentation is available at demo.php
// Example of how to use of BigInteger. The output can be compared to the output that the BCMath functions would yield.
// bcpowmod is included with Math_BigInteger.php via PHP_Compat.
include('../Math/BigInteger.php');
$x = mt_rand(1,10000000);
$y = mt_rand(1,10000000);
$z = mt_rand(1,10000000);
$_x = new Math_BigInteger($x);
$_y = new Math_BigInteger($y);
$_z = new Math_BigInteger($z);
$_result = $_x->add($_y);
echo "\$result = \$x+\$y;\r\n";
echo $_result->toString();
$result = bcsub($result,$y);
$_result = $_result->subtract($_y);
echo "\$result = \$result-\$y;\r\n";
echo $_result->toString();
list($_result,) = $_x->divide($_y);
echo "\$result = \$x/\$y;\r\n";
echo $_result->toString();
list(,$_result) = $_y->divide($_z);
echo "\$result = \$x%\$y;\r\n";
echo $_result->toString();
$_result = $_x->multiply($_z);
echo "\$result = \$x*\$z;\r\n";
echo $_result->toString();
$result = bcpowmod($x,$y,$result);
$_result = $_x->modPow($_y,$_result);
echo "\$result = (\$x**\$y)%\$result;\r\n";
echo $_result->toString();
// modInverse isn't demo'd because no equivalent to it exists in BCMath.
Documentation generated on Mon, 11 Mar 2019 15:56:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|