aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/brick/math/src/Internal/Calculator
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/brick/math/src/Internal/Calculator')
-rw-r--r--vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php47
-rw-r--r--vendor/brick/math/src/Internal/Calculator/GmpCalculator.php48
-rw-r--r--vendor/brick/math/src/Internal/Calculator/NativeCalculator.php57
3 files changed, 5 insertions, 147 deletions
diff --git a/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php b/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php
index 6632b378a..5457a3c98 100644
--- a/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php
+++ b/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php
@@ -15,99 +15,58 @@ use Brick\Math\Internal\Calculator;
*/
class BcMathCalculator extends Calculator
{
- /**
- * {@inheritdoc}
- */
public function add(string $a, string $b) : string
{
return \bcadd($a, $b, 0);
}
- /**
- * {@inheritdoc}
- */
public function sub(string $a, string $b) : string
{
return \bcsub($a, $b, 0);
}
- /**
- * {@inheritdoc}
- */
public function mul(string $a, string $b) : string
{
return \bcmul($a, $b, 0);
}
- /**
- * {@inheritdoc}
- *
- * @psalm-suppress InvalidNullableReturnType
- * @psalm-suppress NullableReturnStatement
- */
public function divQ(string $a, string $b) : string
{
return \bcdiv($a, $b, 0);
}
/**
- * {@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);
+ return \bcmod($a, $b, 0);
}
- /**
- * {@inheritdoc}
- */
public function divQR(string $a, string $b) : array
{
$q = \bcdiv($a, $b, 0);
+ $r = \bcmod($a, $b, 0);
- 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];
}
- /**
- * {@inheritdoc}
- */
public function pow(string $a, int $e) : string
{
return \bcpow($a, (string) $e, 0);
}
- /**
- * {@inheritdoc}
- *
- * @psalm-suppress InvalidNullableReturnType
- * @psalm-suppress NullableReturnStatement
- */
public function modPow(string $base, string $exp, string $mod) : string
{
return \bcpowmod($base, $exp, $mod, 0);
}
/**
- * {@inheritDoc}
- *
- * @psalm-suppress NullableReturnStatement
* @psalm-suppress InvalidNullableReturnType
+ * @psalm-suppress NullableReturnStatement
*/
public function sqrt(string $n) : string
{
diff --git a/vendor/brick/math/src/Internal/Calculator/GmpCalculator.php b/vendor/brick/math/src/Internal/Calculator/GmpCalculator.php
index 52d18800a..42d4c6927 100644
--- a/vendor/brick/math/src/Internal/Calculator/GmpCalculator.php
+++ b/vendor/brick/math/src/Internal/Calculator/GmpCalculator.php
@@ -15,49 +15,31 @@ use Brick\Math\Internal\Calculator;
*/
class GmpCalculator extends Calculator
{
- /**
- * {@inheritdoc}
- */
public function add(string $a, string $b) : string
{
return \gmp_strval(\gmp_add($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function sub(string $a, string $b) : string
{
return \gmp_strval(\gmp_sub($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function mul(string $a, string $b) : string
{
return \gmp_strval(\gmp_mul($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function divQ(string $a, string $b) : string
{
return \gmp_strval(\gmp_div_q($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function divR(string $a, string $b) : string
{
return \gmp_strval(\gmp_div_r($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function divQR(string $a, string $b) : array
{
[$q, $r] = \gmp_div_qr($a, $b);
@@ -68,17 +50,11 @@ class GmpCalculator extends Calculator
];
}
- /**
- * {@inheritdoc}
- */
public function pow(string $a, int $e) : string
{
return \gmp_strval(\gmp_pow($a, $e));
}
- /**
- * {@inheritdoc}
- */
public function modInverse(string $x, string $m) : ?string
{
$result = \gmp_invert($x, $m);
@@ -90,65 +66,41 @@ class GmpCalculator extends Calculator
return \gmp_strval($result);
}
- /**
- * {@inheritdoc}
- */
public function modPow(string $base, string $exp, string $mod) : string
{
return \gmp_strval(\gmp_powm($base, $exp, $mod));
}
- /**
- * {@inheritdoc}
- */
public function gcd(string $a, string $b) : string
{
return \gmp_strval(\gmp_gcd($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function fromBase(string $number, int $base) : string
{
return \gmp_strval(\gmp_init($number, $base));
}
- /**
- * {@inheritdoc}
- */
public function toBase(string $number, int $base) : string
{
return \gmp_strval($number, $base);
}
- /**
- * {@inheritdoc}
- */
public function and(string $a, string $b) : string
{
return \gmp_strval(\gmp_and($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function or(string $a, string $b) : string
{
return \gmp_strval(\gmp_or($a, $b));
}
- /**
- * {@inheritdoc}
- */
public function xor(string $a, string $b) : string
{
return \gmp_strval(\gmp_xor($a, $b));
}
- /**
- * {@inheritDoc}
- */
public function sqrt(string $n) : string
{
return \gmp_strval(\gmp_sqrt($n));
diff --git a/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php b/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
index 020a6338b..7c679d24d 100644
--- a/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
+++ b/vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
@@ -19,17 +19,13 @@ class NativeCalculator extends Calculator
* The max number of digits the platform can natively add, subtract, multiply or divide without overflow.
* For multiplication, this represents the max sum of the lengths of both operands.
*
- * For addition, it is assumed that an extra digit can hold a carry (1) without overflowing.
+ * In addition, it is assumed that an extra digit can hold a carry (1) without overflowing.
* Example: 32-bit: max number 1,999,999,999 (9 digits + carry)
* 64-bit: max number 1,999,999,999,999,999,999 (18 digits + carry)
- *
- * @var int
*/
- private $maxDigits;
+ private int $maxDigits;
/**
- * Class constructor.
- *
* @codeCoverageIgnore
*/
public function __construct()
@@ -48,9 +44,6 @@ class NativeCalculator extends Calculator
}
}
- /**
- * {@inheritdoc}
- */
public function add(string $a, string $b) : string
{
/**
@@ -82,17 +75,11 @@ class NativeCalculator extends Calculator
return $result;
}
- /**
- * {@inheritdoc}
- */
public function sub(string $a, string $b) : string
{
return $this->add($a, $this->neg($b));
}
- /**
- * {@inheritdoc}
- */
public function mul(string $a, string $b) : string
{
/**
@@ -136,25 +123,16 @@ class NativeCalculator extends Calculator
return $result;
}
- /**
- * {@inheritdoc}
- */
public function divQ(string $a, string $b) : string
{
return $this->divQR($a, $b)[0];
}
- /**
- * {@inheritdoc}
- */
public function divR(string $a, string $b): string
{
return $this->divQR($a, $b)[1];
}
- /**
- * {@inheritdoc}
- */
public function divQR(string $a, string $b) : array
{
if ($a === '0') {
@@ -210,9 +188,6 @@ class NativeCalculator extends Calculator
return [$q, $r];
}
- /**
- * {@inheritdoc}
- */
public function pow(string $a, int $e) : string
{
if ($e === 0) {
@@ -240,8 +215,6 @@ class NativeCalculator extends Calculator
/**
* Algorithm from: https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
- *
- * {@inheritdoc}
*/
public function modPow(string $base, string $exp, string $mod) : string
{
@@ -276,8 +249,6 @@ class NativeCalculator extends Calculator
/**
* Adapted from https://cp-algorithms.com/num_methods/roots_newton.html
- *
- * {@inheritDoc}
*/
public function sqrt(string $n) : string
{
@@ -306,11 +277,6 @@ class NativeCalculator extends Calculator
/**
* Performs the addition of two non-signed large integers.
- *
- * @param string $a The first operand.
- * @param string $b The second operand.
- *
- * @return string
*/
private function doAdd(string $a, string $b) : string
{
@@ -363,11 +329,6 @@ class NativeCalculator extends Calculator
/**
* Performs the subtraction of two non-signed large integers.
- *
- * @param string $a The first operand.
- * @param string $b The second operand.
- *
- * @return string
*/
private function doSub(string $a, string $b) : string
{
@@ -445,11 +406,6 @@ class NativeCalculator extends Calculator
/**
* Performs the multiplication of two non-signed large integers.
- *
- * @param string $a The first operand.
- * @param string $b The second operand.
- *
- * @return string
*/
private function doMul(string $a, string $b) : string
{
@@ -522,9 +478,6 @@ class NativeCalculator extends Calculator
/**
* Performs the division of two non-signed large integers.
*
- * @param string $a The first operand.
- * @param string $b The second operand.
- *
* @return string[] The quotient and remainder.
*/
private function doDiv(string $a, string $b) : array
@@ -583,9 +536,6 @@ class NativeCalculator extends Calculator
/**
* Compares two non-signed large numbers.
*
- * @param string $a The first operand.
- * @param string $b The second operand.
- *
* @return int [-1, 0, 1]
*/
private function doCmp(string $a, string $b) : int
@@ -607,9 +557,6 @@ class NativeCalculator extends Calculator
*
* The numbers must only consist of digits, without leading minus sign.
*
- * @param string $a The first operand.
- * @param string $b The second operand.
- *
* @return array{string, string, int}
*/
private function pad(string $a, string $b) : array