Recent Changes - Search:

* PCAN

* Phix

edit SideBar

AtomsAndIntegers

Index | Core Language | Atoms and Integers

Atoms and Integers

Atoms can have any integer or floating point value.

On a 32-bit architecture atoms can hold approximately ±1e+308, with ±1e-324 being the closest you can get to 0 without actually being 0, to a maximum of about 15 decimal digits of accuracy. On a 64-bit architecture atoms can hold approximately ±1e+4932, with ±1e-4951 being the closest you can get to 0 without actually being 0, to a maximum of about 19 decimal digits of accuracy.

Integers in Phix are limited to the subset that begin with 0b00 or 0b11: on a 32-bit architecture they can contain a single value in the range -1,073,741,824 to +1,073,741,823 (-#40000000 to #3FFFFFFF), with no fractional part, hence technically speaking Phix integers are 31-bit, straddling the "middle half" of the actual hardware range (-2GB..+2GB-1). On a 64-bit architecture the range is -4,611,686,018,427,387,904 to +4,611,686,018,427,387,903 (-#4000000000000000 to #3FFFFFFFFFFFFFFF), which technically speaking makes them 63-bit. Should you need to hold full 32 (or 64) bit "integers", simply use an atom (trust me, it works).

The following values may also prove useful:

printf(1,"maxint  %d (#%x)\n",power(2,machine_bits()-2)-1)
printf(1,"minint %d (#%x)\n",-power(2,machine_bits()-2))
printf(1,"maxatm %d\n",{power(2,iff(machine_bits()=32?53:64))})
--32-bit:
maxint  1073741823 (#3FFFFFFF)
minint -1073741824 (#C0000000)
maxatm 9007199254740992
-- 64-bit:
maxint  4611686018427387903 (#3FFFFFFFFFFFFFFF)
minint -4611686018427387904 (#C000000000000000)
maxatm 18446744073709551616

where maxatm is the largest integer than can be held exactly in a native atom, above that you need to use mpir/gmp.

Phix does not entertain the idea of unsigned integers: zero less one is -1, not suddenly +4GB (which is what happens in C-based languages). Likewise storing >=1GB in an integer leads to a clear no-nonsense type check error, telling you the file name and the line number where it went wrong, and, as long as you use the right editor, jumping there automatically, rather than quietly hiding the error.

While you can store any integer value in a variable declared as an atom, the reverse is not true.

Here are some Phix integers and atoms:

    0       -- (integer)
    1000    -- (integer)
    98.6    -- (atom)
    -1e60   -- (atom)

Phix stores integer-valued atoms as machine integers (4 or 8 bytes) to save space and improve execution speed. When fractional results occur or numbers get too big, conversion to floating-point happens automatically. As we shall soon see, should that conversion be the wrong thing to do, you are immediately notified in a clear and no-nonsense, human-readable manner.

Of course if you need to replicate the truncating/wrapping behaviour of C integer maths, for instance in hashing and cryptographic functions, you can easily do that with a bit of inline assembly, and should you need to work with ridiculously large numbers, an arbitrary precision maths library, mpfr, is included with the distribution.

See also: Number Bases

< Core Language | Index | Number Bases >

Edit - History - Print - Recent Changes - Search
Page last modified on April 16, 2026, at 04:04 AM