Corrected description of the "//" operator

The operator was previously described to truncate the the value when it in fact floors the result of the division (which can be seen in https://github.com/fabpot/Twig/blob/master/lib/Twig/Node/Expression/Binary/FloorDiv.php#L20).
By the old description one would think that ``{{ -20 // 7 }}`` would yield -2 (as in ``(int)(-20/7)``) when it actually returns -3 (as in ``floor(-20/7)``). Floor is not truncate (cast to int).
This commit is contained in:
ureimers
2013-12-03 12:55:12 +01:00
parent cab9fd9a10
commit a360bc037c
+4 -4
View File
@@ -617,7 +617,7 @@ Arrays and hashes can be nested:
.. code-block:: jinja .. code-block:: jinja
{% set foo = [1, {"foo": "bar"}] %} {% set foo = [1, {"foo": "bar"}] %}
7
.. tip:: .. tip::
Using double-quoted or single-quoted strings has no impact on performance Using double-quoted or single-quoted strings has no impact on performance
@@ -641,9 +641,9 @@ but exists for completeness' sake. The following operators are supported:
* ``%``: Calculates the remainder of an integer division. ``{{ 11 % 7 }}`` is * ``%``: Calculates the remainder of an integer division. ``{{ 11 % 7 }}`` is
``4``. ``4``.
* ``//``: Divides two numbers and returns the truncated integer result. ``{{ 20 * ``//``: Divides two numbers and returns the floored integer result. ``{{ 20
// 7 }}`` is ``2`` (this is just syntactic sugar for the // 7 }}`` is ``2``, ``{{ -20 // 7 }}`` is ``-3``(this is just syntactic
:doc:`round<filters/round>` filter). sugar for the :doc:`round<filters/round>` filter).
* ``*``: Multiplies the left operand with the right one. ``{{ 2 * 2 }}`` would * ``*``: Multiplies the left operand with the right one. ``{{ 2 * 2 }}`` would
return ``4``. return ``4``.