Calculators

interface Ramsey\Uuid\Math\CalculatorInterface

Provides functionality for performing mathematical calculations.

add($augend, ...$addends)
Parameters
Returns

The sum of all the parameters

Return type

Ramsey\Uuid\Type\NumberInterface

subtract($minuend, ...$subtrahends)
Parameters
Returns

The difference after subtracting all parameters

Return type

Ramsey\Uuid\Type\NumberInterface

multiply($multiplicand, ...$multipliers)
Parameters
Returns

The product of multiplying all the provided parameters

Return type

Ramsey\Uuid\Type\NumberInterface

divide($roundingMode, $scale, $dividend, ...$divisors)
Parameters
Returns

The quotient of dividing the provided parameters left-to-right

Return type

Ramsey\Uuid\Type\NumberInterface

fromBase($value, $base)

Converts a value from an arbitrary base to a base-10 integer value.

Parameters
  • $value (string) – The value to convert

  • $base (int) – The base to convert from (i.e., 2, 16, 32, etc.)

Returns

The base-10 integer value of the converted value

Return type

Ramsey\Uuid\Type\Integer

toBase($value, $base)

Converts a base-10 integer value to an arbitrary base.

Parameters
  • $value (Ramsey\Uuid\Type\Integer) – The integer value to convert

  • $base (int) – The base to convert to (i.e., 2, 16, 32, etc.)

Returns

The value represented in the specified base

Return type

string

toHexadecimal($value)

Converts an Integer instance to a Hexadecimal instance.

Parameters
Return type

Ramsey\Uuid\Type\Hexadecimal

toInteger($value)

Converts a Hexadecimal instance to an Integer instance.

Parameters
Return type

Ramsey\Uuid\Type\Integer

class Ramsey\Uuid\Math\RoundingMode
constant UNNECESSARY

Asserts that the requested operation has an exact result, hence no rounding is necessary.

constant UP

Rounds away from zero.

Always increments the digit prior to a nonzero discarded fraction. Note that this rounding mode never decreases the magnitude of the calculated value.

constant DOWN

Rounds towards zero.

Never increments the digit prior to a discarded fraction (i.e., truncates). Note that this rounding mode never increases the magnitude of the calculated value.

constant CEILING

Rounds towards positive infinity.

If the result is positive, behaves as for UP; if negative, behaves as for DOWN. Note that this rounding mode never decreases the calculated value.

constant FLOOR

Rounds towards negative infinity.

If the result is positive, behave as for DOWN; if negative, behave as for UP. Note that this rounding mode never increases the calculated value.

constant HALF_UP

Rounds towards “nearest neighbor” unless both neighbors are equidistant, in which case round up.

Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves as for DOWN. Note that this is the rounding mode commonly taught at school.

constant HALF_DOWN

Rounds towards “nearest neighbor” unless both neighbors are equidistant, in which case round down.

Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves as for DOWN.

constant HALF_CEILING

Rounds towards “nearest neighbor” unless both neighbors are equidistant, in which case round towards positive infinity.

If the result is positive, behaves as for HALF_UP; if negative, behaves as for HALF_DOWN.

constant HALF_FLOOR

Rounds towards “nearest neighbor” unless both neighbors are equidistant, in which case round towards negative infinity.

If the result is positive, behaves as for HALF_DOWN; if negative, behaves as for HALF_UP.

constant HALF_EVEN

Rounds towards the “nearest neighbor” unless both neighbors are equidistant, in which case rounds towards the even neighbor.

Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for HALF_DOWN if it’s even.

Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a sequence of calculations. It is sometimes known as “Banker’s rounding”, and is chiefly used in the USA.