From b165ac859d8dd75f13890d63b1d7a27b2edf2259 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 7 Mar 2024 21:11:43 -0800 Subject: [PATCH] docs: add rationale for floordiv rounding behavior (#3845) --- docs/types.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/types.rst b/docs/types.rst index 44d66fa28d..86b5cdde49 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -132,7 +132,7 @@ Shifting is only available for 256-bit wide types. That is, ``x`` must be ``int2 While at runtime shifts are unchecked (that is, they can be for any number of bits), to prevent common mistakes, the compiler is stricter at compile-time and will prevent out of bounds shifts. For instance, at runtime, ``1 << 257`` will evaluate to ``0``, while that expression at compile-time will raise an ``OverflowException``. .. note:: - Integer division has different rounding semantics than Python for negative numbers: Vyper rounds towards zero, while Python rounds towards negative infinity. For example, ``-1 // 2` will return ``-1`` in Python, but ``0`` in Vyper. + Integer division has different rounding semantics than Python for negative numbers: Vyper rounds towards zero, while Python rounds towards negative infinity. For example, ``-1 // 2`` will return ``-1`` in Python, but ``0`` in Vyper. This preserves the spirit (but not the text!) of the reasoning for Python's round-towards-negative-infinity behavior, which is that the behavior of ``//`` combined with the behavior of ``%`` preserves the following identity no matter if the quantities are negative or non-negative: ``(x // y) * y + (x % y) == x``. .. index:: ! uint, ! uintN, ! unsigned integer