Overview

Namespaces

  • BN
    • Collections
    • Compiler
      • Grammar
      • Parser
        • Operator
        • Token
      • Postfix
        • Operands
        • Operator
        • Token
      • Scanner
        • Converter
      • Token
  • Demo
  • None

Classes

  • AggregateFunctions
  • Number
  • NumberFactory
  • OperatorsFactory

Interfaces

  • INumber
  • Overview
  • Namespace
  • Class
  • Tree

Interface INumber

Interface for number which is used in expression evaluator. Variables can be used in evaluator only if they implement this interface. In class which implements this interface number have to be represented as string and the representation is accessible via @method __toString().

Direct known implementers

BN\Number
Namespace: BN
Located at lib/BN/INumber.php
Methods summary
public BN\INumber
# add( BN\INumber $number )

Gets a new number which is the sum of instance and argument.

Gets a new number which is the sum of instance and argument.

Parameters

$number
BN\INumber
$number

Returns

BN\INumber
public BN\INumber
# subtract( BN\INumber $number )

Gets a new number which is the difference of instance and argument.

Gets a new number which is the difference of instance and argument.

Parameters

$number
BN\INumber
$number

Returns

BN\INumber
public BN\INumber
# multiply( BN\INumber $number )

Gets a new number which is the product of instance and argument.

Gets a new number which is the product of instance and argument.

Parameters

$number
BN\INumber
$number

Returns

BN\INumber
public BN\INumber
# divide( BN\INumber $number )

Gets a new number which is the division of instance and argument.

Gets a new number which is the division of instance and argument.

Parameters

$number
BN\INumber
$number

Returns

BN\INumber

Throws

InvalidArgumentException
if $number equals 0

Example

5 / 2 = 2.5
public BN\INumber
# quotient( BN\INumber $number )

Gets a new number which is the division of instance and argument without remainder.

Gets a new number which is the division of instance and argument without remainder.

Returns

BN\INumber

Throws

InvalidArgumentException
if $number equals 0

Example

10 \ 3 = 3
10 \ -3 = -3
-10 \ 3 = -3
-10 \ -3 = 3
public BN\INumber
# modulo( BN\INumber $number )

Gets a new number which is the remainder after division of instance by argument. It supports a decimal remainder (calculated m(x,n) = x - n * floor(x/n)). See the rules in examples:

Gets a new number which is the remainder after division of instance by argument. It supports a decimal remainder (calculated m(x,n) = x - n * floor(x/n)). See the rules in examples:

Parameters

$number
BN\INumber
$number

Returns

BN\INumber

Throws

InvalidArgumentException
if $number equals 0

Example

10 % 2.1 = 1.6
10 % -2.1 = 1.6
-10 % 2.1 = -1.6
-10 % 2.1 = -1.6
public BN\INumber
# power( BN\INumber $number )

Gets a new number which is instance raised to the power of argument. If power is decimal number and it's not square root (1/2) then numbers are typed to float (IEEE 754) and then pow function is used. Result can be influenced by inaccurate floating point precision.

Gets a new number which is instance raised to the power of argument. If power is decimal number and it's not square root (1/2) then numbers are typed to float (IEEE 754) and then pow function is used. Result can be influenced by inaccurate floating point precision.

Parameters

$number
BN\INumber
$number

Returns

BN\INumber
public BN\INumber
# sqrt( )

Gets a new number which is the square root of instance.

Gets a new number which is the square root of instance.

Returns

BN\INumber

Throws

InvalidArgumentException
if $number is smaller than 0
public BN\INumber
# abs( )

Gets a new number which is the absolute value of instance.

Gets a new number which is the absolute value of instance.

Returns

BN\INumber
public BN\INumber
# negate( )

Gets a new number which is the negated instance.

Gets a new number which is the negated instance.

Returns

BN\INumber
public boolean
# isInteger( )

Returns true if instance is integer. Number is integer if don't have a decimal point or if numbers after decimal points are zeros.

Returns true if instance is integer. Number is integer if don't have a decimal point or if numbers after decimal points are zeros.

Returns

