Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37408 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28920 invoked from network); 2 May 2008 18:36:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2008 18:36:59 -0000 Authentication-Results: pb1.pair.com header.from=stefan.walk@gmail.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=stefan.walk@gmail.com; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain gmail.com does not designate 62.75.137.136 as permitted sender) X-PHP-List-Original-Sender: stefan.walk@gmail.com X-Host-Fingerprint: 62.75.137.136 fuer-et.de Linux 2.5 (sometimes 2.4) (4) Received: from [62.75.137.136] ([62.75.137.136:58590] helo=eve.fuer-et.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/F4-01733-94F5B184 for ; Fri, 02 May 2008 14:36:58 -0400 Received: from [192.168.178.34] (drms-590c836f.pool.einsundeins.de [89.12.131.111]) by eve.fuer-et.de (Postfix) with ESMTP id 799E71C59EA0; Fri, 2 May 2008 18:36:54 +0000 (UTC) Message-ID: <481B5F45.4030106@gmail.com> Date: Fri, 02 May 2008 20:36:53 +0200 User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Todd Ruth , jbondc@openmv.com CC: internals@lists.php.net References: <001401c8ac74$dda6d060$98f47120$@com> <1209749793.1075.54.camel@inspiron.local> In-Reply-To: <1209749793.1075.54.camel@inspiron.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Float comparison From: stefan.walk@gmail.com (Stefan Walk) Todd Ruth schrieb: > I'm afraid you'll find Pierre's response representative. The > php devs seem to consider the fact that a theoretically perfect > "==" doesn't exist to mean that the improvements that would > cover 99.9% of user issues with float == shouldn't be made. > > It could be worse, however. At least the cast to string works > as one would expect. Just imagine if those who oppose > improving "==" had their logic extended to the cast to string. > Php might to the following: > > $x=.3+.4+.5; > print "$x\n"; > ?> > > might output "1.19999999999999996447286321199499070644378662109375" > > If someone filed a bug report, they could refer you to that > paper and tell you there's no bug because you're trying to get > a string from float and you never know what you might get. Actually, depending on ini settings, that happens: $ php -dprecision=100 -r 'echo 0.3+0.4+0.5,"\n";' 1.1999999999999999555910790149937383830547332763671875 Don't echo floats, use printf() or alike. And you'll quickly see that the "cast to string before comparision" is a bad idea, because: $ php -dprecision=1 -r 'var_dump((string)1.4 == (string)1.1);' bool(true) Having display settings affect comparisions seems like a really bad idea to me ;) Regards, Stefan