Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87018 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90578 invoked from network); 4 Jul 2015 21:09:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jul 2015 21:09:29 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.218 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.218 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.218] ([81.169.146.218:23403] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/21-02984-78B48955 for ; Sat, 04 Jul 2015 17:09:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1436044164; l=6775; s=domk; d=kelunik.com; h=Content-Type:Cc:To:From:Subject:Date:References:In-Reply-To: MIME-Version; bh=SZl2xfGUwQOgHQcoH4Q8mVNsx0byr+97B2uO7SAffxY=; b=jkMjceTkAIJRgfBGt1aFa/SbFmNzsL0X9yxKuqD9AaNR6+LfKrF9u/3m7du38p1MhDC PbqTQ0cyk9NYz5n3pF9qV5JOsummuDqcLXMC/Mpwi6XuGUtbbj9Mzs1IfZUcD7JweDqV1 UBT9LKzC06QOcd3Zmo6cHgQ04jhmiuTW9ro= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3I6 X-RZG-CLASS-ID: mo00 Received: from mail-wg0-f41.google.com ([74.125.82.41]) by smtp.strato.de (RZmta 37.8 AUTH) with ESMTPSA id 50615cr64L9OVkt (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate) for ; Sat, 4 Jul 2015 23:09:24 +0200 (CEST) Received: by wguu7 with SMTP id u7so111578817wgu.3 for ; Sat, 04 Jul 2015 14:09:24 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.194.60.226 with SMTP id k2mr76178897wjr.10.1436044164180; Sat, 04 Jul 2015 14:09:24 -0700 (PDT) Received: by 10.27.210.82 with HTTP; Sat, 4 Jul 2015 14:09:24 -0700 (PDT) In-Reply-To: References: <33BCE1D0-BA6D-464C-B23D-69AF71356111@ajf.me> <3932E76B-DC75-40CD-8B1A-B84F387707CC@ajf.me> <1EFE20ED-ED80-47D1-B697-58CA4359CA62@ajf.me> Date: Sat, 4 Jul 2015 23:09:24 +0200 Message-ID: To: Sherif Ramadan Cc: =?UTF-8?B?SmFrdWIgS3Viw63EjWVr?= , Dmitry Stogov , Bob Weinand , Andrea Faulds , PHP Internals , Nikita Popov , Aaron Piotrowski , Levi Morrison Content-Type: multipart/alternative; boundary=047d7bacbed649b539051a131697 Subject: Re: [PHP-DEV] Fix division by zero to throw exception (round 2) From: me@kelunik.com (Niklas Keller) --047d7bacbed649b539051a131697 Content-Type: text/plain; charset=UTF-8 2015-07-04 22:56 GMT+02:00 Sherif Ramadan : > Hey guys, > > I'm proposing that we reconsider removing the warning from floating point > division and here's why. > > While IEEE 754 defines special values for floating point arithmetic when > division by zero occurs, there's nothing stopping the language from > providing useful error information to the user, which may help them debug > potentially buggy code. It's true that it's not exceptional since there is > now well defined behavior in the case of changing division by zero to IEEE > 754 standard in PHP. However, PHP didn't actually distinguish between > integer division and floating point division prior to intdiv. So in the > case of division by zero the warning was useful to help someone catch their > mistake. > > Now, the onus is on the person writing the code to decipher whether or not > they created a potential division by zero scenario by deducing how they > arrived at INF at some point in their code. This is creating an unnecessary > burden when we've always provided the user with the useful error > information in the past. I'm not sure why we should remove it now, but > based on this conversation I can see that the confusion resonates around > this urge to convert the warning to an exception and the conflict of it not > being exceptional (in the case of floating point math) since there is now > well defined behavior. > > So my conclusion is that... > > Yes, it's not exceptional. No, we shouldn't throw an exception for division > by zero in floating point arithmetic. No, we shouldn't remove the warning > since it still provides useful information to the person debugging the > code. Debugging the code without this warning can be a monstrosity since > you won't necessarily know at which point in a compounded operation the > division by zero occurred. For example, PHP_INT_MAX ** PHP_INT_MAX creates > an overflow resulting in INF. Though 0 / INF results in 0. So an operation > like (1 / ($x / PHP_INT_MAX ** PHP_INT_MAX) where $x happened to be 0 in > one particular case, makes both hunting down and reproducing the bug quite > difficult without some direction. The warning has historically provided > this direction in the past and I believe that removing it now will only > further the confusion. > > I don't think people actually care about whether or not we keep the > warning. I think what they would care about more is the consistency of the > return value and defined behavior, which I believe we have already > addressed very well. +1, I fully agree. It's not exceptional, but it's potentially buggy code and should therefore produce a warning instead of just returning INF. I assume, most developers don't want to deal with INF in their code. If there's a warning, they can convert it to an exception which would not be possible without it. Regards, Niklas --047d7bacbed649b539051a131697--