class Number

Represents a number for use with Binary Calculator computations

Properties

protected string $numberValue

Number value, as a string

protected int $numberScale

The scale for the current number

Methods

__construct(mixed $number, int $scale = 2)

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

string
__toString()

Returns the string value of this BigNumber

abs()

将当前数字设置为自身的绝对值 Sets the current number to the absolute value of itself

$this
add(mixed $number)

加法运算 Adds the given number to the current number

ceil()

通过重新排列当前数字来查找下一个最高整型值 Finds the next highest integer value by rounding up the current number if necessary

int
compareTo(mixed $number)

比较数据 Compares the current number with the given number

string
convertToBase(int $base)

进制转换, 转换成任意进制 Returns the current value converted to an arbitrary base

decrement()

将当前数字的值减一 Decreases the value of the current number by one

$this
divide(mixed $number)

除法运算 Divides the current number by the given number

floor()

通过舍入当前数字找到下一个最低整数值 Finds the next lowest integer value by rounding down the current number if necessary

int
getScale()

返回小数位数 Returns the scale used for this BigNumber

string
getValue()

获取字串值 Returns the current raw value of this BigNumber

increment()

增加 Increases the value of the current number by one

bool
isEqualTo(mixed $number)

检测是否相等 Returns true if the current number equals the given number

bool
isGreaterThan(mixed $number)

检测是否大于 Returns true if the current number is greater than the given number

bool
isGreaterThanOrEqualTo(mixed $number)

检测大于等于 Returns true if the current number is greater than or equal to the given number

bool
isLessThan(mixed $number)

检测小与 Returns true if the current number is less than the given number

bool
isLessThanOrEqualTo(mixed $number)

检测小与等于 Returns true if the current number is less than or equal to the given number

bool
isNegative()

是否是负数 Returns true if the current number is a negative number

bool
isPositive()

是否是正数 Returns true if the current number is a positive number

$this
mod(mixed $number)

取余数 Finds the modulus of the current number divided by the given number

$this
multiply(mixed $number)

乘法 Multiplies the current number by the given number

negate()

返回负数 Sets the current number to the negative value of itself

$this
pow(mixed $number)

幂运算 Raises current number to the given number

$this
powMod(mixed $pow, mixed $mod)

指定次数的幂运算 Raises the current number to the $pow, then divides by the $mod to find the modulus

round(int $precision = 0)

四舍五入 Rounds the current number to the nearest integer

$this
setScale(int $scale)

设置小数位数 Sets the scale of this BigNumber

$this
setValue(mixed $number)

设置为一个新值 Sets the value of this BigNumber to a new value

$this
shiftLeft(int $bits)

位向左移动 Shifts the current number $bits to the left

$this
shiftRight(int $bits)

位向右移动 Shifts the current number $bits to the right

int
signum()

前数字的符号 Returns the sign (signum) of the current number

sqrt()

求平方根 Finds the square root of the current number

$this
subtract(mixed $number)

减法 Subtracts the given number from the current number

static string
baseConvert(string|int $number, int $fromBase = 10, int $toBase = 16)

进制转换 Converts a number between arbitrary bases (from 2 to 36)

static string
convertFromBase10(string|int $number, int $toBase)

转换 10 进制到其他进制 Converts a base-10 number to an arbitrary base (from 2 to 36)

static string
convertToBase10(string|int $number, int $fromBase)

转换成 10 进制 Converts a number from an arbitrary base (from 2 to 36) to base 10

static void
setDefaultScale(int $scale)

设置默认小数位数 Changes the default scale used by all Binary Calculator functions

string
filterNumber(mixed $number)

转换成 String 类型 Filters a number, converting it to a string value

Details

at line 62
__construct(mixed $number, int $scale = 2)

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

Parameters

mixed $number

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

int $scale

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

at line 76
string __toString()

Returns the string value of this BigNumber

Return Value

string

String representation of the number in base 10

at line 85
abs()

将当前数字设置为自身的绝对值 Sets the current number to the absolute value of itself

at line 105
$this add(mixed $number)

加法运算 Adds the given number to the current number

Parameters

mixed $number

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

Return Value

$this

at line 123
ceil()

通过重新排列当前数字来查找下一个最高整型值 Finds the next highest integer value by rounding up the current number if necessary

at line 152
int compareTo(mixed $number)

比较数据 Compares the current number with the given number

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

Parameters

mixed $number

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

Return Value

int

at line 168
string convertToBase(int $base)

进制转换, 转换成任意进制 Returns the current value converted to an arbitrary base

Parameters

int $base

The base to convert the current number to

Return Value

string

String representation of the number in the given base

at line 177
decrement()

将当前数字的值减一 Decreases the value of the current number by one

at line 192
$this divide(mixed $number)

