51 } |
51 } |
52 |
52 |
53 /** |
53 /** |
54 * Adds two arbitrary precision numbers |
54 * Adds two arbitrary precision numbers |
55 * |
55 * |
56 * @param string $left_operand |
56 * @param resource $left_operand |
57 * @param string $right_operand |
57 * @param resource $right_operand |
58 * @return string |
58 * @return string |
59 */ |
59 */ |
60 public function add($left_operand, $right_operand) |
60 public function add($left_operand, $right_operand) |
61 { |
61 { |
62 $result = gmp_add($left_operand, $right_operand); |
62 $result = gmp_add($left_operand, $right_operand); |
63 return gmp_strval($result); |
63 return gmp_strval($result); |
64 } |
64 } |
65 |
65 |
66 /** |
66 /** |
67 * @param string $left_operand |
67 * Subtract numbers |
68 * @param string $right_operand |
68 * |
|
69 * @param resource $left_operand |
|
70 * @param resource $right_operand |
69 * @return string |
71 * @return string |
70 */ |
72 */ |
71 public function subtract($left_operand, $right_operand) |
73 public function subtract($left_operand, $right_operand) |
72 { |
74 { |
73 $result = gmp_sub($left_operand, $right_operand); |
75 $result = gmp_sub($left_operand, $right_operand); |
76 |
78 |
77 /** |
79 /** |
78 * Compare two big integers and returns result as an integer where 0 means |
80 * Compare two big integers and returns result as an integer where 0 means |
79 * both are identical, 1 that left_operand is larger, or -1 that |
81 * both are identical, 1 that left_operand is larger, or -1 that |
80 * right_operand is larger. |
82 * right_operand is larger. |
81 * @param string $left_operand |
83 * |
82 * @param string $right_operand |
84 * @param resource $left_operand |
|
85 * @param resource $right_operand |
83 * @return int |
86 * @return int |
84 */ |
87 */ |
85 public function compare($left_operand, $right_operand) |
88 public function compare($left_operand, $right_operand) |
86 { |
89 { |
87 $result = gmp_cmp($left_operand, $right_operand); |
90 $result = gmp_cmp($left_operand, $right_operand); |
89 } |
92 } |
90 |
93 |
91 /** |
94 /** |
92 * Divide two big integers and return result or NULL if the denominator |
95 * Divide two big integers and return result or NULL if the denominator |
93 * is zero. |
96 * is zero. |
94 * @param string $left_operand |
97 * |
95 * @param string $right_operand |
98 * @param resource $left_operand |
|
99 * @param resource $right_operand |
96 * @return string|null |
100 * @return string|null |
97 */ |
101 */ |
98 public function divide($left_operand, $right_operand) |
102 public function divide($left_operand, $right_operand) |
99 { |
103 { |
100 $result = gmp_div($left_operand, $right_operand); |
104 $result = gmp_div($left_operand, $right_operand); |
101 return gmp_strval($result); |
105 return gmp_strval($result); |
102 } |
106 } |
103 |
107 |
104 /** |
108 /** |
105 * @param string $left_operand |
109 * Modulo operation |
106 * @param string $right_operand |
110 * |
|
111 * @param resource $left_operand |
|
112 * @param resource $modulus |
|
113 * @internal param string $right_operand |
107 * @return string |
114 * @return string |
108 */ |
115 */ |
109 public function modulus($left_operand, $modulus) |
116 public function modulus($left_operand, $modulus) |
110 { |
117 { |
111 $result = gmp_mod($left_operand, $modulus); |
118 $result = gmp_mod($left_operand, $modulus); |
112 return gmp_strval($result); |
119 return gmp_strval($result); |
113 } |
120 } |
114 |
121 |
115 /** |
122 /** |
116 * @param string $left_operand |
123 * Multiply numbers |
117 * @param string $right_operand |
124 * |
|
125 * @param resource $left_operand |
|
126 * @param resource $right_operand |
118 * @return string |
127 * @return string |
119 */ |
128 */ |
120 public function multiply($left_operand, $right_operand) |
129 public function multiply($left_operand, $right_operand) |
121 { |
130 { |
122 $result = gmp_mul($left_operand, $right_operand); |
131 $result = gmp_mul($left_operand, $right_operand); |
123 return gmp_strval($result); |
132 return gmp_strval($result); |
124 } |
133 } |
125 |
134 |
126 /** |
135 /** |
127 * @param string $left_operand |
136 * Raise number into power |
128 * @param string $right_operand |
137 * |
|
138 * @param resource $left_operand |
|
139 * @param int $right_operand |
129 * @return string |
140 * @return string |
130 */ |
141 */ |
131 public function pow($left_operand, $right_operand) |
142 public function pow($left_operand, $right_operand) |
132 { |
143 { |
133 $result = gmp_pow($left_operand, $right_operand); |
144 $result = gmp_pow($left_operand, $right_operand); |
134 return gmp_strval($result); |
145 return gmp_strval($result); |
135 } |
146 } |
136 |
147 |
137 /** |
148 /** |
138 * @param string $left_operand |
149 * Raise number into power with modulo |
139 * @param string $right_operand |
150 * |
|
151 * @param resource $left_operand |
|
152 * @param resource $right_operand |
|
153 * @param resource $modulus |
140 * @return string |
154 * @return string |
141 */ |
155 */ |
142 public function powmod($left_operand, $right_operand, $modulus) |
156 public function powmod($left_operand, $right_operand, $modulus) |
143 { |
157 { |
144 $result = gmp_powm($left_operand, $right_operand, $modulus); |
158 $result = gmp_powm($left_operand, $right_operand, $modulus); |
145 return gmp_strval($result); |
159 return gmp_strval($result); |
146 } |
160 } |
147 |
161 |
148 /** |
162 /** |
149 * @param string $left_operand |
163 * Calculate square root |
150 * @param string $right_operand |
164 * |
|
165 * @param $operand |
151 * @return string |
166 * @return string |
152 */ |
167 */ |
153 public function sqrt($operand) |
168 public function sqrt($operand) |
154 { |
169 { |
155 $result = gmp_sqrt($operand); |
170 $result = gmp_sqrt($operand); |
156 return gmp_strval($result); |
171 return gmp_strval($result); |
157 } |
172 } |
158 |
173 |
159 |
174 /** |
|
175 * @param string $operand |
|
176 * @return string |
|
177 */ |
160 public function binaryToInteger($operand) |
178 public function binaryToInteger($operand) |
161 { |
179 { |
162 $result = '0'; |
180 $result = '0'; |
163 while (strlen($operand)) { |
181 while (strlen($operand)) { |
164 $ord = ord(substr($operand, 0, 1)); |
182 $ord = ord(substr($operand, 0, 1)); |