aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/brick/math/src/BigInteger.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/brick/math/src/BigInteger.php')
-rw-r--r--vendor/brick/math/src/BigInteger.php48
1 files changed, 10 insertions, 38 deletions
diff --git a/vendor/brick/math/src/BigInteger.php b/vendor/brick/math/src/BigInteger.php
index 435679331..73dcc89a2 100644
--- a/vendor/brick/math/src/BigInteger.php
+++ b/vendor/brick/math/src/BigInteger.php
@@ -27,7 +27,7 @@ final class BigInteger extends BigNumber
* No leading zeros must be present.
* No leading minus sign must be present if the number is zero.
*/
- private string $value;
+ private readonly string $value;
/**
* Protected constructor. Use a factory method to obtain an instance.
@@ -40,15 +40,11 @@ final class BigInteger extends BigNumber
}
/**
- * Creates a BigInteger of the given value.
- *
- * @throws MathException If the value cannot be converted to a BigInteger.
- *
* @psalm-pure
*/
- public static function of(BigNumber|int|float|string $value) : BigInteger
+ protected static function from(BigNumber $number): static
{
- return parent::of($value)->toBigInteger();
+ return $number->toBigInteger();
}
/**
@@ -225,9 +221,10 @@ final class BigInteger extends BigNumber
}
if ($randomBytesGenerator === null) {
- $randomBytesGenerator = 'random_bytes';
+ $randomBytesGenerator = random_bytes(...);
}
+ /** @var int<1, max> $byteLength */
$byteLength = \intdiv($numBits - 1, 8) + 1;
$extraBits = ($byteLength * 8 - $numBits);
@@ -429,12 +426,12 @@ final class BigInteger extends BigNumber
* Returns the result of the division of this number by the given one.
*
* @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger.
- * @param int $roundingMode An optional rounding mode.
+ * @param RoundingMode $roundingMode An optional rounding mode, defaults to UNNECESSARY.
*
* @throws MathException If the divisor is not a valid number, is not convertible to a BigInteger, is zero,
* or RoundingMode::UNNECESSARY is used and the remainder is not zero.
*/
- public function dividedBy(BigNumber|int|float|string $that, int $roundingMode = RoundingMode::UNNECESSARY) : BigInteger
+ public function dividedBy(BigNumber|int|float|string $that, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigInteger
{
$that = BigInteger::of($that);
@@ -534,6 +531,8 @@ final class BigInteger extends BigNumber
*
* @return BigInteger[] An array containing the quotient and the remainder.
*
+ * @psalm-return array{BigInteger, BigInteger}
+ *
* @throws DivisionByZeroException If the divisor is zero.
*/
public function quotientAndRemainder(BigNumber|int|float|string $that) : array
@@ -888,7 +887,7 @@ final class BigInteger extends BigNumber
return self::newBigRational($this, BigInteger::one(), false);
}
- public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
+ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
{
return $this->toBigDecimal()->toScale($scale, $roundingMode);
}
@@ -1049,31 +1048,4 @@ final class BigInteger extends BigNumber
$this->value = $data['value'];
}
-
- /**
- * This method is required by interface Serializable and SHOULD NOT be accessed directly.
- *
- * @internal
- */
- public function serialize() : string
- {
- return $this->value;
- }
-
- /**
- * This method is only here to implement interface Serializable and cannot be accessed directly.
- *
- * @internal
- * @psalm-suppress RedundantPropertyInitializationCheck
- *
- * @throws \LogicException
- */
- public function unserialize($value) : void
- {
- if (isset($this->value)) {
- throw new \LogicException('unserialize() is an internal function, it must not be called directly.');
- }
-
- $this->value = $value;
- }
}