Skip to content

Commit 56a7d32

Browse files
committed
Throw error, if bcmath is missing
1 parent 23daa4b commit 56a7d32

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/Type/Number.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,49 @@ public function __construct(string $value)
2323

2424
public function add(NumberInterface $addend): self
2525
{
26-
$this->value = bcadd($this->value, (string) $addend, static::PRECISION);
26+
$this->value = \bcadd($this->value, (string) $addend, static::PRECISION);
2727
return $this;
2828
}
2929

3030
public function sub(NumberInterface $subtrahend): self
3131
{
32-
$this->value = bcsub($this->value, (string) $subtrahend, static::PRECISION);
32+
$this->value = \bcsub($this->value, (string) $subtrahend, static::PRECISION);
3333
return $this;
3434
}
3535

3636
public function mul(NumberInterface $multiplicand): self
3737
{
38-
$this->value = bcmul($this->value, (string) $multiplicand, static::PRECISION);
38+
$this->value = \bcmul($this->value, (string) $multiplicand, static::PRECISION);
3939
return $this;
4040
}
4141

4242
public function div(NumberInterface $divisor): self
4343
{
44-
$this->value = bcdiv($this->value, (string) $divisor, static::PRECISION);
44+
$this->value = \bcdiv($this->value, (string) $divisor, static::PRECISION);
4545
return $this;
4646
}
4747

4848
public function pow(NumberInterface $exponent): self
4949
{
50-
$this->value = bcpow($this->value, (string) $exponent, static::PRECISION);
50+
$this->value = \bcpow($this->value, (string) $exponent, static::PRECISION);
5151
return $this;
5252
}
5353

5454
public function mod(NumberInterface $divisor): self
5555
{
56-
$this->value = bcmod($this->value, (string) $divisor, static::PRECISION);
56+
$this->value = \bcmod($this->value, (string) $divisor, static::PRECISION);
5757
return $this;
5858
}
5959

6060
public function sqrt(): self
6161
{
62-
$this->value = bcsqrt($this->value, static::PRECISION);
62+
$this->value = \bcsqrt($this->value, static::PRECISION);
6363
return $this;
6464
}
6565

6666
public function compare(NumberInterface $operand): int
6767
{
68-
return bccomp($this->value, (string) $operand, static::PRECISION);
68+
return \bccomp($this->value, (string) $operand, static::PRECISION);
6969
}
7070

7171
public function equals(NumberInterface $operand): bool
@@ -101,7 +101,7 @@ public function isInteger(): bool
101101
return true;
102102
}
103103

104-
return bccomp($parts[1], '0') === 0;
104+
return \bccomp($parts[1], '0') === 0;
105105
}
106106

107107
public function __toString(): string
@@ -112,8 +112,12 @@ public function __toString(): string
112112
protected function parseBcMathNumber(string $string): ?string
113113
{
114114
try {
115-
return bcadd($string, '0', static::PRECISION);
116-
} catch (\Throwable) {
115+
return \bcadd($string, '0', static::PRECISION);
116+
} catch (\Throwable $throwable) {
117+
if (!function_exists('bcadd')) {
118+
throw $throwable;
119+
}
120+
117121
// not well-formed number
118122
}
119123

0 commit comments

Comments
 (0)