class Number (View source)

Provides helper methods for manipulating numbers.

Methods

static bool
validStep(float $value, float $step, float $offset = 0.0)

Verifies that a number is a multiple of a given step.

static string
intToAlphadecimal(int $i = 0)

Generates a sorting code from an integer.

static int
alphadecimalToInt(string $string = '00')

Decodes a sorting code back to an integer.

Details

static bool validStep(float $value, float $step, float $offset = 0.0)

Verifies that a number is a multiple of a given step.

The implementation assumes it is dealing with IEEE 754 double precision floating point numbers that are used by PHP on most systems.

This is based on the number/range verification methods of webkit.

Parameters

float $value

The value that needs to be checked.

float $step

The step scale factor. Must be positive.

float $offset

(optional) An offset, to which the difference must be a multiple of the given step.

Return Value

bool

TRUE if no step mismatch has occurred, or FALSE otherwise.

See also

http://opensource.apple.com/source/WebCore/WebCore-1298/html/NumberInputType.cpp

static string intToAlphadecimal(int $i = 0)

Generates a sorting code from an integer.

Consists of a leading character indicating length, followed by N digits with a numerical value in base 36 (alphadecimal). These codes can be sorted as strings without altering numerical order.

It goes: 00, 01, 02, ..., 0y, 0z, 110, 111, ... , 1zy, 1zz, 2100, 2101, ..., 2zzy, 2zzz, 31000, 31001, ...

Parameters

int $i

The integer value to convert.

Return Value

string

The alpha decimal value.

See also

Number::alphadecimalToInt

static int alphadecimalToInt(string $string = '00')

Decodes a sorting code back to an integer.

Parameters

string $string

The alpha decimal value to convert

Return Value

int

The integer value.

See also

Number::intToAlphadecimal