Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Nov 29, 2023
1 parent 6380a77 commit 3ebe5dd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/BigNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ abstract class BigNumber implements \JsonSerializable
'\/?' .
'(?<denominator>[0-9]+)' .
'$/';

/**
* Creates a BigNumber of the given value.
*
Expand Down Expand Up @@ -139,7 +140,7 @@ private static function _of(BigNumber|int|float|string $value) : BigNumber
throw new NumberFormatException('Exponent too large.');
}

$unscaledValue = self::cleanUp(($sign ?? ''), $integral . $fractional);
$unscaledValue = self::cleanUp($sign, $integral . $fractional);

$scale = \strlen($fractional) - $exponent;

Expand All @@ -153,7 +154,7 @@ private static function _of(BigNumber|int|float|string $value) : BigNumber
return new BigDecimal($unscaledValue, $scale);
}

$integral = self::cleanUp(($sign ?? ''), $integral);
$integral = self::cleanUp($sign, $integral);

return new BigInteger($integral);
}
Expand Down Expand Up @@ -324,10 +325,11 @@ private static function add(BigNumber $a, BigNumber $b) : BigNumber
}

/**
* Removes optional leading zeros and applies sign if needed(- for negatives).
* Removes optional leading zeros and applies sign.
*
* @param string|null $sign The sign, '+' or '-', optional. Null is allowed for convenience and treated as '+'.
* @param string $number The number, validated as a non-empty string of digits.
*
* @param string|null $sign The sign, '+' or '-', optional.
* @param string $number The number, validated as a non-empty string of digits.
* @psalm-pure
*/
private static function cleanUp(string|null $sign, string $number) : string
Expand Down

0 comments on commit 3ebe5dd

Please sign in to comment.