diff options
author | Mario <mario@mariovavti.com> | 2023-05-30 08:36:17 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-05-30 08:36:17 +0000 |
commit | b9812ba06ac16899df2a25f0abf25962ae3273f2 (patch) | |
tree | 35762d0183f5b0c6d866b00cdeebfbae595cfa56 /vendor/brick/math/src/Internal/Calculator.php | |
parent | bc6aded074156ec81084334a4d6aa58bc0f37a68 (diff) | |
download | volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.tar.gz volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.tar.bz2 volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.zip |
update composer libs
Diffstat (limited to 'vendor/brick/math/src/Internal/Calculator.php')
-rw-r--r-- | vendor/brick/math/src/Internal/Calculator.php | 110 |
1 files changed, 15 insertions, 95 deletions
diff --git a/vendor/brick/math/src/Internal/Calculator.php b/vendor/brick/math/src/Internal/Calculator.php index a6eac799f..b8cecda96 100644 --- a/vendor/brick/math/src/Internal/Calculator.php +++ b/vendor/brick/math/src/Internal/Calculator.php @@ -34,10 +34,8 @@ abstract class Calculator /** * The Calculator instance in use. - * - * @var Calculator|null */ - private static $instance; + private static ?Calculator $instance = null; /** * Sets the Calculator instance to use. @@ -45,8 +43,6 @@ abstract class Calculator * An instance is typically set only in unit tests: the autodetect is usually the best option. * * @param Calculator|null $calculator The calculator instance, or NULL to revert to autodetect. - * - * @return void */ final public static function set(?Calculator $calculator) : void { @@ -58,8 +54,6 @@ abstract class Calculator * * If none has been explicitly set, the fastest available implementation will be returned. * - * @return Calculator - * * @psalm-pure * @psalm-suppress ImpureStaticProperty */ @@ -77,8 +71,6 @@ abstract class Calculator * Returns the fastest available Calculator implementation. * * @codeCoverageIgnore - * - * @return Calculator */ private static function detect() : Calculator { @@ -96,9 +88,6 @@ abstract class Calculator /** * Extracts the sign & digits of the operands. * - * @param string $a The first operand. - * @param string $b The second operand. - * * @return array{bool, bool, string, string} Whether $a and $b are negative, followed by their digits. */ final protected function init(string $a, string $b) : array @@ -114,10 +103,6 @@ abstract class Calculator /** * Returns the absolute value of a number. - * - * @param string $n The number. - * - * @return string The absolute value. */ final public function abs(string $n) : string { @@ -126,10 +111,6 @@ abstract class Calculator /** * Negates a number. - * - * @param string $n The number. - * - * @return string The negated value. */ final public function neg(string $n) : string { @@ -147,9 +128,6 @@ abstract class Calculator /** * Compares two numbers. * - * @param string $a The first number. - * @param string $b The second number. - * * @return int [-1, 0, 1] If the first number is less than, equal to, or greater than the second number. */ final public function cmp(string $a, string $b) : int @@ -180,31 +158,16 @@ abstract class Calculator /** * Adds two numbers. - * - * @param string $a The augend. - * @param string $b The addend. - * - * @return string The sum. */ abstract public function add(string $a, string $b) : string; /** * Subtracts two numbers. - * - * @param string $a The minuend. - * @param string $b The subtrahend. - * - * @return string The difference. */ abstract public function sub(string $a, string $b) : string; /** * Multiplies two numbers. - * - * @param string $a The multiplicand. - * @param string $b The multiplier. - * - * @return string The product. */ abstract public function mul(string $a, string $b) : string; @@ -234,7 +197,7 @@ abstract class Calculator * @param string $a The dividend. * @param string $b The divisor, must not be zero. * - * @return string[] An array containing the quotient and remainder. + * @return array{string, string} An array containing the quotient and remainder. */ abstract public function divQR(string $a, string $b) : array; @@ -249,10 +212,7 @@ abstract class Calculator abstract public function pow(string $a, int $e) : string; /** - * @param string $a * @param string $b The modulus; must not be zero. - * - * @return string */ public function mod(string $a, string $b) : string { @@ -266,10 +226,7 @@ abstract class Calculator * * This method can be overridden by the concrete implementation if the underlying library has built-in support. * - * @param string $x * @param string $m The modulus; must not be negative or zero. - * - * @return string|null */ public function modInverse(string $x, string $m) : ?string { @@ -283,9 +240,7 @@ abstract class Calculator $modVal = $this->mod($x, $m); } - $x = '0'; - $y = '0'; - $g = $this->gcdExtended($modVal, $m, $x, $y); + [$g, $x] = $this->gcdExtended($modVal, $m); if ($g !== '1') { return null; @@ -300,8 +255,6 @@ abstract class Calculator * @param string $base The base number; must be positive or zero. * @param string $exp The exponent; must be positive or zero. * @param string $mod The modulus; must be strictly positive. - * - * @return string The power. */ abstract public function modPow(string $base, string $exp, string $mod) : string; @@ -311,9 +264,6 @@ abstract class Calculator * This method can be overridden by the concrete implementation if the underlying library * has built-in support for GCD calculations. * - * @param string $a The first number. - * @param string $b The second number. - * * @return string The GCD, always positive, or zero if both arguments are zero. */ public function gcd(string $a, string $b) : string @@ -329,24 +279,21 @@ abstract class Calculator return $this->gcd($b, $this->divR($a, $b)); } - private function gcdExtended(string $a, string $b, string &$x, string &$y) : string + /** + * @return array{string, string, string} GCD, X, Y + */ + private function gcdExtended(string $a, string $b) : array { if ($a === '0') { - $x = '0'; - $y = '1'; - - return $b; + return [$b, '0', '1']; } - $x1 = '0'; - $y1 = '0'; - - $gcd = $this->gcdExtended($this->mod($b, $a), $a, $x1, $y1); + [$gcd, $x1, $y1] = $this->gcdExtended($this->mod($b, $a), $a); $x = $this->sub($y1, $this->mul($this->divQ($b, $a), $x1)); $y = $x1; - return $gcd; + return [$gcd, $x, $y]; } /** @@ -354,10 +301,6 @@ abstract class Calculator * * The result is the largest x such that x² ≤ n. * The input MUST NOT be negative. - * - * @param string $n The number. - * - * @return string The square root. */ abstract public function sqrt(string $n) : string; @@ -489,10 +432,10 @@ abstract class Calculator * @param string $b The divisor, must not be zero. * @param int $roundingMode The rounding mode. * - * @return string - * * @throws \InvalidArgumentException If the rounding mode is invalid. * @throws RoundingNecessaryException If RoundingMode::UNNECESSARY is provided but rounding is necessary. + * + * @psalm-suppress ImpureFunctionCall */ final public function divRound(string $a, string $b, int $roundingMode) : string { @@ -570,11 +513,6 @@ abstract class Calculator * * This method can be overridden by the concrete implementation if the underlying library * has built-in support for bitwise operations. - * - * @param string $a - * @param string $b - * - * @return string */ public function and(string $a, string $b) : string { @@ -586,11 +524,6 @@ abstract class Calculator * * This method can be overridden by the concrete implementation if the underlying library * has built-in support for bitwise operations. - * - * @param string $a - * @param string $b - * - * @return string */ public function or(string $a, string $b) : string { @@ -602,11 +535,6 @@ abstract class Calculator * * This method can be overridden by the concrete implementation if the underlying library * has built-in support for bitwise operations. - * - * @param string $a - * @param string $b - * - * @return string */ public function xor(string $a, string $b) : string { @@ -616,11 +544,9 @@ abstract class Calculator /** * Performs a bitwise operation on a decimal number. * - * @param string $operator The operator to use, must be "and", "or" or "xor". - * @param string $a The left operand. - * @param string $b The right operand. - * - * @return string + * @param 'and'|'or'|'xor' $operator The operator to use. + * @param string $a The left operand. + * @param string $b The right operand. */ private function bitwise(string $operator, string $a, string $b) : string { @@ -678,8 +604,6 @@ abstract class Calculator /** * @param string $number A positive, binary number. - * - * @return string */ private function twosComplement(string $number) : string { @@ -709,8 +633,6 @@ abstract class Calculator * Converts a decimal number to a binary string. * * @param string $number The number to convert, positive or zero, only digits. - * - * @return string */ private function toBinary(string $number) : string { @@ -728,8 +650,6 @@ abstract class Calculator * Returns the positive decimal representation of a binary number. * * @param string $bytes The bytes representing the number. - * - * @return string */ private function toDecimal(string $bytes) : string { |