Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70961 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54280 invoked from network); 2 Jan 2014 18:37:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jan 2014 18:37:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:59505] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/01-48256-2D1B5C25 for ; Thu, 02 Jan 2014 13:37:07 -0500 Received: (qmail 7125 invoked from network); 2 Jan 2014 19:37:02 +0100 Received: from heim-032-99.raab-heim.uni-linz.ac.at (HELO RoLaptop) (193.171.32.99) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 2 Jan 2014 19:37:02 +0100 To: Date: Thu, 2 Jan 2014 19:36:59 +0100 Message-ID: <001801cf07e9$a07af1e0$e170d5a0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: Ac8H6FGKsG/kxIMaTl+WYv6LdaUt8A== Content-Language: de-ch Subject: NAN and INF cast to int From: php@tutteli.ch ("Robert Stoll") Heya, I was quite surprised that a conversion from NAN or INF does not trigger an E_WARNING. Following some examples: An example: $f = NAN; var_dump(++$f); // float NAN var_dump((float) NAN); // float NAN var_dump((int) NAN); // int -2147483648 -> what? var_dump((bool) NAN); // bool true -> makes sense $f = INF; var_dump(++$f); // float INF var_dump((float) INF); // float INF var_dump((int) INF); // int 0 -> what? var_dump((bool) INF); // bool true -> so why int 0? var_dump((int) (bool) INF); // int 1 Another behaviour which I find strange is that a division by 0 yields false and not NAN: var_dump(1.5/0) ; // boolean false I am aware of that introducing an E_WARNING would be somewhat a BC break but I still suggest to consider it because I rather see it as a bug. Consider the following example: $f = INF; //somehow INF was assigned to $f at some point $g = $f - 1; //$g is still INF -> correct IMO $h = (int) $g; // $i = 0; -> the value as such is ok IMO but it should trigger an E_WARNING $i = $h - 1; //$i = -1 -> especially hard to detect if one does further calculations with such a value Thoughts on this? Cheers, Robert