Bug #52324 [Dup]: bad result when adding two floats
| From: | brunog at micro-examples dot com | Date: | Tue, 13 Jul 2010 08:55:49 +0000 |
| Subject: | Bug #52324 [Dup]: bad result when adding two floats | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152360@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52324&edit=1
ID: 52324
User updated by: brunog at micro-examples dot com
Reported by: brunog at micro-examples dot com
Summary: bad result when adding two floats
Status: Duplicate
Type: Bug
Package: *General Issues
Operating System: ubuntu
PHP Version: 5.2.14RC2
New Comment:
yes the issues you mention are connected to mine
since there are only a few operations in my source code example, and not
billions as in others, maybe it will be easier to track the bug
to me, lunar phase is a stranger to this problem but I can check again
in a few days if you like :))
I believe it is a conjonction between floating point internal
representation and float to str routine that causes problem
I have this problem on CODERO and 1AND1 dedicated servers that come with
ubuntu, so I think many other users may be impacted too
a workaround in my case would be to multiply operands by 100 and to
divide result by 100
it seems that this issues goes back and forth depending on multiple
criteria, and may come again at any time
thank you
Previous Comments:
------------------------------------------------------------------------
[2010-07-13 04:52:25] aharvey@php.net
Actually, the colon is part of the output here: we have a rare bug
that seems to be platform, architecture, compiler and optimisation
level dependent. (It may also involve the phase of the moon, but we
can't be absolutely sure -- I've never been able to reproduce it,
and I've tried pretty hard.)
Other bugs discussing this issue include bug #47716, bug #49764 and
bug #51396.
------------------------------------------------------------------------
[2010-07-13 01:35:03] brunog at micro-examples dot com
strangely it works fine on an older php version
PHP Version => 5.1.6
gives 0.1 as expected
------------------------------------------------------------------------
[2010-07-13 01:16:39] rasmus@php.net
It doesn't show 0.0 on any PHP version I have access to. No idea about
your
5.2.4. That's from 3 years ago. I don't have anything that old on any
of my
machines.
------------------------------------------------------------------------
[2010-07-13 01:10:58] brunog at micro-examples dot com
maybe, but 0.0: is not a correct value at all as an add result, whatever
floating point accuracy is
0.09 + 0.02 gives 0.11 as expected, neither 0.109999999999 nor 0.::
------------------------------------------------------------------------
[2010-07-13 01:04:36] rasmus@php.net
That is the "correct" value according to how computers store floating
point
values. If you want it accurate to 2 decimal places, round() it to 2
decimal
places. Read the big red warning box here:
http://php.net/manual/en/language.types.float.php
------------------------------------------------------------------------
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/bug.php?id=52324
--
Edit this bug report at http://bugs.php.net/bug.php?id=52324&edit=1