Is there any method of php to get the highest number value supported by it?
Is there any method of php to get the highest number value supported by it?
PHP has the default constant of PHP_INT_MAX
since 5.0. 5, as well as PHP_INT_MIN
since PHP 7.0. The first will return the highest possible value and the second the lowest possible value.
<?php
echo 'Máximo: ' .PHP_INT_MAX;
echo PHP_EOL;
echo 'Minimo: ' . PHP_INT_MIN;
Typically, on 32-bit systems it will return 2147483647
and -2147483648
, respectively. While in 64 bits it will return 9223372036854775807
and -9223372036854775808
.
With the constant PHP_INT_MAX
, which is the largest integer supported in this interpreter, which is available from the 5.0.5
version.
Reference Pre Constants -definidas
The size of an integer is platform dependent, although a maximum value of about two billion is the usual value (that is, the largest signaled value represented with 32 bits). 64-bit platforms have a maximum value close to 9e18, except in Windows, versions prior to PHP 7, which will always be 32 bits. PHP does not support unsigned integers. The integer size can be determined by the constant PHP_INT_SIZE
and the maximum value by the constant PHP_INT_MAX
since PHP version 5.0.5. As of PHP 7.0.0, the minimum value can be obtained through the constant PHP_INT_MIN
.
The size of a floating-point number depends on the platform, with a maximum of ~ 1.8e308 accurate to 14 decimal digits (64-bit representation in IEEE 754 ).
Warning : Floating-point numbers have limited accuracy. Although it depends on the system, PHP generally uses the IEEE 754 dual-precision format, which will bring maximum precision due to rounds of the order of 1.11e-16. Uncommon math operations may cause larger errors, and of course, error propagation must be considered when multiple operations are performed.
In addition, rational numbers that have exact representation on base 10 numbers, such as 0.1 or 0.7, do not have exact floating-point representation in base 2, the format used internally, regardless of the size of the mantissa. So there is no conversion to the internal format without a small loss of precision. This can cause confusing results: for example, floor ((0.1 + 0.7) * 10) will usually return 7, instead of the expected result 8, because the final internal representation will look something like 7.9999999999999991118 ....So, never trust results with floating-point numbers to the last house, and never compare floating-point numbers in equalities. If you really need high precision, you can use arbitrary precision math functions and gmp are available.
For a "simple" explanation of this question, see the floating point guide , which also has the alternate title of " Why do not my numbers add up right? "