CalculatorInterface
in
A calculator performs arithmetic operations on numbers
Tags
Table of Contents
- 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
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