#50095 [NEW]: Unexpected behavior of precision of float numbers
| From: | majkl578 at gmail dot com | Date: | Thu, 05 Nov 2009 20:12:18 +0000 |
| Subject: | #50095 [NEW]: Unexpected behavior of precision of float numbers | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-144305@lists.php.net to get a copy of this message | ||
From: majkl578 at gmail dot com
Operating system: Linux Debian
PHP version: 5.2.11
PHP Bug Type: Scripting Engine problem
Bug description: Unexpected behavior of precision of float numbers
Description:
------------
When dumping a float number, it is represented incorrectly. Generally, in
some cases, PHP handles float numbers in invalid format.
It is related to a setting of php.ini directive "precision". When a float
number with one decimal place is dumped and high precision is set, it is
not dumped in an original format, but in damaged one.
Additional info:
32-bit system
CPU: AMD Athlon64
Reproduce code:
---------------
foreach (range(0, 30) as $precision) {
ini_set('precision', $precision);
echo $precision . ': ';
var_dump(20.2);
}
Expected result:
----------------
0: float(20)
1: float(20.2)
2: float(20.2)
3: float(20.2)
4: float(20.2)
5: float(20.2)
6: float(20.2)
7: float(20.2)
8: float(20.2)
9: float(20.2)
10: float(20.2)
11: float(20.2)
12: float(20.2)
13: float(20.2)
14: float(20.2)
15: float(20.2)
16: float(20.2)
17: float(20.2)
18: float(20.2)
19: float(20.2)
20: float(20.2)
21: float(20.2)
22: float(20.2)
23: float(20.2)
24: float(20.2)
25: float(20.2)
26: float(20.2)
27: float(20.2)
28: float(20.2)
29: float(20.2)
30: float(20.2)
Actual result:
--------------
0: float(2.0E+1)
1: float(2.0E+1)
2: float(20)
3: float(20.2)
4: float(20.2)
5: float(20.2)
6: float(20.2)
7: float(20.2)
8: float(20.2)
9: float(20.2)
10: float(20.2)
11: float(20.2)
12: float(20.2)
13: float(20.2)
14: float(20.2)
15: float(20.2)
16: float(20.2)
17: float(20.199999999999999)
18: float(20.1999999999999993)
19: float(20.19999999999999929)
20: float(20.199999999999999289)
21: float(20.1999999999999992895)
22: float(20.19999999999999928946)
23: float(20.199999999999999289457)
24: float(20.1999999999999992894573)
25: float(20.19999999999999928945726)
26: float(20.199999999999999289457264)
27: float(20.1999999999999992894572642)
28: float(20.19999999999999928945726424)
29: float(20.19999999999999928945726424)
30: float(20.1999999999999992894572642399)
--
Edit bug report at http://bugs.php.net/?id=50095&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50095&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50095&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50095&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=50095&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50095&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=50095&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=50095&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=50095&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=50095&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=50095&r=support
Expected behavior: http://bugs.php.net/fix.php?id=50095&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=50095&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=50095&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=50095&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50095&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50095&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=50095&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=50095&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=50095&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=50095&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=50095&r=mysqlcfg