Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70327 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63284 invoked from network); 23 Nov 2013 16:10:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2013 16:10:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.49 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.49 mail-vb0-f49.google.com Received: from [209.85.212.49] ([209.85.212.49:48727] helo=mail-vb0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/71-53898-683D0925 for ; Sat, 23 Nov 2013 11:10:47 -0500 Received: by mail-vb0-f49.google.com with SMTP id p5so1670473vbn.22 for ; Sat, 23 Nov 2013 08:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=vvWzk1+vVVf2xP7zTrqsjAzDry6syrCYH0AeN8rigvc=; b=iwb8CpELgUZg7FDpvGTp24IGnUCfZaaf1V346ZvQ8uj33ERmuz2cOj0hV03T5duPE0 0jRSimtA5nwxiD4uyihjjCG5tAtqKK3R2B8swy2WYqBQX4d6MT20Gvyh/KNyScJ7bd9j w+XYwH2+oFvWYcgiPQ9PE87pLIIKLf+INI+54kAjWv8+JG/hLX717dteAPM4xC73nfPT RMNkzGq5JghZOhhq+On3cLG4e9hxCP9h0JPstoOb86Hmd2Y5Afq3Ilj6aEKTVmapm/KI 7xoi99esUVhSAiLmkM7utxx/TSHzacJKvi6oZMkEpS616gTjZcwgh4c8rvoUEhlExAML j0Yw== MIME-Version: 1.0 X-Received: by 10.220.95.139 with SMTP id d11mr1864303vcn.21.1385223044133; Sat, 23 Nov 2013 08:10:44 -0800 (PST) Received: by 10.58.128.33 with HTTP; Sat, 23 Nov 2013 08:10:44 -0800 (PST) In-Reply-To: <1385221643.7200.25.camel@guybrush> References: <1385221643.7200.25.camel@guybrush> Date: Sun, 24 Nov 2013 00:10:44 +0800 Message-ID: To: =?ISO-8859-1?Q?Johannes_Schl=FCter?= Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c2ae767af6c604ebda5f03 Subject: Re: [PHP-DEV] Power function as operator From: tjerk.meesters@gmail.com (Tjerk Meesters) --001a11c2ae767af6c604ebda5f03 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Johannes, On Sat, Nov 23, 2013 at 11:47 PM, Johannes Schl=C3=BCter wrote: > Hi, > > On Sat, 2013-11-23 at 00:58 +0800, Tjerk Meesters wrote: > > It introduces the pow() function as an operator ** (double asterisk), a= s > > can be found in languages such as Python (with perhaps the notable > > difference that it's right associative there). > > As a comment: In my view we try to keep the language understandable even > for people who aren't as deep into it as we are. There having power as > function serves two purposes. For one it is a normal function and can > easily identified as such with clear precedence etc. Secondly people can stick it in their favorite search engine and can understand what it > means. Searching for ** however isn't as trivial. > I agree with both comments; it's easy to forget the practicality of being able to search on something you don't know, although I would hope that people recognize it as an operator and go here: http://php.net/manual/en/language.operators.arithmetic.php :) > Is the power operation really that common so we have to have it as an > operator and opcode? I don't know what the threshold is, but -/ might be > a nice unary (square) root operator ;-) > Actually, I was going to suggest creating a Unicode token =E2=88=9A for tha= t ;-) > > Looking at github search results > https://github.com/search?l=3DPHP&p=3D1&q=3Dpow&source=3Dcc&type=3DCode > I see quite a few search results but most of them duplication (pow.phpt > from our test suite comes very often) and in others I inspected it > didn't see to be critical code paths gaining much from performance in > (in my personal opinion) loosing readability. > > Randomly picked example: > } elseif ($dec - pow(2,$i) >=3D 0) { > vs. > } elseif ($dec - (2 ** $i) >=3D 0) { > > https://github.com/pkeane/exercises/blob/68b58fb11abfbe8301c202b94906a4ec= 7e041c10/binpal.php#L59 > I consider the former to be better to parse with my brain. > Actually the latter could read: } elseif ($dec - 2 ** $i >=3D 0) { I can't judge on that, because my opinion will obviously be biased :) > > And yes, I understand that there are cases where this will boost > performance by quite a bit, but then we'd rather make strlen() an > opcode. ;-) > Well, why don't we? :) > > johannes > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 -- Tjerk --001a11c2ae767af6c604ebda5f03--