diff options
author | Mario <mario@mariovavti.com> | 2021-03-08 09:31:23 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-03-08 09:31:23 +0000 |
commit | 951e9c8c4f39dd8577834d5bc501c05d80722de9 (patch) | |
tree | 6a42c6a229c7b2b3e13bc5af77a733d054242695 /vendor/brick/math/src/Internal/Calculator | |
parent | f94b046333c57acde493ee5dc2511acc6baca701 (diff) | |
parent | 89415e17313578eb115c441480b6e0ddfa90afef (diff) | |
download | volse-hubzilla-5.4.tar.gz volse-hubzilla-5.4.tar.bz2 volse-hubzilla-5.4.zip |
Merge branch '5.4RC'5.4
Diffstat (limited to 'vendor/brick/math/src/Internal/Calculator')
-rw-r--r-- | vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php | 26 | ||||
-rw-r--r-- | vendor/brick/math/src/Internal/Calculator/NativeCalculator.php | 28 |
2 files changed, 48 insertions, 6 deletions
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; } |