mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
minor #2255 Simplify power (SpacePossum)
This PR was merged into the 1.x branch.
Discussion
----------
Simplify power
Commits
-------
9307bba Simplify power
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user