Skip to content

Commit

Permalink
Use type unions in api doc
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 25, 2022
1 parent 9b88894 commit 5d421e4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 65 deletions.
32 changes: 16 additions & 16 deletions src/main/php/math/BigFloat.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BigFloat extends BigNum {
/**
* Creates a new BigFloat instance
*
* @param string in
* @param int|float|string $in
*/
public function __construct($in) {
$this->num= false !== strpos($in, '.') ? rtrim(rtrim($in, '0'), '.') : (string)$in;
Expand All @@ -23,8 +23,8 @@ public function __construct($in) {
/**
* +
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function add($other) {
return new self(bcadd($this->num, $other instanceof self ? $other->num : $other));
Expand All @@ -33,8 +33,8 @@ public function add($other) {
/**
* -
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function subtract($other) {
return new self(bcsub($this->num, $other instanceof self ? $other->num : $other));
Expand All @@ -43,8 +43,8 @@ public function subtract($other) {
/**
* *
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function multiply($other) {
return new self(bcmul($this->num, $other instanceof self ? $other->num : $other));
Expand All @@ -53,8 +53,8 @@ public function multiply($other) {
/**
* /
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function divide($other) {
try {
Expand All @@ -72,9 +72,9 @@ public function divide($other) {
/**
* ^
*
* @see http://en.wikipedia.org/wiki/Exponentiation
* @param var other
* @return math.BigNum
* @see http://en.wikipedia.org/wiki/Exponentiation
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function power($other) {
return new self(bcpow($this->num, $other instanceof self ? $other->num : $other));
Expand All @@ -83,7 +83,7 @@ public function power($other) {
/**
* Returns the next lowest "integer" value by rounding down value if necessary.
*
* @return math.BigFloat
* @return self
*/
public function ceil() {
return new self(false === strpos($this->num, '.')
Expand All @@ -95,7 +95,7 @@ public function ceil() {
/**
* Returns the next highest "integer" value by rounding up value if necessary
*
* @return math.BigFloat
* @return self
*/
public function floor() {
return new self(false === strpos($this->num, '.')
Expand All @@ -108,8 +108,8 @@ public function floor() {
* Returns the rounded value of val to specified precision (number of digits
* after the decimal point).
*
* @param int precision
* @return math.BigFloat
* @param int $precision
* @return self
*/
public function round($precision= 0) {
if (false === strpos($this->num, '.')) return new self($this->num);
Expand Down
64 changes: 32 additions & 32 deletions src/main/php/math/BigInt.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BigInt extends BigNum {
/**
* Creates a new BigInt instance
*
* @param string in
* @param int|float|string $in
*/
public function __construct($in) {
$this->num= substr($in, 0, strcspn($in, '.'));
Expand All @@ -23,8 +23,8 @@ public function __construct($in) {
/**
* +
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function add($other) {
if ($other instanceof self) {
Expand All @@ -41,8 +41,8 @@ public function add($other) {
/**
* -
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function subtract($other) {
if ($other instanceof self) {
Expand All @@ -59,8 +59,8 @@ public function subtract($other) {
/**
* *
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function multiply($other) {
if ($other instanceof self) {
Expand All @@ -77,8 +77,8 @@ public function multiply($other) {
/**
* /
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function divide($other) {
try {
Expand Down Expand Up @@ -119,8 +119,8 @@ public function divide($other) {
/**
* +(0), strictly integer addition
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function add0($other) {
return new self(bcadd($this->num, $other instanceof parent ? $other->num : $other, 0));
Expand All @@ -129,8 +129,8 @@ public function add0($other) {
/**
* -(0), strictly integer subtraction
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function subtract0($other) {
return new self(bcsub($this->num, $other instanceof parent ? $other->num : $other, 0));
Expand All @@ -139,8 +139,8 @@ public function subtract0($other) {
/**
* *(0), strictly integer multiplication
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function multiply0($other) {
return new self(bcmul($this->num, $other instanceof self ? $other->num : $other, 0));
Expand All @@ -149,8 +149,8 @@ public function multiply0($other) {
/**
* /
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function divide0($other) {
try {
Expand All @@ -169,8 +169,8 @@ public function divide0($other) {
* ^
*
* @see http://en.wikipedia.org/wiki/Exponentiation
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function power($other) {
if ($other instanceof self) {
Expand All @@ -193,8 +193,8 @@ public function power($other) {
/**
* %
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function modulo($other) {
try {
Expand All @@ -212,8 +212,8 @@ public function modulo($other) {
/**
* &
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function bitwiseAnd($other) {
$a= self::bytesOf($this->num);
Expand All @@ -225,8 +225,8 @@ public function bitwiseAnd($other) {
/**
* |
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function bitwiseOr($other) {
$a= self::bytesOf($this->num);
Expand All @@ -238,8 +238,8 @@ public function bitwiseOr($other) {
/**
* ^
*
* @param var other
* @return math.BigNum
* @param math.BigNum|int|float|string $other
* @return math.BigNum
*/
public function bitwiseXor($other) {
$a= self::bytesOf($this->num);
Expand All @@ -252,7 +252,7 @@ public function bitwiseXor($other) {
* >>
*
* @param var shift
* @return math.BigNum
* @return math.BigNum
*/
public function shiftRight($shift) {
return new self(bcdiv($this->num, bcpow(2, $shift instanceof self ? $shift->num : $shift, 0), 0));
Expand All @@ -262,7 +262,7 @@ public function shiftRight($shift) {
* <<
*
* @param var shift
* @return math.BigNum
* @return math.BigNum
*/
public function shiftLeft($shift) {
return new self(bcmul($this->num, bcpow(2, $shift instanceof self ? $shift->num : $shift, 0), 0));
Expand All @@ -273,7 +273,7 @@ public function shiftLeft($shift) {
*
* @see xp://math.BigNum#toBytes
* @param string bytes
* @return math.BigNum
* @return math.BigNum
*/
protected static function fromBytes($bytes) {
$len= strlen($bytes);
Expand All @@ -294,7 +294,7 @@ protected static function fromBytes($bytes) {
* Creates sequence of bytes from a bignum
*
* @see xp://math.BigNum#fromBytes
* @return string
* @return string
*/
protected static function bytesOf($n) {
$value= '';
Expand All @@ -308,7 +308,7 @@ protected static function bytesOf($n) {
/**
* Returns an byte representing this big integer
*
* @return int
* @return int
*/
public function byteValue() {
return $this->bitwiseAnd(0xFF)->intValue();
Expand Down
28 changes: 11 additions & 17 deletions src/main/php/math/BigNum.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,32 @@ static function __static() {
/**
* +
*
* @param var other
* @return math.BigNum
* @param self|int|float|string $other
* @return self
*/
public function add($other) {
return new static(bcadd($this->num, $other instanceof self ? $other->num : $other));
}
public abstract function add($other);

/**
* -
*
* @param var other
* @return math.BigNum
* @param self|int|float|string $other
* @return self
*/
public function subtract($other) {
return new static(bcsub($this->num, $other instanceof self ? $other->num : $other));
}
public abstract function subtract($other);

/**
* *
*
* @param var other
* @return math.BigNum
* @param self|int|float|string $other
* @return self
*/
public function multiply($other) {
return new static(bcmul($this->num, $other instanceof self ? $other->num : $other));
}
public abstract function multiply($other);

/**
* /
*
* @param var other
* @return math.BigNum
* @param self|int|float|string $other
* @return self
*/
public abstract function divide($other);

Expand Down

0 comments on commit 5d421e4

Please sign in to comment.