Skip to content

Commit 64a2662

Browse files
Merge #518
518: Define ShiftLeftExpression and ShiftRightExpression evaluation for integer types r=Veykril a=scrabsha Fix #517. I did my best to follow the style of the rest of the specification. Thank you for building Ferrocene!! Co-authored-by: Sasha Pourcelot <sasha.pourcelot@trust-in-soft.com>
2 parents 23dc919 + 6fe92f1 commit 64a2662

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/expressions.rst

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,17 @@ The :t:`evaluation` of a :t:`shift left expression` proceeds as follows:
17191719
The :t:`right operand` is evaluated.
17201720

17211721
#. :dp:`fls_f0p70y92k14f`
1722-
``core::ops::Shl::shl(left_operand, right_operand)`` is invoked.
1722+
If the types of both :t:`[operand]s` are :t:`[integer type]s`, then the
1723+
:t:`shift left expression` evaluates to the value of the left :t:`operand`
1724+
whose bits are shifted left by the number of positions the right :t:`operand`
1725+
evaluates to. Vacated bits are filled with zeros. ``lhs << rhs`` evaluates
1726+
to :math:`\mathrm{lhs} \times 2 ^ \mathrm{rhs}`, casted to the type of the left
1727+
:t:`operand`. If the value of the right :t:`operand` is negative or greater
1728+
than or equal to the width of the left operand, then the operation results in
1729+
an :t:`arithmetic overflow`.
1730+
1731+
#. :dp:`fls_8QGbl2SBU3R0`
1732+
Otherwise, ``core::ops::Shl::shl(left_operand, right_operand)`` is invoked.
17231733

17241734
:dp:`fls_303r0u6ug215`
17251735
The :t:`evaluation` of a :t:`shift right expression` proceeds as follows:
@@ -1730,8 +1740,20 @@ The :t:`evaluation` of a :t:`shift right expression` proceeds as follows:
17301740
#. :dp:`fls_gurl2ve58drz`
17311741
The :t:`right operand` is evaluated.
17321742

1743+
#. :dp:`fls_r02OGonXp93A`
1744+
If the types of both :t:`[operand]s` are :t:`[integer type]s`, then the
1745+
:t:`shift right expression` evaluates to the value of the left :t:`operand`
1746+
whose bits are shifted right by the number of positions the right
1747+
:t:`operand` evaluates to. If the type of the left :t:`operand` is any
1748+
:t:`signed integer type` and is negative, then vacated bits are filled
1749+
with ones. Otherwise, vacated bits are filled with zeros. ``lhs >> rhs``
1750+
evaluates to :math:`\mathrm{lhs} / 2^ \mathrm{rhs}`, casted to the type of
1751+
the left :t:`operand`. If the value of the right :t:`operand` is negative,
1752+
greater than or equal to the width of the left operand, then the operation
1753+
results in an :t:`arithmetic overflow`.
1754+
17331755
#. :dp:`fls_xkyj83mcb9d5`
1734-
``core::ops::Shr::shr(left_operand, right_operand)`` is invoked.
1756+
Otherwise, ``core::ops::Shr::shr(left_operand, right_operand)`` is invoked.
17351757

17361758
.. rubric:: Examples
17371759

@@ -5099,9 +5121,11 @@ Arithmetic Overflow
50995121
-------------------
51005122

51015123
:dp:`fls_oFIRXBPXu6Zv`
5102-
An :t:`arithmetic overflow` occurs when an :t:`arithmetic expression` or a
5103-
:t:`negation expression` computes a :t:`value` of a :t:`scalar type` that lies
5104-
outside of the range of valid :t:`[value]s` for the :t:`scalar type`.
5124+
An :t:`arithmetic overflow` occurs when an :t:`operator expression` computes a
5125+
:t:`value` of a :t:`scalar type` that lies outside of the range of valid
5126+
:t:`[value]s` for the :t:`scalar type` or when one or more :t:`operand` of an
5127+
:t:`operator expression` lies outside of the range of valid :t:`[value]s` for
5128+
the operation.
51055129

51065130
.. rubric:: Dynamic Semantics
51075131

0 commit comments

Comments
 (0)