class NumberBase (View source)

Represents a positional numeral system with a specific number base.

NumberBase provides convenience when dealing numbers that are represented by a specific list of digits. NumberBase can interpret numbers presented as strings and also provides convenience when creating lists of digits.

Methods

__construct(DigitList|int|string|array $digitList)

Creates a new instance of NumberBase.

bool
hasStringConflict()

Tells if numbers using this numeral system cannot be represented using a string.

bool
isCaseSensitive()

Tells if this numeral system is case sensitive or not.

int
getRadix()

Returns the radix (i.e. base) of the numeral system.

array
getDigitList()

Returns list of all digits in the numeral system.

bool
hasDigit(mixed $digit)

Tells if the given digit is part of this numeral system.

int
getValue(mixed $digit)

Returns the decimal value represented by the given digit.

int[]
getValues(array $digits)

Returns the decimal values for given digits.

mixed
getDigit(int $decimal)

Returns the digit representing the given decimal value.

array
getDigits(array $decimals)

Returns the digits representing the given decimal values.

int|false
findCommonRadixRoot(NumberBase $base)

Finds the largest integer root shared by the radix of both numeral systems.

array
canonizeDigits(array $digits)

Replaces all values in the array with actual digits from the digit list.

array
splitString(string $string)

Splits number string into individual digits.

Details

__construct(DigitList|int|string|array $digitList)

Creates a new instance of NumberBase.

The constructor takes a list of digits for the numeral system as the constructor parameter. This can either be an instance of DigitList or it can be a string, an integer or an array that is used to construct the appropriate type of DigitList. See the constructors for appropriate classes for how to define those digit lists.

Parameters

DigitList|int|string|array $digitList List of digits

Exceptions

InvalidArgumentException If the list of digits is invalid

bool hasStringConflict()

Tells if numbers using this numeral system cannot be represented using a string.

Return Value

bool True if string representation is not supported, false if it is

bool isCaseSensitive()

Tells if this numeral system is case sensitive or not.

Return Value

bool True if case sensitive, false if not

int getRadix()

Returns the radix (i.e. base) of the numeral system.

Return Value

int Radix of the numeral system

array getDigitList()

Returns list of all digits in the numeral system.

Return Value

array Array of digits in the numeral system

bool hasDigit(mixed $digit)

Tells if the given digit is part of this numeral system.

Parameters

mixed $digit The digit to look up

Return Value

bool True if the digit exists, false is not

int getValue(mixed $digit)

Returns the decimal value represented by the given digit.

Parameters

mixed $digit The digit to look up

Return Value

int The decimal value for the provided digit

Exceptions

InvalidDigitException If the given digit is invalid

int[] getValues(array $digits)

Returns the decimal values for given digits.

Parameters

array $digits Array of digits to look up

Return Value

int[] Array of digit values

Exceptions

InvalidDigitException If any of the digits is invalid

mixed getDigit(int $decimal)

Returns the digit representing the given decimal value.

Parameters

int $decimal Decimal value to lookup

Return Value

mixed The digit that represents the given decimal value

Exceptions

InvalidArgumentException If the decimal value is not within the number system

array getDigits(array $decimals)

Returns the digits representing the given decimal values.

Parameters

array $decimals Decimal values to look up

Return Value

array Array of digits that represent the given decimal values

Exceptions

InvalidArgumentException If any of the decimal values is invalid

int|false findCommonRadixRoot(NumberBase $base)

Finds the largest integer root shared by the radix of both numeral systems.

Parameters

NumberBase $base Numeral system to compare against

Return Value

int|false Highest common integer root or false if none

array canonizeDigits(array $digits)

Replaces all values in the array with actual digits from the digit list.

This method takes a list of digits and returns the digits properly capitalized and typed. This can be used to canonize numbers when dealing with case insensitive and loosely typed number bases.

Parameters

array $digits List of digits to canonize

Return Value

array Canonized list of digits

Exceptions

InvalidDigitException If any of the digits are invalid

array splitString(string $string)

Splits number string into individual digits.

Parameters

string $string String to split into array of digits

Return Value

array Array of digits

Exceptions

RuntimeException If numeral system does not support strings