Commit | Line | Data |
---|---|---|
14d4f286 S |
1 | <?php |
2 | /** | |
3 | * A class for arbitrary precision math functions | |
4 | * | |
5 | * PHP version 5.3 | |
6 | * | |
7 | * @category PHPCryptLib | |
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 CryptLib\Core; | |
15 | ||
16 | /** | |
17 | * A class for arbitrary precision math functions | |
18 | * | |
19 | * @category PHPCryptLib | |
20 | * @package Core | |
21 | * @author Anthony Ferrara <ircmaxell@ircmaxell.com> | |
22 | */ | |
23 | abstract class BigMath { | |
24 | ||
25 | /** | |
26 | * Get an instance of the big math class | |
27 | * | |
28 | * This is NOT a singleton. It simply loads the proper strategy | |
29 | * given the current server configuration | |
30 | * | |
31 | * @return \CryptLib\Core\BigMath A big math instance | |
32 | */ | |
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(); | |
39 | } else { | |
40 | return new \CryptLib\Core\BigMath\PHPMath(); | |
41 | } | |
42 | //@codeCoverageIgnoreEnd | |
43 | } | |
44 | ||
45 | /** | |
46 | * Add two numbers together | |
47 | * | |
48 | * @param string $left The left argument | |
49 | * @param string $right The right argument | |
50 | * | |
51 | * @return A base-10 string of the sum of the two arguments | |
52 | */ | |
53 | abstract public function add($left, $right); | |
54 | ||
55 | /** | |
56 | * Subtract two numbers | |
57 | * | |
58 | * @param string $left The left argument | |
59 | * @param string $right The right argument | |
60 | * | |
61 | * @return A base-10 string of the difference of the two arguments | |
62 | */ | |
63 | abstract public function subtract($left, $right); | |
64 | ||
65 | } |