1 | <?php |
||
11 | class BigNumber |
||
12 | { |
||
13 | /** |
||
14 | * The value represented as a string. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | private $value; |
||
19 | |||
20 | /** |
||
21 | * The scale that is used. |
||
22 | * |
||
23 | * @var int |
||
24 | */ |
||
25 | private $scale; |
||
26 | |||
27 | /** |
||
28 | * A flag that indicates whether or not the state of this object can be changed. |
||
29 | * |
||
30 | * @var bool |
||
31 | */ |
||
32 | private $mutable; |
||
33 | |||
34 | /** |
||
35 | * Initializes a new instance of this class. |
||
36 | * |
||
37 | * @param string|int|self $value The value to set. |
||
38 | * @param int $scale The scale to use. |
||
39 | * @param bool $mutable Whether or not the state of this object can be changed. |
||
40 | */ |
||
41 | 102 | public function __construct($value = 0, $scale = 10, $mutable = true) |
|
48 | |||
49 | /** |
||
50 | * Gets the value of the big number. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | 85 | public function getValue() |
|
59 | |||
60 | /** |
||
61 | * Sets the value. |
||
62 | * |
||
63 | * @param string $value |
||
64 | */ |
||
65 | 5 | public function setValue($value) |
|
73 | |||
74 | /** |
||
75 | * Gets the scale of this number. |
||
76 | * |
||
77 | * @return int |
||
78 | */ |
||
79 | 101 | public function getScale() |
|
83 | |||
84 | /** |
||
85 | * Sets the scale of this number. |
||
86 | * |
||
87 | * @param int $scale The scale to set. |
||
88 | * @return BigNumber |
||
89 | */ |
||
90 | 8 | public function setScale($scale) |
|
112 | |||
113 | /** |
||
114 | * Converts the number to an absolute value. |
||
115 | */ |
||
116 | 6 | public function abs() |
|
122 | |||
123 | /** |
||
124 | * Adds the given value to this value. |
||
125 | * |
||
126 | * @param float|int|string|BigNumber $value The value to add. |
||
127 | * @return BigNumber |
||
128 | */ |
||
129 | 8 | public function add($value) |
|
139 | |||
140 | /** |
||
141 | * Divides this value by the given value. |
||
142 | * |
||
143 | * @param float|int|string|BigNumber $value The value to divide by. |
||
144 | * @return BigNumber |
||
145 | */ |
||
146 | 9 | public function divide($value) |
|
161 | |||
162 | /** |
||
163 | * Multiplies the given value with this value. |
||
164 | * |
||
165 | * @param float|int|string|BigNumber $value The value to multiply with. |
||
166 | * @return BigNumber |
||
167 | */ |
||
168 | 12 | public function multiply($value) |
|
178 | |||
179 | /** |
||
180 | * Performs a modulo operation with the given number. |
||
181 | * |
||
182 | * @param float|int|string|BigNumber $value The value to perform a modulo operation with. |
||
183 | * @return BigNumber |
||
184 | */ |
||
185 | 9 | public function mod($value) |
|
193 | |||
194 | /** |
||
195 | * Performs a power operation with the given number. |
||
196 | * |
||
197 | * @param int|string $value The value to perform a power operation with. Should be an integer (or an int-string). |
||
198 | * @return BigNumber |
||
199 | */ |
||
200 | 8 | public function pow($value) |
|
213 | |||
214 | /** |
||
215 | * Performs a square root operation with the given number. |
||
216 | * |
||
217 | * @return BigNumber |
||
218 | */ |
||
219 | 3 | public function sqrt() |
|
225 | |||
226 | /** |
||
227 | * Subtracts the given value from this value. |
||
228 | * |
||
229 | * @param float|int|string|BigNumber $value The value to subtract. |
||
230 | * @return BigNumber |
||
231 | */ |
||
232 | 8 | public function subtract($value) |
|
242 | |||
243 | /** |
||
244 | * Checks if this object is mutable. |
||
245 | * |
||
246 | * @return bool |
||
247 | */ |
||
248 | 68 | public function isMutable() |
|
252 | |||
253 | /** |
||
254 | * Converts this class to a string. |
||
255 | * |
||
256 | * @return string |
||
257 | */ |
||
258 | 10 | public function toString() |
|
262 | |||
263 | /** |
||
264 | * Converts this class to a string. |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | 10 | public function __toString() |
|
272 | |||
273 | /** |
||
274 | * A helper method to assign the given value. |
||
275 | * |
||
276 | * @param int|string|BigNumber $value The value to assign. |
||
277 | * @return BigNumber |
||
278 | */ |
||
279 | 52 | private function assignValue($value) |
|
289 | |||
290 | /** |
||
291 | * A helper method to set the value on this class. |
||
292 | * |
||
293 | * @param int|string|BigNumber $value The value to assign. |
||
294 | * @return BigNumber |
||
295 | */ |
||
296 | 102 | private function internalSetValue($value) |
|
309 | } |
||
310 |