Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use function assert;
use function bin2hex;
use function chr;
use function filter_var;
use function hex2bin;
use function in_array;
use function intdiv;
Expand All @@ -32,6 +33,8 @@
use function strtolower;
use function substr;

use const FILTER_VALIDATE_INT;

/**
* An arbitrary-size integer.
*
Expand Down Expand Up @@ -979,9 +982,9 @@ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::U
#[Override]
public function toInt(): int
{
$intValue = (int) $this->value;
$intValue = filter_var($this->value, FILTER_VALIDATE_INT);

if ($this->value !== (string) $intValue) {
if ($intValue === false) {
throw IntegerOverflowException::toIntOverflow($this);
}

Expand Down
7 changes: 6 additions & 1 deletion src/BigNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use function assert;
use function is_float;
use function is_int;
use function is_nan;
use function ltrim;
use function preg_match;
use function str_contains;
Expand Down Expand Up @@ -456,7 +457,11 @@ private static function _of(BigNumber|int|float|string $value): BigNumber
}

if (is_float($value)) {
$value = (string) $value;
if (is_nan($value)) {
$value = 'NAN';
} else {
$value = (string) $value;
}
}

if (str_contains($value, '/')) {
Expand Down