]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
document chained pow order 1541/head
authorDavid Lord <davidism@gmail.com>
Tue, 9 Nov 2021 18:50:35 +0000 (10:50 -0800)
committerDavid Lord <davidism@gmail.com>
Tue, 9 Nov 2021 18:52:34 +0000 (10:52 -0800)
docs/templates.rst

index 237a46b5b702232d9f92c6668b133239ef6388fd..89958b86f6e6ac1212fc1549d2c4d98186d419d8 100644 (file)
@@ -1344,8 +1344,19 @@ but exists for completeness' sake.  The following operators are supported:
     ``{{ '=' * 80 }}`` would print a bar of 80 equal signs.
 
 ``**``
-    Raise the left operand to the power of the right operand.  ``{{ 2**3 }}``
-    would return ``8``.
+    Raise the left operand to the power of the right operand.
+    ``{{ 2**3 }}`` would return ``8``.
+
+    Unlike Python, chained pow is evaluated left to right.
+    ``{{ 3**3**3 }}`` is evaluated as ``(3**3)**3`` in Jinja, but would
+    be evaluated as ``3**(3**3)`` in Python. Use parentheses in Jinja
+    to be explicit about what order you want. It is usually preferable
+    to do extended math in Python and pass the results to ``render``
+    rather than doing it in the template.
+
+    This behavior may be changed in the future to match Python, if it's
+    possible to introduce an upgrade path.
+
 
 Comparisons
 ~~~~~~~~~~~