aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/brick/math/src/BigRational.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/brick/math/src/BigRational.php')
-rw-r--r--vendor/brick/math/src/BigRational.php106
1 files changed, 14 insertions, 92 deletions
diff --git a/vendor/brick/math/src/BigRational.php b/vendor/brick/math/src/BigRational.php
index bee094f73..31f2904fa 100644
--- a/vendor/brick/math/src/BigRational.php
+++ b/vendor/brick/math/src/BigRational.php
@@ -20,17 +20,13 @@ final class BigRational extends BigNumber
{
/**
* The numerator.
- *
- * @var BigInteger
*/
- private $numerator;
+ private BigInteger $numerator;
/**
* The denominator. Always strictly positive.
- *
- * @var BigInteger
*/
- private $denominator;
+ private BigInteger $denominator;
/**
* Protected constructor. Use a factory method to obtain an instance.
@@ -61,15 +57,11 @@ final class BigRational extends BigNumber
/**
* Creates a BigRational of the given value.
*
- * @param BigNumber|int|float|string $value
- *
- * @return BigRational
- *
* @throws MathException If the value cannot be converted to a BigRational.
*
* @psalm-pure
*/
- public static function of($value) : BigNumber
+ public static function of(BigNumber|int|float|string $value) : BigRational
{
return parent::of($value)->toBigRational();
}
@@ -83,16 +75,16 @@ final class BigRational extends BigNumber
* @param BigNumber|int|float|string $numerator The numerator. Must be convertible to a BigInteger.
* @param BigNumber|int|float|string $denominator The denominator. Must be convertible to a BigInteger.
*
- * @return BigRational
- *
* @throws NumberFormatException If an argument does not represent a valid number.
* @throws RoundingNecessaryException If an argument represents a non-integer number.
* @throws DivisionByZeroException If the denominator is zero.
*
* @psalm-pure
*/
- public static function nd($numerator, $denominator) : BigRational
- {
+ public static function nd(
+ BigNumber|int|float|string $numerator,
+ BigNumber|int|float|string $denominator,
+ ) : BigRational {
$numerator = BigInteger::of($numerator);
$denominator = BigInteger::of($denominator);
@@ -102,8 +94,6 @@ final class BigRational extends BigNumber
/**
* Returns a BigRational representing zero.
*
- * @return BigRational
- *
* @psalm-pure
*/
public static function zero() : BigRational
@@ -124,8 +114,6 @@ final class BigRational extends BigNumber
/**
* Returns a BigRational representing one.
*
- * @return BigRational
- *
* @psalm-pure
*/
public static function one() : BigRational
@@ -146,8 +134,6 @@ final class BigRational extends BigNumber
/**
* Returns a BigRational representing ten.
*
- * @return BigRational
- *
* @psalm-pure
*/
public static function ten() : BigRational
@@ -165,17 +151,11 @@ final class BigRational extends BigNumber
return $ten;
}
- /**
- * @return BigInteger
- */
public function getNumerator() : BigInteger
{
return $this->numerator;
}
- /**
- * @return BigInteger
- */
public function getDenominator() : BigInteger
{
return $this->denominator;
@@ -183,8 +163,6 @@ final class BigRational extends BigNumber
/**
* Returns the quotient of the division of the numerator by the denominator.
- *
- * @return BigInteger
*/
public function quotient() : BigInteger
{
@@ -193,8 +171,6 @@ final class BigRational extends BigNumber
/**
* Returns the remainder of the division of the numerator by the denominator.
- *
- * @return BigInteger
*/
public function remainder() : BigInteger
{
@@ -216,11 +192,9 @@ final class BigRational extends BigNumber
*
* @param BigNumber|int|float|string $that The number to add.
*
- * @return BigRational The result.
- *
* @throws MathException If the number is not valid.
*/
- public function plus($that) : BigRational
+ public function plus(BigNumber|int|float|string $that) : BigRational
{
$that = BigRational::of($that);
@@ -236,11 +210,9 @@ final class BigRational extends BigNumber
*
* @param BigNumber|int|float|string $that The number to subtract.
*
- * @return BigRational The result.
- *
* @throws MathException If the number is not valid.
*/
- public function minus($that) : BigRational
+ public function minus(BigNumber|int|float|string $that) : BigRational
{
$that = BigRational::of($that);
@@ -256,11 +228,9 @@ final class BigRational extends BigNumber
*
* @param BigNumber|int|float|string $that The multiplier.
*
- * @return BigRational The result.
- *
* @throws MathException If the multiplier is not a valid number.
*/
- public function multipliedBy($that) : BigRational
+ public function multipliedBy(BigNumber|int|float|string $that) : BigRational
{
$that = BigRational::of($that);
@@ -275,11 +245,9 @@ final class BigRational extends BigNumber
*
* @param BigNumber|int|float|string $that The divisor.
*
- * @return BigRational The result.
- *
* @throws MathException If the divisor is not a valid number, or is zero.
*/
- public function dividedBy($that) : BigRational
+ public function dividedBy(BigNumber|int|float|string $that) : BigRational
{
$that = BigRational::of($that);
@@ -292,10 +260,6 @@ final class BigRational extends BigNumber
/**
* Returns this number exponentiated to the given value.
*
- * @param int $exponent The exponent.
- *
- * @return BigRational The result.
- *
* @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
*/
public function power(int $exponent) : BigRational
@@ -322,8 +286,6 @@ final class BigRational extends BigNumber
*
* The reciprocal has the numerator and denominator swapped.
*
- * @return BigRational
- *
* @throws DivisionByZeroException If the numerator is zero.
*/
public function reciprocal() : BigRational
@@ -333,8 +295,6 @@ final class BigRational extends BigNumber
/**
* Returns the absolute value of this BigRational.
- *
- * @return BigRational
*/
public function abs() : BigRational
{
@@ -343,8 +303,6 @@ final class BigRational extends BigNumber
/**
* Returns the negated value of this BigRational.
- *
- * @return BigRational
*/
public function negated() : BigRational
{
@@ -353,8 +311,6 @@ final class BigRational extends BigNumber
/**
* Returns the simplified value of this BigRational.
- *
- * @return BigRational
*/
public function simplified() : BigRational
{
@@ -366,25 +322,16 @@ final class BigRational extends BigNumber
return new BigRational($numerator, $denominator, false);
}
- /**
- * {@inheritdoc}
- */
- public function compareTo($that) : int
+ public function compareTo(BigNumber|int|float|string $that) : int
{
return $this->minus($that)->getSign();
}
- /**
- * {@inheritdoc}
- */
public function getSign() : int
{
return $this->numerator->getSign();
}
- /**
- * {@inheritdoc}
- */
public function toBigInteger() : BigInteger
{
$simplified = $this->simplified();
@@ -396,49 +343,32 @@ final class BigRational extends BigNumber
return $simplified->numerator;
}
- /**
- * {@inheritdoc}
- */
public function toBigDecimal() : BigDecimal
{
return $this->numerator->toBigDecimal()->exactlyDividedBy($this->denominator);
}
- /**
- * {@inheritdoc}
- */
public function toBigRational() : BigRational
{
return $this;
}
- /**
- * {@inheritdoc}
- */
public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
{
return $this->numerator->toBigDecimal()->dividedBy($this->denominator, $scale, $roundingMode);
}
- /**
- * {@inheritdoc}
- */
public function toInt() : int
{
return $this->toBigInteger()->toInt();
}
- /**
- * {@inheritdoc}
- */
public function toFloat() : float
{
- return $this->numerator->toFloat() / $this->denominator->toFloat();
+ $simplified = $this->simplified();
+ return $simplified->numerator->toFloat() / $simplified->denominator->toFloat();
}
- /**
- * {@inheritdoc}
- */
public function __toString() : string
{
$numerator = (string) $this->numerator;
@@ -471,8 +401,6 @@ final class BigRational extends BigNumber
*
* @param array{numerator: BigInteger, denominator: BigInteger} $data
*
- * @return void
- *
* @throws \LogicException
*/
public function __unserialize(array $data): void
@@ -489,8 +417,6 @@ final class BigRational extends BigNumber
* This method is required by interface Serializable and SHOULD NOT be accessed directly.
*
* @internal
- *
- * @return string
*/
public function serialize() : string
{
@@ -503,10 +429,6 @@ final class BigRational extends BigNumber
* @internal
* @psalm-suppress RedundantPropertyInitializationCheck
*
- * @param string $value
- *
- * @return void
- *
* @throws \LogicException
*/
public function unserialize($value) : void