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.
|
Are tests green? |
|
Thanks for the PR! |
There was a problem hiding this comment.
Can you explain this part please?
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 ?
|
We have to talk about testing :-). We use Any proposal (I have several ones, but I would like your opinion first 😉)? |
|
Maybe we can have both ^ with left-associativity and ** with right associativity? |
|
@Savageman Ole. Nop. Stop. Nada. Too much dangerous :-p. We have the |
|
Let me re-phrase: I don't really understand the need for |
|
Then I think we should only implement |
|
@Savageman Agree. @osaris Thought? Is this PR left-associative? |
|
As said here, PR is right associative. @Savageman, I was thinking like you before read this:
|
|
ping? |
|
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. |
|
Ok. @osaris? |
|
My PR is right-associative so what should I do now ? |
|
@osaris Write test cases. |
|
@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