Represents a number for use with Binary Calculator computations

link http://www.php.net/bcmath

 Methods

Constructs a BigNumber object from a string, integer, float, or any object that may be cast to a string, resulting in a numeric string value

__construct(mixed $number, int $scale) : void

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

$scale

int

(optional) Specifies the default number of digits after the decimal place to be used in operations for this BigNumber

Returns the string value of this BigNumber

__toString() : string

Returns

stringString representation of the number in base 10

Sets the current number to the absolute value of itself

abs() : \Moontoast\Math\BigNumber

Returns

\Moontoast\Math\BigNumberfor fluent interface

Adds the given number to the current number

add(mixed $number) : \Moontoast\Math\BigNumber
link http://www.php.net/bcadd

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

\Moontoast\Math\BigNumberfor fluent interface

Converts a number between arbitrary bases (from 2 to 36)

baseConvert(string | int $number, int $fromBase, int $toBase) : string
Static

Parameters

$number

stringint

The number to convert

$fromBase

int

(optional) The base $number is in; defaults to 10

$toBase

int

(optional) The base to convert $number to; defaults to 16

Returns

string

Finds the next highest integer value by rounding up the current number if necessary

ceil() : \Moontoast\Math\BigNumber
link http://www.php.net/ceil

Returns

\Moontoast\Math\BigNumberfor fluent interface

Compares the current number with the given number

compareTo(mixed $number) : int

Returns 0 if the two operands are equal, 1 if the current number is larger than the given number, -1 otherwise.

link http://www.php.net/bccomp

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

int

Converts a base-10 number to an arbitrary base (from 2 to 36)

convertFromBase10(string | int $number, int $toBase) : string
Static

Parameters

$number

stringint

The number to convert

$toBase

int

The base to convert $number to

Exceptions

\InvalidArgumentException if $toBase is outside the range 2 to 36

Returns

string

Returns the current value converted to an arbitrary base

convertToBase(int $base) : string

Parameters

$base

int

The base to convert the current number to

Returns

stringString representation of the number in the given base

Converts a number from an arbitrary base (from 2 to 36) to base 10

convertToBase10(string | int $number, int $fromBase) : string
Static

Parameters

$number

stringint

The number to convert

$fromBase

int

The base $number is in

Exceptions

\InvalidArgumentException if $fromBase is outside the range 2 to 36

Returns

string

Decreases the value of the current number by one

decrement() : \Moontoast\Math\BigNumber

Returns

\Moontoast\Math\BigNumberfor fluent interface

Divides the current number by the given number

divide(mixed $number) : \Moontoast\Math\BigNumber
link http://www.php.net/bcdiv

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Exceptions

\Moontoast\Math\Exception\ArithmeticException if $number is zero

Returns

\Moontoast\Math\BigNumberfor fluent interface

Finds the next lowest integer value by rounding down the current number if necessary

floor() : \Moontoast\Math\BigNumber
link http://www.php.net/floor

Returns

\Moontoast\Math\BigNumberfor fluent interface

Returns the scale used for this BigNumber

getScale() : int

If no scale was set, this will default to the value of bcmath.scale in php.ini.

Returns

int

Returns the current raw value of this BigNumber

getValue() : string

Returns

stringString representation of the number in base 10

Increases the value of the current number by one

increment() : \Moontoast\Math\BigNumber

Returns

\Moontoast\Math\BigNumberfor fluent interface

Returns true if the current number equals the given number

isEqualTo(mixed $number) : bool

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

bool

Returns true if the current number is greater than the given number

isGreaterThan(mixed $number) : bool

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

bool

Returns true if the current number is greater than or equal to the given number

isGreaterThanOrEqualTo(mixed $number) : bool

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

bool

Returns true if the current number is less than the given number

isLessThan(mixed $number) : bool

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

bool

Returns true if the current number is less than or equal to the given number

isLessThanOrEqualTo(mixed $number) : bool

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

bool

Returns true if the current number is a negative number

isNegative() : bool

Returns

bool

Returns true if the current number is a positive number

isPositive() : bool

Returns

bool

Finds the modulus of the current number divided by the given number

mod(mixed $number) : \Moontoast\Math\BigNumber
link http://www.php.net/bcmod

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Exceptions

\Moontoast\Math\Exception\ArithmeticException if $number is zero

Returns

\Moontoast\Math\BigNumberfor fluent interface

Multiplies the current number by the given number

multiply(mixed $number) : \Moontoast\Math\BigNumber
link http://www.php.net/bcmul

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

\Moontoast\Math\BigNumberfor fluent interface

Sets the current number to the negative value of itself

negate() : \Moontoast\Math\BigNumber

Returns

\Moontoast\Math\BigNumberfor fluent interface

Raises current number to the given number

pow(mixed $number) : \Moontoast\Math\BigNumber
link http://www.php.net/bcpow

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

\Moontoast\Math\BigNumberfor fluent interface

Raises the current number to the $pow, then divides by the $mod to find the modulus

powMod(mixed $pow, mixed $mod) : \Moontoast\Math\BigNumber

This is functionally equivalent to the following code:

    $n = new BigNumber(1234);
    $n->mod($n->pow(32), 2);

However, it uses bcpowmod(), so it is faster and can accept larger parameters.

link http://www.php.net/bcpowmod

Parameters

$pow

mixed

May be of any type that can be cast to a string representation of a base 10 number

$mod

mixed

May be of any type that can be cast to a string representation of a base 10 number

Exceptions

\Moontoast\Math\Exception\ArithmeticException if $number is zero

Returns

\Moontoast\Math\BigNumberfor fluent interface

Rounds the current number to the nearest integer

round() : \Moontoast\Math\BigNumber
todo Implement precision digits

Returns

\Moontoast\Math\BigNumberfor fluent interface

Changes the default scale used by all Binary Calculator functions

setDefaultScale(int $scale) : void
Static

Parameters

$scale

int

Sets the scale of this BigNumber

setScale(int $scale) : \Moontoast\Math\BigNumber

Parameters

$scale

int

Specifies the default number of digits after the decimal place to be used in operations for this BigNumber

Returns

\Moontoast\Math\BigNumberfor fluent interface

Sets the value of this BigNumber to a new value

setValue(mixed $number) : \Moontoast\Math\BigNumber

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

\Moontoast\Math\BigNumberfor fluent interface

Shifts the current number $bits to the left

shiftLeft(int $bits) : \Moontoast\Math\BigNumber

Parameters

$bits

int

Returns

\Moontoast\Math\BigNumberfor fluent interface

Shifts the current number $bits to the right

shiftRight(int $bits) : \Moontoast\Math\BigNumber

Parameters

$bits

int

Returns

\Moontoast\Math\BigNumberfor fluent interface

Returns the sign (signum) of the current number

signum() : int

Returns

int-1, 0 or 1 as the value of this BigNumber is negative, zero or positive

Finds the square root of the current number

sqrt() : \Moontoast\Math\BigNumber
link http://www.php.net/bcsqrt

Returns

\Moontoast\Math\BigNumberfor fluent interface

Subtracts the given number from the current number

subtract(mixed $number) : \Moontoast\Math\BigNumber
link http://www.php.net/bcsub

Parameters

$number

mixed

May be of any type that can be cast to a string representation of a base 10 number

Returns

\Moontoast\Math\BigNumberfor fluent interface

Filters a number, converting it to a string value

filterNumber(mixed $number) : string

Parameters

$number

mixed

Returns

string

 Properties

 

The scale for the current number

$numberScale : int
 

Number value, as a string

$numberValue : string