3 * A class for arbitrary precision math functions
7 * @category PHPCryptLib
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@@
14 namespace CryptLib\Core
;
17 * A class for arbitrary precision math functions
19 * @category PHPCryptLib
21 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
23 abstract class BigMath
{
26 * Get an instance of the big math class
28 * This is NOT a singleton. It simply loads the proper strategy
29 * given the current server configuration
31 * @return \CryptLib\Core\BigMath A big math instance
33 public static function createFromServerConfiguration() {
34 //@codeCoverageIgnoreStart
35 if (extension_loaded('bcmath')) {
36 return new \CryptLib\Core\BigMath\
BCMath();
37 } elseif (extension_loaded('gmp')) {
38 return new \CryptLib\Core\BigMath\
GMP();
40 return new \CryptLib\Core\BigMath\
PHPMath();
42 //@codeCoverageIgnoreEnd
46 * Add two numbers together
48 * @param string $left The left argument
49 * @param string $right The right argument
51 * @return A base-10 string of the sum of the two arguments
53 abstract public function add($left, $right);
56 * Subtract two numbers
58 * @param string $left The left argument
59 * @param string $right The right argument
61 * @return A base-10 string of the difference of the two arguments
63 abstract public function subtract($left, $right);