Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65629 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10628 invoked from network); 4 Feb 2013 11:32:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2013 11:32:57 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; 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:41943] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/B5-14611-56C9F015 for ; Mon, 04 Feb 2013 06:32:55 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 6963070003DD; Mon, 4 Feb 2013 11:32:50 +0000 (WET) 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 Mh8fSooyyV3o; Mon, 4 Feb 2013 11:32:50 +0000 (WET) 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 574027000453; Mon, 4 Feb 2013 11:32:49 +0000 (WET) Received: from damnation.nl.lo.geleia.net (unknown [IPv6:2001:470:94a2:4:21d:baff:feee:cc0b]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 87FD02002FA4; Mon, 4 Feb 2013 11:32:47 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "'Patrick Schaaf'" , internals@lists.php.net, "Frank Liepert" Cc: "'Derick Rethans'" , "'Martin Jansen'" References: <510EA95F.40503@divbyzero.net> <2835262.zO39iNXCyM@rofl> <002d01ce02c8$dbb6d430$93247c90$@Liepert@gmx.de> Date: Mon, 04 Feb 2013 12:32:42 +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: <002d01ce02c8$dbb6d430$93247c90$@Liepert@gmx.de> User-Agent: Opera Mail/12.12 (Linux) Subject: Re: AW: [PHP-DEV] FILTER_VALIDATE_INT and +0/-0 From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Mon, 04 Feb 2013 12:14:50 +0100, Frank Liepert = = wrote: > The change to FILTER_VALIDATE_INT seems to be inconsistent. > > First of all, take the following bug = > (https://bugs.php.net/bug.php?id=3D54096) where it says "PHP defines -= 0 as = > an int.". Where does PHP define it? The documentation says: "An intege= r = > is a number of the set =E2=84=A4 =3D {..., -2, -1, 0, 1, 2, ...}." > > Secondly, try the following code: var_dump(round(-0.1)); > What is the result? Surprise: float(-0) > And it is not a bug (https://bugs.php.net/bug.php?id=3D42477) > > To sum it up: > - FILTER_VALIDATE_INT should never treat "+0" or "-0" as valid integer= s. > - Instead, var_dump needs to be corrected. > - It could be even gone further in adding support for signed zero = > arithmetic (see IEEE754). > You're confusing things. Floats are irrelevant to this discussion. It's = = clear -0. (float) does exist and has a well defined meaning. The situati= on = is manifestly different for integers because there are no separate = positive and negative 0 integers in most likely all the architectures PH= P = runs on. So the question is only whether "+0" or "-0" (or "+0", etc.) should be = accepted as integers by FILTER_VALIDATE_INT. I think they should, becaus= e = we also accept non-canonical inputs such as "+5", i.e., we always accept= a = sign. It's true that 0 is neither positive or negative, but I don't thin= k = "accepts a leading sign, except if it's 0" is a good option. It's an = unnecessary special case. Finally, please don't top post. See = http://lxr.php.net/xref/PHP_TRUNK/README.MAILINGLIST_RULES#67 -- = Gustavo Lopes