BigMath.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * A class for arbitrary precision math functions
  4. *
  5. * PHP version 5.3
  6. *
  7. * @category PHPPasswordLib
  8. * @package Core
  9. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  10. * @copyright 2011 The Authors
  11. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  12. * @version Build @@version@@
  13. */
  14. namespace SecurityLib;
  15. /**
  16. * A class for arbitrary precision math functions
  17. *
  18. * @category PHPPasswordLib
  19. * @package Core
  20. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  21. */
  22. abstract class BigMath {
  23. /**
  24. * Get an instance of the big math class
  25. *
  26. * This is NOT a singleton. It simply loads the proper strategy
  27. * given the current server configuration
  28. *
  29. * @return \PasswordLib\Core\BigMath A big math instance
  30. */
  31. public static function createFromServerConfiguration() {
  32. //@codeCoverageIgnoreStart
  33. if (extension_loaded('gmp')) {
  34. return new \SecurityLib\BigMath\GMP();
  35. } elseif (extension_loaded('bcmath')) {
  36. return new \SecurityLib\BigMath\BCMath();
  37. } else {
  38. return new \SecurityLib\BigMath\PHPMath();
  39. }
  40. //@codeCoverageIgnoreEnd
  41. }
  42. /**
  43. * Add two numbers together
  44. *
  45. * @param string $left The left argument
  46. * @param string $right The right argument
  47. *
  48. * @return A base-10 string of the sum of the two arguments
  49. */
  50. abstract public function add($left, $right);
  51. /**
  52. * Subtract two numbers
  53. *
  54. * @param string $left The left argument
  55. * @param string $right The right argument
  56. *
  57. * @return A base-10 string of the difference of the two arguments
  58. */
  59. abstract public function subtract($left, $right);
  60. }