From 18c8f1b903e90ca3632520b90d21ec3770bf6e0b Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 15 Feb 2021 18:27:20 +0000 Subject: composer update brick/math --- .../src/Internal/Calculator/BcMathCalculator.php | 26 +++++++++++++++++++- .../src/Internal/Calculator/NativeCalculator.php | 28 ++++++++++++++++++---- 2 files changed, 48 insertions(+), 6 deletions(-) (limited to 'vendor/brick/math/src/Internal/Calculator') diff --git a/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php b/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php index c087245bd..6632b378a 100644 --- a/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php +++ b/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php @@ -41,6 +41,9 @@ class BcMathCalculator extends Calculator /** * {@inheritdoc} + * + * @psalm-suppress InvalidNullableReturnType + * @psalm-suppress NullableReturnStatement */ public function divQ(string $a, string $b) : string { @@ -49,9 +52,16 @@ class BcMathCalculator extends Calculator /** * {@inheritdoc} + * + * @psalm-suppress InvalidNullableReturnType + * @psalm-suppress NullableReturnStatement */ public function divR(string $a, string $b) : string { + if (version_compare(PHP_VERSION, '7.2') >= 0) { + return \bcmod($a, $b, 0); + } + return \bcmod($a, $b); } @@ -61,7 +71,15 @@ class BcMathCalculator extends Calculator public function divQR(string $a, string $b) : array { $q = \bcdiv($a, $b, 0); - $r = \bcmod($a, $b); + + if (version_compare(PHP_VERSION, '7.2') >= 0) { + $r = \bcmod($a, $b, 0); + } else { + $r = \bcmod($a, $b); + } + + assert($q !== null); + assert($r !== null); return [$q, $r]; } @@ -76,6 +94,9 @@ class BcMathCalculator extends Calculator /** * {@inheritdoc} + * + * @psalm-suppress InvalidNullableReturnType + * @psalm-suppress NullableReturnStatement */ public function modPow(string $base, string $exp, string $mod) : string { @@ -84,6 +105,9 @@ class BcMathCalculator extends Calculator /** * {@inheritDoc} + * + * @psalm-suppress NullableReturnStatement + * @psalm-suppress InvalidNullableReturnType */ public function sqrt(string $n) : string { diff --git a/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php b/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php index d248e6849..a5f8a9b48 100644 --- a/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php +++ b/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php @@ -53,6 +53,10 @@ class NativeCalculator extends Calculator */ public function add(string $a, string $b) : string { + /** + * @psalm-var numeric-string $a + * @psalm-var numeric-string $b + */ $result = $a + $b; if (is_int($result)) { @@ -69,11 +73,7 @@ class NativeCalculator extends Calculator [$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b); - if ($aNeg === $bNeg) { - $result = $this->doAdd($aDig, $bDig); - } else { - $result = $this->doSub($aDig, $bDig); - } + $result = $aNeg === $bNeg ? $this->doAdd($aDig, $bDig) : $this->doSub($aDig, $bDig); if ($aNeg) { $result = $this->neg($result); @@ -95,6 +95,10 @@ class NativeCalculator extends Calculator */ public function mul(string $a, string $b) : string { + /** + * @psalm-var numeric-string $a + * @psalm-var numeric-string $b + */ $result = $a * $b; if (is_int($result)) { @@ -169,9 +173,11 @@ class NativeCalculator extends Calculator return [$this->neg($a), '0']; } + /** @psalm-var numeric-string $a */ $na = $a * 1; // cast to number if (is_int($na)) { + /** @psalm-var numeric-string $b */ $nb = $b * 1; if (is_int($nb)) { @@ -221,6 +227,8 @@ class NativeCalculator extends Calculator $e -= $odd; $aa = $this->mul($a, $a); + + /** @psalm-suppress PossiblyInvalidArgument We're sure that $e / 2 is an int now */ $result = $this->pow($aa, $e / 2); if ($odd === 1) { @@ -316,10 +324,14 @@ class NativeCalculator extends Calculator if ($i < 0) { $blockLength += $i; + /** @psalm-suppress LoopInvalidation */ $i = 0; } + /** @psalm-var numeric-string $blockA */ $blockA = \substr($a, $i, $blockLength); + + /** @psalm-var numeric-string $blockB */ $blockB = \substr($b, $i, $blockLength); $sum = (string) ($blockA + $blockB + $carry); @@ -386,10 +398,14 @@ class NativeCalculator extends Calculator if ($i < 0) { $blockLength += $i; + /** @psalm-suppress LoopInvalidation */ $i = 0; } + /** @psalm-var numeric-string $blockA */ $blockA = \substr($a, $i, $blockLength); + + /** @psalm-var numeric-string $blockB */ $blockB = \substr($b, $i, $blockLength); $sum = $blockA - $blockB - $carry; @@ -450,6 +466,7 @@ class NativeCalculator extends Calculator if ($i < 0) { $blockALength += $i; + /** @psalm-suppress LoopInvalidation */ $i = 0; } @@ -463,6 +480,7 @@ class NativeCalculator extends Calculator if ($j < 0) { $blockBLength += $j; + /** @psalm-suppress LoopInvalidation */ $j = 0; } -- cgit v1.2.3