Skip to content

Commit de2d6f0

Browse files
Big Integer Support
1 parent 223caa3 commit de2d6f0

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

spec/05-types.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,21 @@ The library function `is_bool` (§xx) indicates if a given value has type
5858
###The Integer Type
5959

6060
There is one integer type, `int`, for which the name `integer` is a synonym.
61-
This type is binary, signed, and uses twos-complement representation for
62-
negative values. The range of values that can be stored is
63-
implementation-defined; however, the range [-2147483648, 2147483647],
64-
must be supported. This range must be finite.
61+
This type is a binary, signed, arbitrary-precision integer. Its range is
62+
limited only by available memory.
6563

66-
Certain operations on integer values produce a mathematical result that
67-
cannot be represented as an integer. Examples include the following:
64+
Implementations MAY choose to implement this type with an underlying native
65+
integer type and a separate arbitrary-precision integer type, so long as the
66+
observed behaviour is identical and the two types are indistinguishable, i.e.
67+
they are, for all intents and purposes, the same type and are reported as such.
6868

69-
- Incrementing the largest value or decrementing the smallest value.
70-
- Applying the unary minus to the smallest value.
71-
- Multiplying, adding, or subtracting two values.
72-
73-
In such cases, the computation is done as though the types of the values were
74-
`float` with the result having that type.
69+
Bitwise operations MUST use two's-complement arithmetic, however implementations
70+
MAY choose not to use a two's-complement underlying representation.
7571

7672
The constants `PHP_INT_SIZE`[[6.3](06-constants.md#core-predefined-constants)](#core-predefined-constants)), `PHP_INT_MAX`[[6.3](06-constants.md#core-predefined-constants)](#core-predefined-constants)) and `PHP_INT_MIN`[[6.3](06-constants.md#core-predefined-constants)](#core-predefined-constants))
77-
define certain characteristics about type `int`.
73+
exist for backwards-compatibility reasons, and indicate the native integer
74+
size of the machine (usually 32-bit or 64-bit). They do not, however, represent
75+
the actual range and size of the PHP integer type, which is unlimited.
7876

7977
The library function `is_int` (§xx) indicates if a given value has type
8078
`int`.

spec/06-constants.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ Constant Name | Description
106106
`PHP_EOL` | `string`; the end-of-line terminator for this platform.
107107
`PHP_EXTENSION_DIR` | `string`; The directory to be searched by the library function dl (§xx) when looking for runtime extensions.
108108
`PHP_EXTRA_VERSION` | `string`; the current PHP extra version.
109-
`PHP_INT_MAX` | `int`; the maximum representable value for an integer.
110-
`PHP_INT_MIN` | `int`; the minimum representable value for an integer.
111-
`PHP_INT_SIZE` | `int`; the number of bytes used to represent an integer.
109+
`PHP_INT_MAX` | `int`; the maximum representable value for a native integer on this platform. (This does not correspond to the maximum size of a PHP integer, unlimited.)
110+
`PHP_INT_MIN` | `int`; the minimum representable value for a native integer on this platform. (This does not correspond to the maximum size of a PHP integer, which is unlimited.)
111+
`PHP_INT_SIZE` | `int`; the number of bytes used to represent the native integer size of this platform. (This does not correspond to the maximum size of a PHP integer, which is unlimited.)
112112
`PHP_MAJOR_VERSION` | `int`; the current PHP major version
113113
`PHP_MANDIR` | `string`; the installation location of the manual pages.
114114
`PHP_MAXPATHLEN` | `int`; the maximum length of a fully qualified filename supported by this build.

spec/08-conversions.md

+3-21
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,13 @@ If the source type is `bool`, then if the source value is `FALSE`, the
4242
result value is 0; otherwise, the result value is 1.
4343

4444
If the source type is `float`, for the values `INF`, `-INF`, and `NAN`, the
45-
result value is zero. For all other values, if the
46-
precision can be preserved (that is, the float is within the range of an
47-
integer), the fractional part is rounded towards zero. If the precision cannot
48-
be preserved, the following conversion algorithm is used, where *X* is
49-
defined as two to the power of the number of bits in an integer (for example,
50-
2 to the power of 32, i.e. 4294967296):
51-
52-
1. We take the floating point remainder (wherein the remainder has the same
53-
sign as the dividend) of dividing the float by *X*, rounded towards zero.
54-
2. If the remainder is less than zero, it is rounded towards
55-
infinity and *X* is added.
56-
3. This result is converted to an unsigned integer.
57-
4. This result is converted to a signed integer by treating the unsigned
58-
integer as a two's complement representation of the signed integer.
59-
60-
Implementations may implement this conversion differently (for example, on some
61-
architectures there may be hardware support for this specific conversion mode)
62-
so long as the result is the same.
45+
result value is zero. For all other values, the fractional part is rounded towards zero.
6346

6447
If the source value is `NULL`, the result value is 0.
6548

6649
If the source is a numeric string or leading-numeric string ([§§](05-types.md#the-string-type))
67-
having integer format, if the precision can be preserved the result
68-
value is that string's integer value; otherwise, the result is
69-
undefined. If the source is a numeric string or leading-numeric string
50+
having integer format, the result value is that string's integer value.
51+
If the source is a numeric string or leading-numeric string
7052
having floating-point format, the string's floating-point value is
7153
treated as described above for a conversion from `float`. The trailing
7254
non-numeric characters in leading-numeric strings are ignored. For any

0 commit comments

Comments
 (0)