# [vote] pow-operator

- Thread: https://externals.io/message/70727
- Original archive: https://news-web.php.net/php.internals/70727
- Started by Tjerk Meesters on 2013-12-18T08:31:46+00:00
- Messages: 15
- RFC: Exponential operator (Implemented (PHP 5.6)) — https://externals.io/rfc/pow-operator.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #70727 — Tjerk Meesters — 2013-12-18T08:31:46+00:00

URL: https://externals.io/message/70727#70727

Hi internals,

I've opened up the pow-operator RFC for voting.

https://wiki.php.net/rfc/pow-operator#proposed_voting_choices

Contrary to previous emails, the vote will be an all-or-nothing "Yes / No".

The proposed voting cut off date is 31st of Dec.


-- 
--
Tjerk

---

## #70735 — Tjerk Meesters — 2013-12-19T00:03:29+00:00

URL: https://externals.io/message/70727#70735 · In reply to: #70727

Hi,

As it currently stands the votes are quite polarized, so let me address the
most likely issue: associativity.

The reason I chose for having it right associative is based on mathematical
notation, not a personal preference. I do personally think that the
distinction isn't going to matter in 99% of the cases and nobody in their
right mind would write `$x ** $y ** $z` in production code without testing
either. And lastly, Matlab is wrong, there's only one right associativity :)

If this proposal doesn't make it, I have no intentions on restarting it in
the future to address above concerns.

That said, if there are other reasons for voting 'no' besides
associativity, feel free to shoot me an email or discuss it on the list.


On Wed, Dec 18, 2013 at 4:31 PM, Tjerk Meesters <tjerk.meesters@gmail.com>wrote:

> Hi internals,
>
> I've opened up the pow-operator RFC for voting.
>
> https://wiki.php.net/rfc/pow-operator#proposed_voting_choices
>
> Contrary to previous emails, the vote will be an all-or-nothing "Yes / No".
>
> The proposed voting cut off date is 31st of Dec.
>
>
> --
> --
> Tjerk
>



-- 
--
Tjerk

---

## #70736 — Kris Craig — 2013-12-19T00:35:23+00:00

URL: https://externals.io/message/70727#70736 · In reply to: #70735

>
>
> That said, if there are other reasons for voting 'no' besides
> associativity, feel free to shoot me an email or discuss it on the list.
>

What did it for me was the lower precedence for the unary minus.  I don't
want to have another language that thinks a negative number squared is a
negative number.  I understand and respect your reasoning as outlined in
the RFC, but this is a deal-breaker for me.

--Kris

---

## #70737 — Tjerk Meesters — 2013-12-19T02:04:11+00:00

URL: https://externals.io/message/70727#70737 · In reply to: #70736

Hi Kris,




>
> > […]
>
> What did it for me was the lower precedence for the unary minus.  I don't
> want to have another language that thinks a negative number squared is a
> negative number.  I understand and respect your reasoning as outlined in
> the RFC, but this is a deal-breaker for me.
>

I've had a short discussion with Anthony about this and he convinced me
that I was indeed wrong about my "unary minus" reasoning; therefore I have
updated the RFC to reflect that. So:

echo -3 ** 2; // 9
echo 1 - 3 ** 2; // -8

The unary minus is now at the same level as `[`, the array dereferencing
operator.


>
> --Kris
>
>


-- 
--
Tjerk

---

## #70738 — Hannes Magnusson — 2013-12-19T02:08:31+00:00

URL: https://externals.io/message/70727#70738 · In reply to: #70737

On Wed, Dec 18, 2013 at 6:04 PM, Tjerk Meesters
<tjerk.meesters@gmail.com> wrote:
> Hi Kris,
>
>
> 
>
> > […]
>
> I've had a short discussion with Anthony about this and he convinced me
> that I was indeed wrong about my "unary minus" reasoning; therefore I have
> updated the RFC to reflect that. So:
>


I'm a little bit confused.

Are you modifying the poll, and the rfc itself, in the middle of a vote?

-Hannes

---

## #70739 — Levi Morrison — 2013-12-19T02:38:19+00:00

URL: https://externals.io/message/70727#70739 · In reply to: #70737

