Number
final class Number implements Stringable (View source)
A class for an arbitrary precision number. These objects support overloaded arithmetic and comparison operators.
Properties
| numeric-string | $value | ||
| int | $scale |
Methods
Creates a BcMath\Number object
Rounds an arbitrary precision number
Converts BcMath\Number to string
Serializes a BcMath\Number object
Deserializes a data parameter into a BcMath\Number object
Details
__construct(string|int $num)
Creates a BcMath\Number object
Creates a BcMath\Number object from an int or string value.
Number
add(Number|string|int $num, int|null $scale = null)
Adds an arbitrary precision number
Adds $this and num.
Number
sub(Number|string|int $num, int|null $scale = null)
Subtracts an arbitrary precision number
Subtracts num from $this.
Number
mul(Number|string|int $num, int|null $scale = null)
Multiplies an arbitrary precision number
Multiplies $this by num.
Number
div(Number|string|int $num, int|null $scale = null)
Divides by an arbitrary precision number
Divides $this by num.
Number
mod(Number|string|int $num, int|null $scale = null)
Gets the modulus of an arbitrary precision number
Gets the remainder of dividing $this by num. Unless num is 0, the result has the same sign as $this.
array
divmod(Number|string|int $num, int|null $scale = null)
Gets the quotient and modulus of an arbitrary precision number
Gets the quotient and remainder of dividing $this by num.
Number
powmod(Number|string|int $exponent, Number|string|int $modulus, int|null $scale = null)
Raises an arbitrary precision number, reduced by a specified modulus
Use the fast-exponentiation method to raise $this to the power exponent with respect to the modulus modulus.
Number
pow(Number|string|int $exponent, int|null $scale = null)
Raises an arbitrary precision number
Raises $this to the exponent power.
Number
sqrt(int|null $scale = null)
Gets the square root of an arbitrary precision number
Return the square root of $this.
Number
floor()
Rounds down an arbitrary precision number
Returns the next highest integer value by rounding down $this if necessary.
Number
ceil()
Rounds up an arbitrary precision number
Returns the next highest integer value by rounding up $this if necessary.
Number
round(int $precision = 0, RoundingMode $mode = \RoundingMode::HalfAwayFromZero)
Rounds an arbitrary precision number
Returns the rounded value of $this to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).
int
compare(Number|string|int $num, int|null $scale = null)
Compares two arbitrary precision numbers
Compare two arbitrary precision numbers. This method behaves similar to the spaceship operator.
string
__toString()
Converts BcMath\Number to string
array
__serialize()
Serializes a BcMath\Number object
Serializes $this.
void
__unserialize(array $data)
Deserializes a data parameter into a BcMath\Number object