Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37415 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97978 invoked from network); 2 May 2008 23:59:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2008 23:59:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.146.177 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 209.85.146.177 wa-out-1112.google.com Received: from [209.85.146.177] ([209.85.146.177:61419] helo=wa-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/F7-55202-9EAAB184 for ; Fri, 02 May 2008 19:59:38 -0400 Received: by wa-out-1112.google.com with SMTP id v27so917559wah.17 for ; Fri, 02 May 2008 16:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=dPJvvY4/OHgZ2+RSZhbUQjAm7VBpkqGkRZzO+xe2oow=; b=BEU8yVSaU8OH5MJYf2513Bzz7m34qfArLOyHGNmws5BjcCzwmFnkqYLqyz6xJ/RxA5q4VrXY1DMWw3gb84oZ40aIw0o0cuTHxxaSf9tAWwW0mKSX1h8v+GIO/dmNAGchS8PSBA8MTUquVrzZWLV+6p0FP6hODxHSBWsnw0LRJp8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Yds+NbGa4hi/nDjdXGKHzdvFsQPCuWo4ebIAJ6MyS6AO7T9fD2pSBDZCpevY+715sUClkoe9xmOUC6A0mzuvFrNOaVDy8Q7z3mrFscnRyVEfo8dzTnYzPYd3Gm5UsZ5zQOFTZNkJNQaz8zUOQoAL6XwONPeIsGvW8vYnvEDNNA0= Received: by 10.114.173.15 with SMTP id v15mr3555361wae.63.1209772774538; Fri, 02 May 2008 16:59:34 -0700 (PDT) Received: by 10.114.209.15 with HTTP; Fri, 2 May 2008 16:59:34 -0700 (PDT) Message-ID: <10845a340805021659p34b5b403r9c2f00b96eb83803@mail.gmail.com> Date: Sat, 3 May 2008 00:59:34 +0100 Reply-To: RQuadling@GoogleMail.com To: "Alain Williams" Cc: internals@lists.php.net In-Reply-To: <20080502232537.GB6064@mint.phcomp.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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> <20080502232537.GB6064@mint.phcomp.co.uk> Subject: Re: [PHP-DEV] Float comparison From: rquadling@googlemail.com ("Richard Quadling") 2008/5/3 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. What about introducing a "money" or "currency" numeric type which guarantees say accuracy to 8DP? -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"