Browse code

minor #2255 Simplify power (SpacePossum)

This PR was merged into the 1.x branch.

Discussion
----------

Simplify power

Commits
-------

9307bba Simplify power

Fabien Potencier authored on 17/11/2016 13:15:48
Showing 2 changed files
... ...
@@ -12,6 +12,10 @@ class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary
12 12
 {
13 13
     public function compile(Twig_Compiler $compiler)
14 14
     {
15
+        if (PHP_VERSION_ID >= 50600) {
16
+            return parent::compile($compiler);
17
+        }
18
+
15 19
         $compiler
16 20
             ->raw('pow(')
17 21
             ->subcompile($this->getNode('left'))
18 22
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+--TEST--
2
+Twig parses power expressions
3
+--TEMPLATE--
4
+{{ 2**3 }}
5
+{{ (-2)**3 }}
6
+{{ (-2)**(-3) }}
7
+{{ a ** a }}
8
+{{ a ** b }}
9
+{{ b ** a }}
10
+{{ b ** b }}
11
+--DATA--
12
+return array('a' => 4, 'b' => -2);
13
+--EXPECT--
14
+8
15
+-8
16
+-0.125
17
+256
18
+0.0625
19
+16
20
+0.25