Uh oh!
There was an error while loading. Please reload this page.
Add ^ operator for power - #26
Conversation
There was a problem hiding this comment.
Are we sure that ^ has not the same priority (precedence) than an other existing operator?
There was a problem hiding this comment.
According to many sources found on Google (!!), ^ priority is lower than multiplication and division operators.
There was a problem hiding this comment.
Since PHP5.6, we have the ** operator with the following precedence: http://php.net/manual/en/language.operators.precedence.php. It is a right associative operator. Is it the case here?
There was a problem hiding this comment.
As said here,
- the common
^operator is left associative (according to my mind and my calculator (2^3^2=64)) - the PHP
**operator is right associative (2 ** 3 ** 2 == 512).
What about Hoa\Math^ operator ?
There was a problem hiding this comment.
It's right associative here (2^3^2 == 512) like the ** operator.
There was a problem hiding this comment.
Ok, it seem my mind and my college calculator were wrong ;)
https://en.wikipedia.org/wiki/Order_of_operations#Special_cases
There was a problem hiding this comment.
So, do we have the same associativity than in PHP? If yes, why not using **? We will be able to fix test suites directly too.
Hywan
commented
Jul 13, 2015
Are tests green? |
Hywan
commented
Jul 13, 2015
Thanks for the PR! |
There was a problem hiding this comment.
Short answer, no. Longer, I have basically copy/pasted what is done for #multiplication and updated the operation ?
Hywan
commented
Jul 22, 2015
We have to talk about testing :-). We use Any proposal (I have several ones, but I would like your opinion first 😉)? |
Savageman
commented
Sep 29, 2015
Maybe we can have both ^ with left-associativity and ** with right associativity? |
Hywan
commented
Sep 29, 2015
@Savageman Ole. Nop. Stop. Nada. Too much dangerous :-p. We have the |
Hywan
commented
Sep 29, 2015
Let me re-phrase: I don't really understand the need for |
Savageman
commented
Sep 30, 2015
Then I think we should only implement |
Hywan
commented
Sep 30, 2015
@Savageman Agree. @osaris Thought? Is this PR left-associative? |
Metalaka
commented
Sep 30, 2015
As said here, PR is right associative. @Savageman, I was thinking like you before read this:
|
Hywan
commented
Nov 9, 2015
ping? |
Savageman
commented
Nov 9, 2015
After reading the comment from @Metalaka, other sources and how its done in other languages, I now think it's best to implement with right-associativity. It makes more sense in the programming world. |
Hywan
commented
Nov 9, 2015
Ok. @osaris? |
osaris
commented
Nov 24, 2015
My PR is right-associative so what should I do now ? |
Hywan
commented
Nov 25, 2015
@osaris Write test cases. |
Hywan
commented
Nov 25, 2015
@osaris Currently, how do we test the grammar? We generated expressions based on the arithmetic grammar, and then we evaluate them twice: By PHP and by our visitor. We must obtain the same results. If we don't, either there is an error in PHP or there is an error in our visitor. The problem is: We use |
Reference #25