Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70283 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47656 invoked from network); 22 Nov 2013 16:58:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Nov 2013 16:58:06 -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.51 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.51 mail-vb0-f51.google.com Received: from [209.85.212.51] ([209.85.212.51:33298] helo=mail-vb0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/F8-28674-E1D8F825 for ; Fri, 22 Nov 2013 11:58:06 -0500 Received: by mail-vb0-f51.google.com with SMTP id m10so1037661vbh.24 for ; Fri, 22 Nov 2013 08:58:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=iBD+lXsuAlExhOVHhzI4WJmrnw9H22eTopl5ckg/sOw=; b=NaX/LbSN9XsqkjWyZYyNsTW9c2DN3FOoz2PqKf7dtYjmdncIil4xiuyjUhKbioQE7u 8iefr5A3awu9rkKH76IM1SB95gJ84NuLGT4cATnz/V1zY6zTX9VRq4uqFIEdeHTsmnKi HtkdpsYr3zJbgUmH1Mge5uosALFYU81Sgv9bUu2yK9K9Fq2wFMKtJSo8+CbK5uifE8qY ETQoP2/Dfx+s8jeyKhsvmjxM/iXaEfbWdDx8P6NZ5ZRQoCKL2pDQDaAH3Aelp6jasUnN Z8br6d/LRY+YkOuFXhMH1ikzyvANw9u625SqKs5O0YuiJ+1FWrPCQZaeSvEcO8MNxCFS Pvdw== MIME-Version: 1.0 X-Received: by 10.220.74.69 with SMTP id t5mr12305811vcj.18.1385139482238; Fri, 22 Nov 2013 08:58:02 -0800 (PST) Received: by 10.58.128.33 with HTTP; Fri, 22 Nov 2013 08:58:02 -0800 (PST) Date: Sat, 23 Nov 2013 00:58:02 +0800 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=047d7b624cbecda63104ebc6eafa Subject: Power function as operator From: tjerk.meesters@gmail.com (Tjerk Meesters) --047d7b624cbecda63104ebc6eafa Content-Type: text/plain; charset=ISO-8859-1 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 --047d7b624cbecda63104ebc6eafa--