aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/brick/math/src/Internal/Calculator.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/brick/math/src/Internal/Calculator.php')
-rw-r--r--vendor/brick/math/src/Internal/Calculator.php44
1 files changed, 18 insertions, 26 deletions
diff --git a/vendor/brick/math/src/Internal/Calculator.php b/vendor/brick/math/src/Internal/Calculator.php
index b8cecda96..44dd66924 100644
--- a/vendor/brick/math/src/Internal/Calculator.php
+++ b/vendor/brick/math/src/Internal/Calculator.php
@@ -25,7 +25,7 @@ abstract class Calculator
/**
* The maximum exponent value allowed for the pow() method.
*/
- public const MAX_POWER = 1000000;
+ public const MAX_POWER = 1_000_000;
/**
* The alphabet for converting from and to base 2 to 36, lowercase.
@@ -128,7 +128,9 @@ abstract class Calculator
/**
* Compares two numbers.
*
- * @return int [-1, 0, 1] If the first number is less than, equal to, or greater than the second number.
+ * @psalm-return -1|0|1
+ *
+ * @return int -1 if the first number is less than, 0 if equal to, 1 if greater than the second number.
*/
final public function cmp(string $a, string $b) : int
{
@@ -428,16 +430,16 @@ abstract class Calculator
*
* Rounding is performed when the remainder of the division is not zero.
*
- * @param string $a The dividend.
- * @param string $b The divisor, must not be zero.
- * @param int $roundingMode The rounding mode.
+ * @param string $a The dividend.
+ * @param string $b The divisor, must not be zero.
+ * @param RoundingMode $roundingMode The rounding mode.
*
* @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
+ final public function divRound(string $a, string $b, RoundingMode $roundingMode) : string
{
[$quotient, $remainder] = $this->divQR($a, $b);
@@ -571,27 +573,17 @@ abstract class Calculator
$bBin = $this->twosComplement($bBin);
}
- switch ($operator) {
- case 'and':
- $value = $aBin & $bBin;
- $negative = ($aNeg and $bNeg);
- break;
-
- case 'or':
- $value = $aBin | $bBin;
- $negative = ($aNeg or $bNeg);
- break;
-
- case 'xor':
- $value = $aBin ^ $bBin;
- $negative = ($aNeg xor $bNeg);
- break;
+ $value = match ($operator) {
+ 'and' => $aBin & $bBin,
+ 'or' => $aBin | $bBin,
+ 'xor' => $aBin ^ $bBin,
+ };
- // @codeCoverageIgnoreStart
- default:
- throw new \InvalidArgumentException('Invalid bitwise operator.');
- // @codeCoverageIgnoreEnd
- }
+ $negative = match ($operator) {
+ 'and' => $aNeg and $bNeg,
+ 'or' => $aNeg or $bNeg,
+ 'xor' => $aNeg xor $bNeg,
+ };
if ($negative) {
$value = $this->twosComplement($value);