BrickMathCalculator
in package
implements
CalculatorInterface
A calculator using the brick/math library for arbitrary-precision arithmetic
Tags
Interfaces, Classes, Traits and Enums
- CalculatorInterface
- A calculator performs arithmetic operations on numbers
Table of Contents
- ROUNDING_MODE_MAP = [\Ramsey\Uuid\Math\RoundingMode::UNNECESSARY => \Brick\Math\RoundingMode::UNNECESSARY, \Ramsey\Uuid\Math\RoundingMode::UP => \Brick\Math\RoundingMode::UP, \Ramsey\Uuid\Math\RoundingMode::DOWN => \Brick\Math\RoundingMode::DOWN, \Ramsey\Uuid\Math\RoundingMode::CEILING => \Brick\Math\RoundingMode::CEILING, \Ramsey\Uuid\Math\RoundingMode::FLOOR => \Brick\Math\RoundingMode::FLOOR, \Ramsey\Uuid\Math\RoundingMode::HALF_UP => \Brick\Math\RoundingMode::HALF_UP, \Ramsey\Uuid\Math\RoundingMode::HALF_DOWN => \Brick\Math\RoundingMode::HALF_DOWN, \Ramsey\Uuid\Math\RoundingMode::HALF_CEILING => \Brick\Math\RoundingMode::HALF_CEILING, \Ramsey\Uuid\Math\RoundingMode::HALF_FLOOR => \Brick\Math\RoundingMode::HALF_FLOOR, \Ramsey\Uuid\Math\RoundingMode::HALF_EVEN => \Brick\Math\RoundingMode::HALF_EVEN]
- add() : NumberInterface
- Returns the sum of all the provided parameters
- divide() : NumberInterface
- Returns the quotient of the provided parameters divided left-to-right
- fromBase() : Integer
- Converts a value from an arbitrary base to a base-10 integer value
- multiply() : NumberInterface
- Returns the product of all the provided parameters
- subtract() : NumberInterface
- Returns the difference of all the provided parameters
- toBase() : string
- Converts a base-10 integer value to an arbitrary base
- toHexadecimal() : Hexadecimal
- Converts an Integer instance to a Hexadecimal instance
- toInteger() : Integer
- Converts a Hexadecimal instance to an Integer instance
- getBrickRoundingMode() : int
- Maps ramsey/uuid rounding modes to those used by brick/math
Constants
ROUNDING_MODE_MAP
private
mixed
ROUNDING_MODE_MAP
= [\Ramsey\Uuid\Math\RoundingMode::UNNECESSARY => \Brick\Math\RoundingMode::UNNECESSARY, \Ramsey\Uuid\Math\RoundingMode::UP => \Brick\Math\RoundingMode::UP, \Ramsey\Uuid\Math\RoundingMode::DOWN => \Brick\Math\RoundingMode::DOWN, \Ramsey\Uuid\Math\RoundingMode::CEILING => \Brick\Math\RoundingMode::CEILING, \Ramsey\Uuid\Math\RoundingMode::FLOOR => \Brick\Math\RoundingMode::FLOOR, \Ramsey\Uuid\Math\RoundingMode::HALF_UP => \Brick\Math\RoundingMode::HALF_UP, \Ramsey\Uuid\Math\RoundingMode::HALF_DOWN => \Brick\Math\RoundingMode::HALF_DOWN, \Ramsey\Uuid\Math\RoundingMode::HALF_CEILING => \Brick\Math\RoundingMode::HALF_CEILING, \Ramsey\Uuid\Math\RoundingMode::HALF_FLOOR => \Brick\Math\RoundingMode::HALF_FLOOR, \Ramsey\Uuid\Math\RoundingMode::HALF_EVEN => \Brick\Math\RoundingMode::HALF_EVEN]
Methods
add()
Returns the sum of all the provided parameters
public
add(NumberInterface $augend, NumberInterface ...$addends) : NumberInterface
Parameters
- $augend : NumberInterface
-
The first addend (the integer being added to)
- $addends : NumberInterface
-
The additional integers to a add to the augend
Return values
NumberInterface —The sum of all the parameters
divide()
Returns the quotient of the provided parameters divided left-to-right
public
divide(int $roundingMode, int $scale, NumberInterface $dividend, NumberInterface ...$divisors) : NumberInterface
Parameters
- $roundingMode : int
-
The RoundingMode constant to use for this operation
- $scale : int
-
The scale to use for this operation
- $dividend : NumberInterface
-
The integer to be divided
- $divisors : NumberInterface
-
The integers to divide $dividend by, in the order in which the division operations should take place (left-to-right)
Return values
NumberInterface —The quotient of dividing the provided parameters left-to-right
fromBase()
Converts a value from an arbitrary base to a base-10 integer value
public
fromBase(string $value, int $base) : Integer
Parameters
- $value : string
-
The value to convert
- $base : int
-
The base to convert from (i.e., 2, 16, 32, etc.)
Return values
Integer —The base-10 integer value of the converted value
multiply()
Returns the product of all the provided parameters
public
multiply(NumberInterface $multiplicand, NumberInterface ...$multipliers) : NumberInterface
Parameters
- $multiplicand : NumberInterface
-
The integer to be multiplied
- $multipliers : NumberInterface
-
The factors by which to multiply the multiplicand
Return values
NumberInterface —The product of multiplying all the provided parameters
subtract()
Returns the difference of all the provided parameters
public
subtract(NumberInterface $minuend, NumberInterface ...$subtrahends) : NumberInterface
Parameters
- $minuend : NumberInterface
-
The integer being subtracted from
- $subtrahends : NumberInterface
-
The integers to subtract from the minuend
Return values
NumberInterface —The difference after subtracting all parameters
toBase()
Converts a base-10 integer value to an arbitrary base
public
toBase(Integer $value, int $base) : string
Parameters
- $value : Integer
-
The integer value to convert
- $base : int
-
The base to convert to (i.e., 2, 16, 32, etc.)
Return values
string —The value represented in the specified base
toHexadecimal()
Converts an Integer instance to a Hexadecimal instance
public
toHexadecimal(Integer $value) : Hexadecimal
Parameters
- $value : Integer
Return values
Hexadecimal —toInteger()
Converts a Hexadecimal instance to an Integer instance
public
toInteger(Hexadecimal $value) : Integer
Parameters
- $value : Hexadecimal
Return values
Integer —getBrickRoundingMode()
Maps ramsey/uuid rounding modes to those used by brick/math
private
getBrickRoundingMode(int $roundingMode) : int
Parameters
- $roundingMode : int