boolean
public boolean
# isZero( )

Returns true if instance equal to zero.

Returns true if instance equal to zero.

Returns

boolean
public boolean
# isNegative( )

Returns true if instance is smaller than zero.

Returns true if instance is smaller than zero.

Returns

boolean
public boolean
# isPositive( )

Returns true if instance is larger than zero.

Returns true if instance is larger than zero.

Returns

boolean
public integer
# compare( BN\INumber $number )

Compares instance with argument and returns 0 if number are equal. If instance is larger than argument it returns 1. Otherwise returns -1.

Compares instance with argument and returns 0 if number are equal. If instance is larger than argument it returns 1. Otherwise returns -1.

Parameters

$number
BN\INumber
$number

Returns

integer
public boolean
# isEqual( BN\INumber $number )

Returns true if instance and argument are equal numbers.

Returns true if instance and argument are equal numbers.

Parameters

$number
BN\INumber
$number

Returns

boolean
public boolean
# isBiggerThan( BN\INumber $number )

Returns true if instance is larger than argument

Returns true if instance is larger than argument

Parameters

$number
BN\INumber
$number

Returns

boolean
public boolean
# isSmallerThan( BN\INumber $number )

Returns true if instance is less than argument.

Returns true if instance is less than argument.

Parameters

$number
BN\INumber
$number

Returns

boolean
public BN\INumber
# round( integer $precision )

Gets a new number which is number rounded to nearest number. Precision is number of digits before (negative) or after (positive number) the decimal point.

Gets a new number which is number rounded to nearest number. Precision is number of digits before (negative) or after (positive number) the decimal point.

Parameters

$precision
integer
$precision

Returns

BN\INumber

Throws

InvalidArgumentException
if $precision is not integer

Example

2.56 round 1 = 2.6
74 round -1 = 70
public BN\INumber
# roundUp( )

Gets a new number which is the next integer farthest from zero. It round fractions up.

Gets a new number which is the next integer farthest from zero. It round fractions up.

Returns

BN\INumber

Example

8.62 roundUp = 9
-3.2 roundUp = -4
public BN\INumber
# roundDown( )

Gets a new number which is the the next integer closest to zero. It round fractions down.

Gets a new number which is the the next integer closest to zero. It round fractions down.

Returns

BN\INumber

Example

8.62 roundDown = 8
-3.2 roundDown = -3
public BN\INumber
# roundToNumber( integer $precision )

Gets a new number which is the nearest multiple of precision. If precision is positive number (round after decimal point) then it at first rounds number to number of digits in precision.

Gets a new number which is the nearest multiple of precision. If precision is positive number (round after decimal point) then it at first rounds number to number of digits in precision.

Parameters

$precision
integer
$precision

Returns

BN\INumber

Throws

InvalidArgumentException
if $precision is not integer

Example

8.6256 roundTo 20 (= temporary 8.63 roundTo 20) = 8.60
165 roundTo -50 = 150
public
# setLocalScale( integer $scale )

Sets a local scale used to set number of digits after decimal point in the result. It's defined only for the instance, all other instances will use global scale. Be careful about using local scale for methods modulo and roundToNumber, because they are creating temporary numbers without local scale.

Sets a local scale used to set number of digits after decimal point in the result. It's defined only for the instance, all other instances will use global scale. Be careful about using local scale for methods modulo and roundToNumber, because they are creating temporary numbers without local scale.

Parameters

$scale
integer
$scale

Throws

InvalidArgumentException
if $scale is not integer or it's smaller than 2
public
# resetLocalScale( )

Operation won't use local scale, but global scale (if it's defined). E.g. in BC Math global scale is defined by function bcscale.

Operation won't use local scale, but global scale (if it's defined). E.g. in BC Math global scale is defined by function bcscale.

public string
# __toString( )

Gets a string represetation of number.

Gets a string represetation of number.

Returns

string
public BN\INumber
# __clone( )

Clones the current instance.

Clones the current instance.

Returns

BN\INumber
BN-PHP - Big Number data type for PHP API documentation generated by ApiGen 2.8.0