>
> > […]
>
> I've had a short discussion with Anthony about this and he convinced me
> that I was indeed wrong about my "unary minus" reasoning; therefore I have
> updated the RFC to reflect that. So:
>
> echo -3 ** 2; // 9
> echo 1 - 3 ** 2; // -8
>
> The unary minus is now at the same level as `[`, the array dereferencing
> operator.
>

We should follow the mathematic precedence rules; -3 ** 2 should be -9.

Note that "-3^2" as input to Mathematica, Matlab and Google search engine
all gave -9 as the answer, *as mathematically expected*.

---

## #70740 — Tjerk Meesters — 2013-12-19T03:17:08+00:00

URL: https://externals.io/message/70727#70740 · In reply to: #70738

Hi Hannes,


On Thu, Dec 19, 2013 at 10:08 AM, Hannes Magnusson <
hannes.magnusson@gmail.com> wrote:

> On Wed, Dec 18, 2013 at 6:04 PM, Tjerk Meesters
> <tjerk.meesters@gmail.com> wrote:
> > […]
> wrote:
> > […]
> list.
> > […]
> don't
> > […]
> have
> > […]
>
>
> I'm a little bit confused.
>
> Are you modifying the poll, and the rfc itself, in the middle of a vote?
>

You're right. I've made a faux pas, I shouldn't have done that.

Sorry Kris, the change is reverted; in fact, the following documents back
up my original implementation choice:
- http://mathforum.org/library/drmath/view/53194.html
-
http://math.stackexchange.com/questions/491933/exponent-rules-with-negative-numbers
-
http://math.stackexchange.com/questions/68833/what-does-22-evaluate-to/68834#68834

If the conceptual design of php is that unary operators must bind stronger
than any binary operator, we would have to restart the vote but I'm hoping
that won't be necessary.

I shouldn't make decisions before coffee. Apologies for the confusion!


>
> -Hannes
>



-- 
--
Tjerk

---

## #70741 — Sherif Ramadan — 2013-12-19T03:59:24+00:00

URL: https://externals.io/message/70727#70741 · In reply to: #70740

On Wed, Dec 18, 2013 at 10:17 PM, Tjerk Meesters
<tjerk.meesters@gmail.com>wrote:

> Hi Hannes,
>
>
> On Thu, Dec 19, 2013 at 10:08 AM, Hannes Magnusson <
> hannes.magnusson@gmail.com> wrote:
>
> > […]
> is a
> > […]
> in
> > […]
>
> You're right. I've made a faux pas, I shouldn't have done that.
>
> Sorry Kris, the change is reverted; in fact, the following documents back
> up my original implementation choice:
> - http://mathforum.org/library/drmath/view/53194.html
> -
>
> http://math.stackexchange.com/questions/491933/exponent-rules-with-negative-numbers
> -
>
> http://math.stackexchange.com/questions/68833/what-does-22-evaluate-to/68834#68834
>
> If the conceptual design of php is that unary operators must bind stronger
> than any binary operator, we would have to restart the vote but I'm hoping
> that won't be necessary.
>
> I shouldn't make decisions before coffee. Apologies for the confusion!
>
>
> > […]
>
>
>
> --
> --
> Tjerk
>


I honestly do not think that the preference of associativity should
out-weigh the benefits of this RFC (having an exponentiation operator).

As covered in the discussion portion and the RFC, the matter of
associativity is clearly preferential and varies form one language to
another, with the majority of languages (reviewed) leaning towards
right-associative exponentiation operators due to the usefulness of
power-tower. Now, with all this said, that doesn't change the fact that
forcing operator precedence is always possible in every language and no
good developer would rather be sorry than safe. So why associativity should
be a strong basis for accepting or rejecting this RFC is beyond me.
Personally, I would rather have the operator in the language, regardless of
the associativity, than not have it at all.

---

## #70742 — Pierre Joye — 2013-12-19T06:52:17+00:00

URL: https://externals.io/message/70727#70742 · In reply to: #70740

On Thu, Dec 19, 2013 at 4:17 AM, Tjerk Meesters
<tjerk.meesters@gmail.com> wrote:

> I shouldn't make decisions before coffee. Apologies for the confusion!

Right :)

Please restart the poll then and extend the end date.

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #70743 — Kris Craig — 2013-12-19T08:12:27+00:00

URL: https://externals.io/message/70727#70743 · In reply to: #70742

