Skip to content

Commit 8930e4d

Browse files
authored
Merge pull request #101 from julien-boudry/master
PHP 8.5: Fix casting warnings in BigInteger::toInt() and BigNumber::of()
2 parents b9175bf + 49d183c commit 8930e4d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/BigInteger.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use function assert;
1919
use function bin2hex;
2020
use function chr;
21+
use function filter_var;
2122
use function hex2bin;
2223
use function in_array;
2324
use function intdiv;
@@ -32,6 +33,8 @@
3233
use function strtolower;
3334
use function substr;
3435

36+
use const FILTER_VALIDATE_INT;
37+
3538
/**
3639
* An arbitrary-size integer.
3740
*
@@ -979,9 +982,9 @@ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::U
979982
#[Override]
980983
public function toInt(): int
981984
{
982-
$intValue = (int) $this->value;
985+
$intValue = filter_var($this->value, FILTER_VALIDATE_INT);
983986

984-
if ($this->value !== (string) $intValue) {
987+
if ($intValue === false) {
985988
throw IntegerOverflowException::toIntOverflow($this);
986989
}
987990

src/BigNumber.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use function filter_var;
1919
use function is_float;
2020
use function is_int;
21+
use function is_nan;
2122
use function ltrim;
2223
use function preg_match;
2324
use function str_contains;
@@ -458,7 +459,11 @@ private static function _of(BigNumber|int|float|string $value): BigNumber
458459
}
459460

460461
if (is_float($value)) {
461-
$value = (string) $value;
462+
if (is_nan($value)) {
463+
$value = 'NAN';
464+
} else {
465+
$value = (string) $value;
466+
}
462467
}
463468

464469
if (str_contains($value, '/')) {

0 commit comments

Comments
 (0)