Math_BigInteger
[ class tree: Math_BigInteger ] [ index: Math_BigInteger ] [ all elements ]

Source for file demo.php

Documentation is available at demo.php

  1. <?
  2. // $Id: demo.php,v 1.3 2006/10/26 22:17:10 terrafrost Exp $
  3. // Example of how to use of BigInteger.  The output can be compared to the output that the BCMath functions would yield.
  4.  
  5. // bcpowmod is included with Math_BigInteger.php via PHP_Compat.
  6.  
  7.  
  8.  
  9. include('../Math_BigInteger.php');
  10.  
  11. $x mt_rand(1,10000000);
  12. $y mt_rand(1,10000000);
  13. $z mt_rand(1,10000000);
  14.  
  15. $_x = new Math_BigInteger($x);
  16. $_y = new Math_BigInteger($y);
  17. $_z = new Math_BigInteger($z);
  18.  
  19. echo "\$x = $x;\r\n";
  20. echo "\$y = $y;\r\n";
  21. echo "\$z = $z;\r\n";
  22.  
  23. echo "\r\n";
  24.  
  25. $result = bcadd($x,$y);
  26. $_result $_x->add($_y);
  27.  
  28. echo "\$result = \$x+\$y;\r\n";
  29. echo "$result\r\n";
  30. echo $_result->toString();
  31. echo "\r\n\r\n";
  32.  
  33. $result = bcsub($result,$y);
  34. $_result $_result->subtract($_y);
  35.  
  36. echo "\$result = \$result-\$y;\r\n";
  37. echo "$result\r\n";
  38. echo $_result->toString();
  39. echo "\r\n\r\n";
  40.  
  41. $result = bcdiv($x,$y);
  42. list($_result,$_x->divide($_y);
  43.  
  44. echo "\$result = \$x/\$y;\r\n";
  45. echo "$result\r\n";
  46. echo $_result->toString();
  47. echo "\r\n\r\n";
  48.  
  49. $result = bcmod($y,$z);
  50. list(,$_result$_y->divide($_z);
  51.  
  52. echo "\$result = \$x%\$y;\r\n";
  53. echo "$result\r\n";
  54. echo $_result->toString();
  55. echo "\r\n\r\n";
  56.  
  57. $result = bcmul($x,$z);
  58. $_result $_x->multiply($_z);
  59.  
  60. echo "\$result = \$x*\$z;\r\n";
  61. echo "$result\r\n";
  62. echo $_result->toString();
  63. echo "\r\n\r\n";
  64.  
  65. $result = bcpowmod($x,$y,$result);
  66. $_result $_x->modPow($_y,$_result);
  67.  
  68. echo "\$result = (\$x**\$y)%\$result;\r\n";
  69. echo "$result\r\n";
  70. echo $_result->toString();
  71. echo "\r\n\r\n";
  72.  
  73. // modInverse isn't demo'd because no equivalent to it exists in BCMath.
  74.  
  75. ?>

Documentation generated on Thu, 16 Nov 2006 21:00:04 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.