integer

Created by: Lester Caine, Last modification: 6 January 2014

The number range of a simple number depends on the platform being used, and with the prevalence of 64bit hardware, a 64 bit resolution is the norm, but mobile devices may well be restricted to 32 bit values, so a simple assumption is not easy.

The PHP definition is here but I am having a little difficulty with PHP_INT_SIZE which should give the range.

32bit systems, the range is -2^31 to 2^31-1 while for 64 bit this is -2^63 to 2^63-1

While it may be obvious to many people, there is no provision for NAN or INF in a numeric value, and there are several articles explaining that on stackoverflow, the C++ version being a tidy one, but the question does get asked often.

It is also worth pulling in here another aspect of raw numbers when mapping to databases. Many databases support UNSIGNED INTEGER which probably had a place back in the days of 16bit arithmetic, but using a single bit to get a larger positive range nowadays seems a little pointless? Unsigned 32bit integers need to be mapped to 64bit integers in PHP as PHP does not support unsigned. When building cross database applications, UNSIGNED is an option which should be ignored.

On the whole, a database INTEGER field will be a 32bit value, with BIGINT indicating a 64bit range, and often SMALLINT for a 16bit range. Some databases even allow for 8bit CHAR fields to be used for 0-255 integer values. This may seem overkill, but with a relational database, tables with less than 256 values can be common, so a small integer field can be used in other records. Other databases go on to define the range of digits an integer field can display, which can be useful for client applications, but is best left to the display model.

There is a useful crossreference of field types on w3school but this is another area where a PHP related table would be useful.