Skip to content

Commit

Permalink
Final BigNumber public/protected methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Nov 19, 2023
1 parent 96bdecb commit 70843ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- The following breaking changes only affect you if you're creating your own `BigNumber` subclasses:
- the return type of `BigNumber::of()` is now `static`
- `BigNumber` has a new abstract method `from()`
- all `public` and `protected` functions of `BigNumber` are now `final`

## [0.11.0](https://github.com/brick/math/releases/tag/0.11.0) - 2023-01-16

Expand Down
36 changes: 18 additions & 18 deletions src/BigNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class BigNumber implements \JsonSerializable
*
* @psalm-pure
*/
public static function of(BigNumber|int|float|string $value) : static
final public static function of(BigNumber|int|float|string $value) : static
{
$value = self::_of($value);

Expand Down Expand Up @@ -177,7 +177,7 @@ abstract protected static function from(BigNumber $number): static;
* @internal
* @psalm-pure
*/
protected function newBigInteger(string $value) : BigInteger
final protected function newBigInteger(string $value) : BigInteger
{
return new BigInteger($value);
}
Expand All @@ -188,7 +188,7 @@ protected function newBigInteger(string $value) : BigInteger
* @internal
* @psalm-pure
*/
protected function newBigDecimal(string $value, int $scale = 0) : BigDecimal
final protected function newBigDecimal(string $value, int $scale = 0) : BigDecimal
{
return new BigDecimal($value, $scale);
}
Expand All @@ -199,7 +199,7 @@ protected function newBigDecimal(string $value, int $scale = 0) : BigDecimal
* @internal
* @psalm-pure
*/
protected function newBigRational(BigInteger $numerator, BigInteger $denominator, bool $checkDenominator) : BigRational
final protected function newBigRational(BigInteger $numerator, BigInteger $denominator, bool $checkDenominator) : BigRational
{
return new BigRational($numerator, $denominator, $checkDenominator);
}
Expand All @@ -215,7 +215,7 @@ protected function newBigRational(BigInteger $numerator, BigInteger $denominator
*
* @psalm-pure
*/
public static function min(BigNumber|int|float|string ...$values) : static
final public static function min(BigNumber|int|float|string ...$values) : static
{
$min = null;

Expand Down Expand Up @@ -245,7 +245,7 @@ public static function min(BigNumber|int|float|string ...$values) : static
*
* @psalm-pure
*/
public static function max(BigNumber|int|float|string ...$values) : static
final public static function max(BigNumber|int|float|string ...$values) : static
{
$max = null;

Expand Down Expand Up @@ -275,7 +275,7 @@ public static function max(BigNumber|int|float|string ...$values) : static
*
* @psalm-pure
*/
public static function sum(BigNumber|int|float|string ...$values) : static
final public static function sum(BigNumber|int|float|string ...$values) : static
{
/** @var static|null $sum */
$sum = null;
Expand Down Expand Up @@ -357,79 +357,79 @@ private static function cleanUp(string $number) : string
/**
* Checks if this number is equal to the given one.
*/
public function isEqualTo(BigNumber|int|float|string $that) : bool
final public function isEqualTo(BigNumber|int|float|string $that) : bool
{
return $this->compareTo($that) === 0;
}

/**
* Checks if this number is strictly lower than the given one.
*/
public function isLessThan(BigNumber|int|float|string $that) : bool
final public function isLessThan(BigNumber|int|float|string $that) : bool
{
return $this->compareTo($that) < 0;
}

/**
* Checks if this number is lower than or equal to the given one.
*/
public function isLessThanOrEqualTo(BigNumber|int|float|string $that) : bool
final public function isLessThanOrEqualTo(BigNumber|int|float|string $that) : bool
{
return $this->compareTo($that) <= 0;
}

/**
* Checks if this number is strictly greater than the given one.
*/
public function isGreaterThan(BigNumber|int|float|string $that) : bool
final public function isGreaterThan(BigNumber|int|float|string $that) : bool
{
return $this->compareTo($that) > 0;
}

/**
* Checks if this number is greater than or equal to the given one.
*/
public function isGreaterThanOrEqualTo(BigNumber|int|float|string $that) : bool
final public function isGreaterThanOrEqualTo(BigNumber|int|float|string $that) : bool
{
return $this->compareTo($that) >= 0;
}

/**
* Checks if this number equals zero.
*/
public function isZero() : bool
final public function isZero() : bool
{
return $this->getSign() === 0;
}

/**
* Checks if this number is strictly negative.
*/
public function isNegative() : bool
final public function isNegative() : bool
{
return $this->getSign() < 0;
}

/**
* Checks if this number is negative or zero.
*/
public function isNegativeOrZero() : bool
final public function isNegativeOrZero() : bool
{
return $this->getSign() <= 0;
}

/**
* Checks if this number is strictly positive.
*/
public function isPositive() : bool
final public function isPositive() : bool
{
return $this->getSign() > 0;
}

/**
* Checks if this number is positive or zero.
*/
public function isPositiveOrZero() : bool
final public function isPositiveOrZero() : bool
{
return $this->getSign() >= 0;
}
Expand Down Expand Up @@ -513,7 +513,7 @@ abstract public function toFloat() : float;
*/
abstract public function __toString() : string;

public function jsonSerialize() : string
final public function jsonSerialize() : string
{
return $this->__toString();
}
Expand Down

0 comments on commit 70843ed

Please sign in to comment.