Bug #18157 Updated: precision ini value affects internal calculations too
| From: | cnovak at gmx dot net | Date: | Thu, 04 Jul 2002 11:17:11 +0000 |
| Subject: | Bug #18157 Updated: precision ini value affects internal calculations too | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-13101@lists.php.net to get a copy of this message | ||
ID: 18157
Updated by: cnovak@gmx.net
Reported By: cnovak@gmx.net
-Status: Bogus
+Status: Open
Bug Type: Math related
Operating System: Windows XP Pro
PHP Version: 4.2.1
New Comment:
chg. status
Previous Comments:
------------------------------------------------------------------------
[2002-07-04 05:25:10] cnovak@gmx.net
I know that the variable is an integer and that the float/double cast
is only an internal way of PHP handling larger integers. The manual
(http://www.php.net/manual/en/language.types.integer.php) states the
following:
Integer overflow
If you specify a number beyond the _bounds_ of the integer type, it
will be interpreted as a float instead. Also, if you perform an
operation that results in a number beyond the bounds of the integer
type, a float will be returned instead.
--
I would assume from the above detail that PHP would cast my variable
from int to float when reaching the 32bit boundary. I understand that
beyond 2^63 that my number will be incorrect. The strange issue is that
this works correctly until 2^47. When precision is set to 20, it works
as expected. Since the pow(2, int) does not create any fractions I
would assume that the casting works as expected. Same happens using a
left bit shift.
------------------------------------------------------------------------
[2002-07-04 04:38:29] sander@php.net
PHP can't handle numbers larger than 2^32. Use the gmp or bcmath
extension.
(the ini setting precision is only for floats (both calculating and
printing), you're talking about integers).
------------------------------------------------------------------------
[2002-07-04 04:31:37] cnovak@gmx.net
By default precision in php.ini is set to 14 significant digits. I
would assume, that this is for printing float results only. Instead,
the precision argument is used for storing values in databases too.
Check the following code:
01 for ($x = 0; $x < 64; $x++) {
02 $group_bitfield = pow(2, $x);
03 print " $group_bitfield<br>";
04 }
The above yields precision errors at 2^48, 2^49, 2^51, 2^52, 2^54. If
this is for output only, fine. But the issue is that these values are
also _incorrectly_ stored in an INT(20) field on MySQL. Explicit type
casting does not help either. Using arbitrary math is not an option for
speed and availabilty at various ISP's.
Configuration:
WINNT
Apache/1.3.26 (Win32) mod_ssl/2.8.10 OpenSSL/0.9.6d PHP version: 4.2.1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18157&edit=1