Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70288 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58024 invoked from network); 22 Nov 2013 18:03:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Nov 2013 18:03:48 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.48 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.48 mail-vb0-f48.google.com Received: from [209.85.212.48] ([209.85.212.48:55718] helo=mail-vb0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E9/1B-28674-38C9F825 for ; Fri, 22 Nov 2013 13:03:47 -0500 Received: by mail-vb0-f48.google.com with SMTP id x16so1088682vbf.7 for ; Fri, 22 Nov 2013 10:03: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=tjdXYPWlP7HrHXMQxL7BGQgJ5dRfxNc4xBXW43b7M5U=; b=fOSpR4c+yPhLJFToygqCDOPTPNE9tlQsY92kG3RfDk6cinLSXtGLa9PfVF4iN2GUp+ Qjb+VyXhgINxZpzc9KzvL1JKq0PDxGObzvYmnoirTzhdLrnx5v8yCIsIUmW70lElStiK CclYaZl0yFlLVtA3dNzf1UR//ge0jZpjpn3SicqcBtSES0jZ9nlzM9Y4mHqUoxXdg1Bu afMUDNjyNkt5mLqLi9FrWUnWVw055eds8xs+ir4Flfa2FBl9ixAu1jcjgXOj6Vwbkd7g WTrD0ypdE+QUTH/XmPe661P1LQ3Vtg1vIDFv6Dwd2AI5qAWCFa5E1buigEKuF+Z7WWlN qIQA== MIME-Version: 1.0 X-Received: by 10.58.39.97 with SMTP id o1mr12471018vek.15.1385143424460; Fri, 22 Nov 2013 10:03:44 -0800 (PST) Received: by 10.58.128.33 with HTTP; Fri, 22 Nov 2013 10:03:44 -0800 (PST) In-Reply-To: References: Date: Sat, 23 Nov 2013 02:03:44 +0800 Message-ID: To: Leigh Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e011834d8c72c6f04ebc7d5ab Subject: Re: [PHP-DEV] Power function as operator From: tjerk.meesters@gmail.com (Tjerk Meesters) --089e011834d8c72c6f04ebc7d5ab Content-Type: text/plain; charset=ISO-8859-1 Hi, On Sat, Nov 23, 2013 at 1:14 AM, Leigh wrote: > Definitely something that is missing and would be a welcome addition. > > Where have you placed it in terms of operator precedence? > It was equal to the shift operators and left associative, which was most definitely wrong ;-) I've now changed the operator precedence to one higher than ~ (bitwise not) and right associative. So: -3 ** 2 == -9 ~3 ** 2 == -10, 2 ** 3 ** 2 == 512 I should probably add this in a test case as well =D > On 22 November 2013 16:58, Tjerk Meesters > wrote: > > Hi, > > > > To challenge myself I had tasked myself to introduce a new operator and > > opcode to the language; now that I'm done with it, I wanted to measure > the > > response on the list to actually get it merged before writing an RFC. > > > > My work can be found here: > > https://github.com/datibbaw/php-src/compare/pow-operator > > > > It introduces the pow() function as an operator ** (double asterisk), as > > can be found in languages such as Python (with perhaps the notable > > difference that it's right associative there). > > > > The logic gets exposed via the ZEND_POW opcode and all the logic that > went > > into pow() itself is copied into it. The exceptions are that an > expression > > such as [] ** 2 (squared empty array) will cause a fatal error because > the > > operands are incompatible, whereas pow([], 2) would give 0. > > > > Why this operator? Basically because: > > 1) it's shorter (the keyboard rejoices). > > 2) it's faster (no ZEND_CALL). > > 3) it's found in other languages too. > > > > I've only implemented one of the test suites; there are quite a few for > > just one function, but when needed I can add those others as well. > > > > Btw, changes to vld aren't pushed yet. > > > > Let me know! > > > > -- > > -- > > Tjerk > -- -- Tjerk --089e011834d8c72c6f04ebc7d5ab--