> On Thu, Dec 19, 2013 at 4:17 AM, Tjerk Meesters
> <tjerk.meesters@gmail.com> wrote:
>
> > […]
>
> Right :)
>
> Please restart the poll then and extend the end date.
>
> Cheers,
> --
> Pierre
>
> @pierrejoye | http://www.libgd.org
>

Agreed.  I like(d) the change but they're right it shouldn't happen in the
middle of a vote.

How about modifying the RFC so that there's a voting option for each method
(three options total)?  We've done something similar on previous votes
without any problems.  Then you could wipe all the votes clean and start
the process over as the others suggested.  I think that'd be a reasonable
approach.

--Kris

---

## #70753 — Andrea Faulds — 2013-12-19T18:08:44+00:00

URL: https://externals.io/message/70727#70753 · In reply to: #70739

> > […]
>
> We should follow the mathematic precedence rules; -3 ** 2 should be -9.
>
> Note that "-3^2" as input to Mathematica, Matlab and Google search engine
> all gave -9 as the answer, *as mathematically expected*.
>

It would be quite strange if we treated "0 - 3 ^ 2" and "- 3 ^ 2" 
differently. They should be identical!

-- 
Andrea Faulds
http://ajf.me/

---

## #70755 — Sean Coates — 2013-12-19T18:18:57+00:00

URL: https://externals.io/message/70727#70755 · In reply to: #70753

Sorry I'm late (possibly too late?) to this, but:

1) if `pow()` is turning from a function into a construct, can it still be used for callbacks? I don't see a mention of that part in the RFC.
2) if `pow()` drops the overhead of a function call, does `-3 ** 2` really gain us anything over `pow(-3, 2)`? The latter is /far/ less ambiguous IMO.

S

---

## #70756 — Andrea Faulds — 2013-12-19T18:41:03+00:00

URL: https://externals.io/message/70727#70756 · In reply to: #70755

> Sorry I'm late (possibly too late?) to this, but:
>
> 1) if `pow()` is turning from a function into a construct, can it still be used for callbacks? I don't see a mention of that part in the RFC.
> 2) if `pow()` drops the overhead of a function call, does `-3 ** 2` really gain us anything over `pow(-3, 2)`? The latter is /far/ less ambiguous IMO.
>

In answer to your second point: Yes. Math is much easier when you don't 
have to write everything in Polish notation. I don't want to do 
pow(add(2, div(7, 3)), 8), I want to do (2 + 7/3) ** 8.

-- 
Andrea Faulds
http://ajf.me/

---

## #70757 — Tjerk Meesters — 2013-12-19T19:09:53+00:00

URL: https://externals.io/message/70727#70757 · In reply to: #70755

Hi Sean,




> Sorry I'm late (possibly too late?) to this, but:
>
> 1) if `pow()` is turning from a function into a construct, can it still be
> used for callbacks? I don't see a mention of that part in the RFC.
>

It's implied in this section:

No changes to existing code, safe for one:

var_dump(pow([], 2)); // int(0) instead of float(0)


Perhaps it could be made more obvious, but yes, the original function
remains there to serve exactly the purpose of callbacks; its innards have
been replaced by calling the `PHP_SAPI` pow_function(), though.


> 2) if `pow()` drops the overhead of a function call, does `-3 ** 2` really
> gain us anything over `pow(-3, 2)`? The latter is /far/ less ambiguous IMO.
>

Yes, it allows you to write an expression more naturally; regarding the
second part of your question, `(-3) ** 2` is also far less ambiguous :)


> S
>
>


-- 
--
Tjerk

---

## #70758 — Christopher Jones — 2013-12-19T19:14:18+00:00

URL: https://externals.io/message/70727#70758 · In reply to: #70757

> Hi Sean,
>
>
> 
>
> > […]
>
> It's implied in this section:
>
> No changes to existing code, safe for one:
>
> var_dump(pow([], 2)); // int(0) instead of float(0)
>
>
> Perhaps it could be made more obvious, but yes, the original function
> remains there to serve exactly the purpose of callbacks; its innards have
> been replaced by calling the `PHP_SAPI` pow_function(), though.


Can you make the RFC clearer?

(In general, RFCs are not good at accepting feedback from mail list discussions.)

Chris


-- 
christopher.jones@oracle.com  http://twitter.com/ghrd
Free PHP & Oracle book:
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html
