Skip to content

Commit

Permalink
minor #2255 Simplify power (SpacePossum)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

Simplify power

Commits
-------

9307bba Simplify power
  • Loading branch information
fabpot committed Nov 17, 2016
2 parents 61bf5da + 9307bba commit 9514ca3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Twig/Node/Expression/Binary/Power.php
Expand Up @@ -12,6 +12,10 @@ class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary
{
public function compile(Twig_Compiler $compiler)
{
if (PHP_VERSION_ID >= 50600) {
return parent::compile($compiler);
}

$compiler
->raw('pow(')
->subcompile($this->getNode('left'))
Expand Down
20 changes: 20 additions & 0 deletions test/Twig/Tests/Fixtures/expressions/power.test
@@ -0,0 +1,20 @@
--TEST--
Twig parses power expressions
--TEMPLATE--
{{ 2**3 }}
{{ (-2)**3 }}
{{ (-2)**(-3) }}
{{ a ** a }}
{{ a ** b }}
{{ b ** a }}
{{ b ** b }}
--DATA--
return array('a' => 4, 'b' => -2);
--EXPECT--
8
-8
-0.125
256
0.0625
16
0.25

0 comments on commit 9514ca3

Please sign in to comment.