Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52518 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25531 invoked from network); 27 May 2011 10:01:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 May 2011 10:01:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:56634] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/23-25602-7467FDD4 for ; Fri, 27 May 2011 06:01:12 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id B9B4470004DA for ; Fri, 27 May 2011 11:00:36 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 8xH1uKxCTajT for ; Fri, 27 May 2011 11:00:36 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 5FBD97000450 for ; Fri, 27 May 2011 11:00:36 +0100 (WEST) Received: from clk-0081.clk-domain (unknown [85.139.253.17]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 3AD2D2007057 for ; Fri, 27 May 2011 11:00:36 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: Date: Fri, 27 May 2011 11:00:35 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/11.11 (Win32) Subject: Re: [PHP-DEV] INF behavior From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") Em Fri, 27 May 2011 04:03:01 +0100, Philip Olson = escreveu: > Hello geeks, > > A geek is needed to clarify PHP bug #45712. This is an edge case but t= he = > test (bug45712.phpt) contains code similar to the following: > > $inf =3D pow(0, -2); > > var_dump($inf); // float(INF) > var_dump($inf =3D=3D $inf); // bool(false) > var_dump($inf =3D=3D=3D $inf); // bool(true) > ?> > > That's how it's behaved since ~forever (AFAICT) and remains in = > 5.3.7-dev, but PHP 5.4.0-dev changes behavior so both now return true.= > > Is this is how we want it? And how should this be documented/explained= ? What IEEE Std 754-2008 says is this: =C2=AB5.11 Details of comparison predicates 5.11.0 For every supported arithmetic format, it shall be possible to compare o= ne = floating-point datum to another in that format (see 5.6.1). Additionally, floating-point data = represented in different formats shall be comparable as long as the operands=E2=80=99 formats have the same radix.= Four mutually exclusive relations are possible: less than, equal, greate= r = than, and unordered. The last case arises when at least one operand is NaN. Every NaN shall compare unorder= ed = with everything, including itself. Comparisons shall ignore the sign of zero (so +0 =3D =E2=88=920)= . Infinite = operands of the same sign shall compare equal. Languages define how the result of a comparison shall be delivered, in o= ne = of two ways: either as a relation identifying one of the four relations listed above, or as a true-false = response to a predicate that names the specific comparison desired. Table 5.1, Table 5.2, and Table 5.3 exhibit twenty-two functionally = distinct useful predicates and negations with various ad-hoc and traditional names and symbols. Each predicate is= = true if any of its indicated relations is true. The relation =E2=80=9C?=E2=80=9D indicates an unorder= ed relation. (...) (...) Table 5.1 - Required unordered-quiet predicate and negation Unordered quiet predicate | Unordered-quiet Negation -----------------------------------|------------------------------------= --- True Relations | Names | True Relations | Names ---------------|-------------------|------------------------------------= --- EQ | compareQuietEqual | LT GT UN | compareQuietNotEqu= al | =3D | | ?<>, NOT(=3D= ), =E2=89=A0 Given this, I think the behavior of 5.4 is correct because "[i]nfinite = = operands of the same sign shall compare equal" and compareQuietEqual map= s = EQ to true. 5.4 still gives false for NAN=3D=3DNAN, which is also correc= t. This is also what this C99 program gives: #include #include void main() { printf("%d %d\n", INFINITY =3D=3D INFINITY, NAN =3D=3D NAN); } > ./a.out 1 0 -- = Gustavo Lopes