|
29 | 29 | * @method static static from(int|string $number, int $scale = 2) |
30 | 30 | * @method static static makeOrNull(int|string|null $number, int $scale = 2) |
31 | 31 | * |
| 32 | + * @method string abs() |
| 33 | + * @method string add(float|int|string $value) |
| 34 | + * @method string divide(float|int|string $value) |
| 35 | + * @method string multiply(float|int|string $value) |
| 36 | + * @method string mod(float|int|string $value) |
| 37 | + * @method string pow(int|string $value) |
| 38 | + * @method string sqrt() |
| 39 | + * @method string subtract(float|int|string $value) |
| 40 | + * |
| 41 | + * @see \PHP\Math\BigNumber\BigNumber |
| 42 | + * |
32 | 43 | * @extends ValueObject<TKey, TValue> |
33 | 44 | */ |
34 | 45 | class Number extends ValueObject |
@@ -86,4 +97,32 @@ public function asFloat(): float |
86 | 97 | { |
87 | 98 | return (float) $this->bigNumber->getValue(); |
88 | 99 | } |
| 100 | + |
| 101 | + /** |
| 102 | + * Get the underlying `BigNumber` object. |
| 103 | + * |
| 104 | + * @return BigNumber |
| 105 | + */ |
| 106 | + public function asBigNumber(): BigNumber |
| 107 | + { |
| 108 | + return $this->bigNumber; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Forward call to underlying object if the method |
| 113 | + * doesn't exist in `Number` and doesn't have a macro. |
| 114 | + * |
| 115 | + * @param string $method |
| 116 | + * @param array $parameters |
| 117 | + * |
| 118 | + * @return mixed |
| 119 | + */ |
| 120 | + public function __call($method, $parameters) |
| 121 | + { |
| 122 | + if (static::hasMacro($method)) { |
| 123 | + return parent::__call($method, $parameters); |
| 124 | + } |
| 125 | + |
| 126 | + return $this->bigNumber->{$method}(...$parameters)->getValue(); |
| 127 | + } |
89 | 128 | } |
0 commit comments