Difference PHP_INT_MAX PHP_INT_SIZE precision?

4k views Asked by At

What is the difference beetwen

  1. PHP_INT_MAX
  2. PHP_INT_SIZE

precision from php.ini I have Windows 8.1(64bit), entered code:

ini_set('precision', 50);
$t = 12345678901234567890123456789012345678901234567890;
echo $t; //the result is 12345678901234566660398341115085767575755770822656
1

There are 1 answers

0
VolkerK On

http://php.net/manual/en/reserved.constants.php says

PHP_INT_MAX (integer)
The largest integer supported in this build of PHP. Usually int(2147483647). Available since PHP 5.0.5
[...]
PHP_INT_SIZE (integer)
The size of an integer in bytes in this build of PHP. Available since PHP 5.0.5

The values might be e.g. PHP_INT_MAX=2147483647 and PHP_INT_SIZE=4, i.e. the integer type is 32 bits "wide" (4 bytes) and has a range from –2147483648 to 2147483647.

precision is explained at http://docs.php.net/manual/en/ini.core.php#ini.precision as :

precision integer
The number of significant digits displayed in floating point numbers.

So it doesn't affect integers but floats. E.g.

<?php
$f = .123456789;
ini_set('precision', 8);
echo $f, "\r\n";

ini_set('precision', 2);
echo $f, "\r\n";

prints

0.12345679
0.12