Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37403 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11106 invoked from network); 2 May 2008 17:04:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2008 17:04:51 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.184.232 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 64.233.184.232 wr-out-0506.google.com Received: from [64.233.184.232] ([64.233.184.232:25322] helo=wr-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/91-01733-0B94B184 for ; Fri, 02 May 2008 13:04:48 -0400 Received: by wr-out-0506.google.com with SMTP id 50so1046658wri.2 for ; Fri, 02 May 2008 10:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=PNIUuHpb8sDCBJh+qC8g5I/OgfW+G0R4lj57dT7wVfo=; b=BUDTuFoT4BepXpAGPwtqaZOFy7Y/Gh8Rwn29G0/SkMsnn6TfkTvGrnbFJOQgWvDF8Zo3CZ/smOxeC9DTiUmnWZUEsuzg0ki5Ji7n1U1kDKGqS/3o+02r9NPt0ggN1ZH1Rg6cQNYjZq98rJztlFUp0CKRg77ys6fMv15PJNyY4QQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tBtrKXZP5sQ9A3hIdMdV7DrmjswfbB9neX7XL7drnegf1lnRe28i1I2FFTEedERxa05ggyCMyGd7njeAEhbmZ0S8kXiw6ZrB18yTKoviwLyujZljp3Uy79+xB3Py9qFSUUSqWRD1QC5KqiEy88ADSfW8qtxY54G8ULbztppdxk0= Received: by 10.141.36.10 with SMTP id o10mr1443817rvj.176.1209747885168; Fri, 02 May 2008 10:04:45 -0700 (PDT) Received: by 10.141.123.13 with HTTP; Fri, 2 May 2008 10:04:45 -0700 (PDT) Message-ID: Date: Fri, 2 May 2008 19:04:45 +0200 To: "Jonathan Bond-Caron" Cc: internals@lists.php.net In-Reply-To: <001401c8ac74$dda6d060$98f47120$@com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <001401c8ac74$dda6d060$98f47120$@com> Subject: Re: [PHP-DEV] Float comparison From: pierre.php@gmail.com ("Pierre Joye") On Fri, May 2, 2008 at 6:52 PM, Jonathan Bond-Caron wrote: > Hi, > > > > I'm new to the PHP internals list and I'm posting an issue I'm sure has been > mentioned before -- float comparison > > > > I'd like to know if there are reasons not to change the default behavior > when comparing floats. > > > > i.e. This would seem logical to me: > > > > $test = 19.6*100; > > if((float)(string)$test == (double)1960) > > echo "GOOD BEHAVIOR"; > > > > // Implicitely convert the float to string then float (en_US > locale) > > if($test == (double)1960) > > echo "THIS SHOULD PASS by casting > (float)(string)$test internally..."; > > else > > echo "NOT GOOD BEHAVIOR"; > > > > // Exact comparison would still fail > > if($test !== (double)1960) > > echo "GOOD BEHAVIOR"; > > > > Any reason why $test == (double)1960 should fail? I realized we are > comparing two floats, but couldn't php internally convert to string then > float - for the non strict (===) case From our bug report: " Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. " We use this text as automatic reply for bugs about floating points (aka bogus). Cheers, -- Pierre http://blog.thepimp.net | http://www.libgd.org