Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37414 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85792 invoked from network); 2 May 2008 23:25:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2008 23:25:47 -0000 Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 213.152.38.186 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 213.152.38.186 freshmint.phcomp.co.uk Linux 2.5 (sometimes 2.4) (4) Received: from [213.152.38.186] ([213.152.38.186:63420] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/75-55202-4F2AB184 for ; Fri, 02 May 2008 19:25:43 -0400 Received: from addw by mint.phcomp.co.uk with local (Exim 4.69) (envelope-from ) id 1Js4dF-0001Mw-7o for internals@lists.php.net; Sat, 03 May 2008 00:25:37 +0100 Date: Sat, 3 May 2008 00:25:37 +0100 To: internals@lists.php.net Message-ID: <20080502232537.GB6064@mint.phcomp.co.uk> References: <001401c8ac74$dda6d060$98f47120$@com> <1209749793.1075.54.camel@inspiron.local> <481B5F45.4030106@gmail.com> <481B6068.9060402@lerdorf.com> <1209758625.1075.87.camel@inspiron.local> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1209758625.1075.87.camel@inspiron.local> User-Agent: Mutt/1.4.1i Organization: Parliament Hill Computers Ltd Subject: Re: [PHP-DEV] Float comparison From: addw@phcomp.co.uk (Alain Williams) On Fri, May 02, 2008 at 01:03:45PM -0700, Todd Ruth wrote: > On Fri, 2008-05-02 at 11:41 -0700, Rasmus Lerdorf wrote: > > Stefan Walk wrote: > > > 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 ;) > > > > Yup, it would be a fatal flaw in the language if that ever came to be. > > > > -Rasmus > > Most people don't care about floating numbers beyond a certain > number of digits. If precision were the only ini setting that > gave us an idea of how much the person cared, I think it would > be fair to use the setting or introduce a new setting. As it > happens, there is another setting. How would you feel about > this returning true: > > php -dserialize_precision=1 -r 'var_dump(1.4 == 1.1);' > > Setting serialize_precision to 1 is a very strong statement of > not caring about those digits. Personally, I don't care about > more than about 6 digits and I don't do much math, so I could > set it to 8 digits and be happy. Not everyone has the luxury > of controlling ini settings, but for those that do, this > would be much nicer than having Hmmm, what you are talking about is implying: $a == $b be implemented as: abs($a - $b) < (max(abs($a), abs($b)) / EPSILON) Where EPSILON is some sort of accuracy factor. It might be possible to implement this easier/faster at a machine code level. The trouble is that doing something like this would be global and might mess up some code written elsewhere. Mind you: any programmer going '$a == $b' on true floating point has got to expect rubbish. This is making things easier for the naive/novice programmer. In this case I don't think that it realy helps since the naive programmer isn't going to have a clue about choosing a good value for EPSILON. Best leave it the way that it is. -- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php Chairman of UKUUG: http://www.ukuug.org/ #include