-
Notifications
You must be signed in to change notification settings - Fork 37
Add ^ operator for power #26
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,6 +209,17 @@ public function visit( | |
|
||
break; | ||
|
||
case '#power': | ||
$children[0]->accept($this, $a, $eldnah); | ||
|
||
$acc = function ($b) use ($a, $acc) { | ||
return $acc(pow($a(), $b)); | ||
}; | ||
|
||
$children[1]->accept($this, $acc, $eldnah); | ||
|
||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CS: An empty new line is missing before the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this part please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Short answer, no. Longer, I have basically copy/pasted what is done for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Are tests green? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funny: 147a38d. |
||
|
||
case '#fakegroup': | ||
case '#group': | ||
$children[0]->accept($this, $a, $eldnah); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that
^
has not the same priority (precedence) than an other existing operator?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to many sources found on Google (!!),
^
priority is lower than multiplication and division operators.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said here,
^
operator is left associative (according to my mind and my calculator (2^3^2=64))**
operator is right associative (2 ** 3 ** 2 == 512).What about
Hoa\Math
^
operator ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's right associative here (2^3^2 == 512) like the
**
operator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.