Skip to content

Commit c8d1fc4

Browse files
committed
PHP 8.5: Fix casting warnings in BigInteger::toInt() and BigNumber::of()
1 parent 66aa9e0 commit c8d1fc4

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/BigInteger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,9 +979,9 @@ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::U
979979
#[Override]
980980
public function toInt(): int
981981
{
982-
$intValue = (int) $this->value;
982+
$intValue = \filter_var($this->value, \FILTER_VALIDATE_INT);
983983

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

src/BigNumber.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,12 @@ private static function _of(BigNumber|int|float|string $value): BigNumber
456456
}
457457

458458
if (is_float($value)) {
459-
$value = (string) $value;
459+
if (is_nan($value)) {
460+
$value = "NAN";
461+
}
462+
else {
463+
$value = (string) $value;
464+
}
460465
}
461466

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

0 commit comments

Comments
 (0)