Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70962 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56360 invoked from network); 2 Jan 2014 18:54:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jan 2014 18:54:33 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.160.45 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.160.45 mail-pb0-f45.google.com Received: from [209.85.160.45] ([209.85.160.45:44189] helo=mail-pb0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/61-48256-6E5B5C25 for ; Thu, 02 Jan 2014 13:54:32 -0500 Received: by mail-pb0-f45.google.com with SMTP id rp16so14753091pbb.4 for ; Thu, 02 Jan 2014 10:54:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=R5KPj64z8vpS+tvwbqRZgKO5ig18+JFtPRKCdnP0WuU=; b=Tp5cF6DGU8UuZHsLKwQQkHd8nYqvvLtS0GiZOGYuGKimUdX0osk/A70HpS09bALN9n cmltUSMSR05JICv4M1SeM4AEZvzSdECsY/zevYJrojMPgI9SNL/NlAbzWHRaYG+cPVVJ 9fVinpoBML4hDoYtTuLqKoy0x98aXp4dExnibjl0tJyO50WKeVmLza7/gbW7C1bE1zxF u1HdZSBpAu9u6bx0NqSNpJcRQHo19tUtOFDnEVnGvelqpfpte68yEKzUsiXF/U7jlnAO 2cMnMRoIcGFZFrfmJ+ERsb/C7ze4K3jvBbb64z9MGm6x7FfBvc1HwBmFDiUvWwwrMBsx YC5g== X-Gm-Message-State: ALoCoQmJeHfAD3gmxVWWSZuKX66QRqNQalFUonzJ5WxegbUJy0ItAz90z1RZpsa8b6Aazisc3fNP X-Received: by 10.68.133.6 with SMTP id oy6mr16816309pbb.153.1388688867858; Thu, 02 Jan 2014 10:54:27 -0800 (PST) Received: from [192.168.200.30] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPSA id bz4sm103590794pbb.12.2014.01.02.10.54.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 02 Jan 2014 10:54:26 -0800 (PST) Message-ID: <52C5B5E1.5050609@lerdorf.com> Date: Thu, 02 Jan 2014 10:54:25 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Robert Stoll , internals@lists.php.net References: <001801cf07e9$a07af1e0$e170d5a0$@tutteli.ch> In-Reply-To: <001801cf07e9$a07af1e0$e170d5a0$@tutteli.ch> X-Enigmail-Version: 1.6 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bJsI31VAQQU9uCDmGfg25juSwUl1CwLn3" Subject: Re: [PHP-DEV] NAN and INF cast to int From: rasmus@lerdorf.com (Rasmus Lerdorf) --bJsI31VAQQU9uCDmGfg25juSwUl1CwLn3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 1/2/14, 10:36 AM, Robert Stoll wrote: > Another behaviour which I find strange is that a division by 0 yields f= alse and not NAN: > var_dump(1.5/0) ; // boolean false >=20 > I am aware of that introducing an E_WARNING would be somewhat a BC brea= k but I still suggest to consider it because I > rather see it as a bug. Consider the following example: > $f =3D INF; //somehow INF was assigned to $f at some point > $g =3D $f - 1; //$g is still INF -> correct IMO > $h =3D (int) $g; // $i =3D 0; -> the value as such is ok IMO but it sho= uld trigger an E_WARNING > $i =3D $h - 1; //$i =3D -1 -> especially hard to detect if one does fur= ther calculations with such a value Are you testing on Windows? Things are a little odd there with its 32-bit ints on a 64-bit OS. There is a lot of work going on right now to clean up the Windows situation. (int)INF is not 0 on 64-bit Linux. INF/NAN convert to 0x8000000000000000 if you force a cast which is why when you cast it to bool you get true. The reason for 0x8000000000000000 is not a PHP thing but an x86-64 convention. This value is the indefinite integer value and basically just tells you that you performed an action that is not defined. And given that it is not defined, you cannot rely on the behaviour which might be why on your platform you are getting zero. Although the subsequent casts you show indicate it isn't actually zero. I don't see anything incorrect here, but I agree we probably could add an E_WARNING to some of these edge cases in addition to the one we have for division by zero. -Rasmus --bJsI31VAQQU9uCDmGfg25juSwUl1CwLn3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: GPGTools - https://gpgtools.org iEYEARECAAYFAlLFteEACgkQlxayKTuqOuBM3gCdEcVMX0E4kUy2gHxXnCMet+lp bucAmgIilV1R5FDsQlDEvkxnx5wEp1wr =w3w+ -----END PGP SIGNATURE----- --bJsI31VAQQU9uCDmGfg25juSwUl1CwLn3--