#43487 [Com]: Wrong conversion of float to string

From: Date: Mon, 11 Feb 2008 17:49:44 +0000
Subject: #43487 [Com]: Wrong conversion of float to string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122185@lists.php.net to get a copy of this message
 ID:               43487
 Comment by:       oeriksson at mandriva dot com
 Reported By:      jm at wo dot cz
 Status:           Open
 Bug Type:         Strings related
 Operating System: Linux
 PHP Version:      5.2.5
 New Comment:

Here's a shorter URL that hopefully won't wrap:

http://n1.nux.se/php-5.2.5-use-volatile-to-force-float-store.patch


Previous Comments:
------------------------------------------------------------------------

[2008-02-01 12:07:10] oeriksson at mandriva dot com

Pascal Rigaux at Mandriva has a patch for this, please review it.

http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages/cooker/php/current/SOURCES/php-5.2.5-use-volatile-to-force-float-store.patch?revision=161099&view=markup

------------------------------------------------------------------------

[2008-01-31 15:42:55] oeriksson at mandriva dot com

Update; taken from our bugzilla:

"as peroyvind found, the miscompilation is inside Zend/zend_strtod.c,
and -no-ftree-vrp workaround the bug."

------------------------------------------------------------------------

[2008-01-30 19:41:18] oeriksson at mandriva dot com

I think I found the problem. On Mandriva Linux Cooker we are using:

gcc (GCC) 4.2.2 20071128 (prerelease) (4.2.2-2mdv2008.1)
glibc-2.7-1mdv2008.1

If I change the optimization from -O2 to -O0 (-O+zero) the bug goes
away on x86_32.

------------------------------------------------------------------------

[2008-01-28 21:30:37] jm at wo dot cz

The CVS snapshot makes no difference, still getting the same 
incorrect strings.

[jm@st5mag ~]$ php -n -r '$f=array(1E-4, 1E-5, 1E-6, 1E-7, 1E-8); 
foreach ($f as $fval) echo $fval, "\n";'
0.0001
1.0E-5
:.0E-7
:.0E-8
1.0E-8
[jm@st5mag ~]$ php -v
PHP 5.2.6-dev (cli) (built: Jan 28 2008 16:13:46) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Previous poster suggested a CPU-related issue. I have encountered 
this issue on the following CPUs:

vendor_id	: AuthenticAMD
cpu family	: 15
model		: 5
model name	: AMD Opteron(tm) Processor 248
stepping	: 8
cpu MHz		: 2205.074

vendor_id	: GenuineIntel
cpu family	: 6
model		: 13
model name	: Intel(R) Pentium(R) M processor 1.80GHz
stepping	: 6
cpu MHz		: 1800.000

vendor_id	: AuthenticAMD
cpu family	: 15
model		: 37
model name	: AMD Opteron(tm) Processor 252
stepping	: 1
cpu MHz		: 2606.078

------------------------------------------------------------------------

[2008-01-28 07:59:48] oeriksson at mandriva dot com

I get the same problem, but it seems related to what CPU is used.

http://qa.mandriva.com/show_bug.cgi?id=37171


$ uname -a
Linux foo.nux.se 2.6.24-server-0.rc8.2mdv #1 SMP Wed Jan 23 17:15:33
UTC 2008
i686 Intel(R) Pentium(R) 4 CPU 2.80GHz GNU/Linux

$ php -r "var_dump(11.1/111);"
float(0.0:)


$ uname -a
Linux oe.nux.tld 2.6.24-desktop-0.rc8.2mdv #1 SMP Wed Jan 23 18:12:45
CET 2008
x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ GNU/Linux

$ php -r "var_dump(11.1/111);"
float(0.1)


It works with 5.1.6 though.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/43487

-- 
Edit this bug report at http://bugs.php.net/?id=43487&edit=1


Thread (19 messages)

« previous php.bugs (#122185) next »