Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75655 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43573 invoked from network); 17 Jul 2014 07:34:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2014 07:34:19 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:48654] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/07-09067-97C77C35 for ; Thu, 17 Jul 2014 03:34:19 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 95E748800E4; Thu, 17 Jul 2014 03:34:14 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id FWEfKx_zpjZM; Thu, 17 Jul 2014 03:34:14 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 016F78800CB; Thu, 17 Jul 2014 03:34:12 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: Date: Thu, 17 Jul 2014 08:34:09 +0100 Cc: bishop@php.net, PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <7270A150-2BF4-4E4B-907A-47548D705970@ajf.me> References: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> <37F89E54-C5B9-4E81-9D1B-660190BDB1FF@ajf.me> <9F08728B-AF74-4098-8D1D-BC21AB821168@ajf.me> <6cb98adf7a217db7530122c98d2f7d02@mail.gmail.com> <28924D84-6571-4AD3-B541-9A2141BBEFCD@ajf.me> To: Zeev Suraski X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] intdiv() From: ajf@ajf.me (Andrea Faulds) On 17 Jul 2014, at 08:19, Zeev Suraski wrote: > PHP's not Perl. Let's keep it that way please=85 > I don't think it makes sense to add a > specialized integer division operator when we do have a different = division > operator, and I don't think other dynamic languages have such an = operator > - so unlike **, there's no established precedent=85 True, but PHP clearly drew inspiration from Perl, and C, which also has = integer division. Many of these languages don=92t have an integer division operator simply = because they don=92t need one. In most C-like languages and plenty of = non C-like, an integer divided by an integer is always an integer, and = you only get a float result if one or more operands are a float. = However, in languages like PHP, Python, Visual Basic and Pascal, the = division operator is unusually (though I=92d say more intuitively) = defined as sometimes giving a float for integer operands. In the case of = PHP and Python, this is only when the the second operand isn=92t a = factor, while in the case of VB and Pascal, / always results in a float. = It is in these languages that we find the much rarer integer division = operator (Python has //, Visual Basic has \, Pascal has div) because you = can=92t do it the =93normal=94 way. In this respect, it=92s rather = unusual that PHP lacks an integer division operator, or even some = built-in way to do integer division at all, given that all its peers do = support it. There are also languages which don=92t have integers, like JavaScript. = In JS there=92s no need for such an operator as, since it doesn=92t have = integers anyway, Math.floor(x / y) isn=92t going to lose any accuracy. Makes me wonder why we don=92t have one after all these years. I assume = either the division operator hasn=92t always done what id does now (I=92m = not a historian, so I couldn=92t tell you that), or that people have = tended to just go for floor(x / y). After all, that works perfectly on = 32-bit platforms. ;) -- Andrea Faulds http://ajf.me/