除法运算 Divides the current number by the given number

Parameters

mixed $number

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

Return Value

$this

Exceptions

ArithmeticException

at line 216
floor()

通过舍入当前数字找到下一个最低整数值 Finds the next lowest integer value by rounding down the current number if necessary

at line 242
int getScale()

返回小数位数 Returns the scale used for this BigNumber

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

Return Value

int

at line 257
string getValue()

获取字串值 Returns the current raw value of this BigNumber

Return Value

string

String representation of the number in base 10

at line 267
increment()

增加 Increases the value of the current number by one

at line 280
bool isEqualTo(mixed $number)

检测是否相等 Returns true if the current number equals the given number

Parameters

mixed $number

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

Return Value

bool

at line 293
bool isGreaterThan(mixed $number)

检测是否大于 Returns true if the current number is greater than the given number

Parameters

mixed $number

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

Return Value

bool

at line 306
bool isGreaterThanOrEqualTo(mixed $number)

检测大于等于 Returns true if the current number is greater than or equal to the given number

Parameters

mixed $number

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

Return Value

bool

at line 319
bool isLessThan(mixed $number)

检测小与 Returns true if the current number is less than the given number

Parameters

mixed $number

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

Return Value

bool

at line 332
bool isLessThanOrEqualTo(mixed $number)

检测小与等于 Returns true if the current number is less than or equal to the given number

Parameters

mixed $number

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

Return Value

bool

at line 343
bool isNegative()

是否是负数 Returns true if the current number is a negative number

Return Value

bool

at line 354
bool isPositive()

是否是正数 Returns true if the current number is a positive number

Return Value

bool

at line 369
$this mod(mixed $number)

取余数 Finds the modulus of the current number divided by the given number

Parameters

mixed $number

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

Return Value

$this

Exceptions

ArithmeticException

at line 394
$this multiply(mixed $number)

乘法 Multiplies the current number by the given number

Parameters

mixed $number

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

Return Value

$this

at line 409
negate()

返回负数 Sets the current number to the negative value of itself

at line 423
$this pow(mixed $number)

幂运算 Raises current number to the given number

Parameters

mixed $number

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

Return Value

$this

at line 457
$this powMod(mixed $pow, mixed $mod)

指定次数的幂运算 Raises the current number to the $pow, then divides by the $mod to find the modulus

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.

Parameters

mixed $pow

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

mixed $mod

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

Return Value

$this

Exceptions

ArithmeticException

at line 487
Number round(int $precision = 0)

四舍五入 Rounds the current number to the nearest integer

Parameters

int $precision precision

Return Value

Number

at line 516
$this setScale(int $scale)

设置小数位数 Sets the scale of this BigNumber

Parameters

int $scale

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

Return Value

$this

at line 531
$this setValue(mixed $number)

设置为一个新值 Sets the value of this BigNumber to a new value

Parameters

mixed $number

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

Return Value

$this

at line 552
$this shiftLeft(int $bits)

位向左移动 Shifts the current number $bits to the left

Parameters

int $bits bits

Return Value

$this

at line 569
$this shiftRight(int $bits)

位向右移动 Shifts the current number $bits to the right

Parameters

int $bits bits

Return Value

$this

at line 585
int signum()

前数字的符号 Returns the sign (signum) of the current number

Return Value

int

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

at line 603
sqrt()

求平方根 Finds the square root of the current number

at line 622
$this subtract(mixed $number)

减法 Subtracts the given number from the current number

Parameters

mixed $number

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

Return Value

$this

at line 642
static string baseConvert(string|int $number, int $fromBase = 10, int $toBase = 16)

进制转换 Converts a number between arbitrary bases (from 2 to 36)

Parameters

string|int $number

The number to convert

int $fromBase

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

int $toBase

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

Return Value

string

at line 658
static string convertFromBase10(string|int $number, int $toBase)

转换 10 进制到其他进制 Converts a base-10 number to an arbitrary base (from 2 to 36)

Parameters

string|int $number

The number to convert

int $toBase

The base to convert $number to

Return Value

string

Exceptions

InvalidArgumentException

at line 693
static string convertToBase10(string|int $number, int $fromBase)

转换成 10 进制 Converts a number from an arbitrary base (from 2 to 36) to base 10

Parameters

string|int $number

The number to convert

int $fromBase

The base $number is in

Return Value

string

Exceptions

InvalidArgumentException

at line 736
static void setDefaultScale(int $scale)

设置默认小数位数 Changes the default scale used by all Binary Calculator functions

Parameters

int $scale scale

Return Value

void

at line 748
protected string filterNumber(mixed $number)

转换成 String 类型 Filters a number, converting it to a string value

Parameters

mixed $number number

Return Value

string