Skip to content

Commit 967dabc

Browse files
committed
docs/{guide,reference}: clarify semantics of a.any() vs a.bool().
1 parent 3c6f467 commit 967dabc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

amaranth/hdl/_ast.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ def __bool__(self):
622622
def bool(self):
623623
"""Conversion to boolean.
624624
625-
Performs the same operation as :meth:`any`.
625+
Returns the same value as :meth:`any`, but should be used where :py:`self` is semantically
626+
a number.
626627
627628
Returns
628629
-------
@@ -934,6 +935,9 @@ def __ror__(self, other):
934935
def any(self):
935936
"""Reduction OR; is any bit :py:`1`?
936937
938+
Performs the same operation as :meth:`bool`, but should be used where :py:`self` is
939+
semantically a bit sequence.
940+
937941
Returns
938942
-------
939943
:class:`Value`, :py:`unsigned(1)`
@@ -2072,7 +2076,7 @@ def __init__(self, shape=None, *, name=None, init=None, reset=None, reset_less=F
20722076

20732077
if decoder is not None:
20742078
# The value representation is specified explicitly. Since we do not expose `hdl._repr`,
2075-
# this is the only way to add a custom filter to the signal right now.
2079+
# this is the only way to add a custom filter to the signal right now.
20762080
if isinstance(decoder, type) and issubclass(decoder, Enum):
20772081
self._value_repr = (_repr.Repr(_repr.FormatEnum(decoder), self),)
20782082
else:

docs/guide.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,14 @@ The following table lists the reduction operations provided by Amaranth:
610610
Operation Description Notes
611611
============ ============================================= ======
612612
``a.all()`` reduction AND; are all bits set? [#opR1]_
613-
``a.any()`` reduction OR; is any bit set? [#opR1]_
613+
``a.any()`` reduction OR; is any bit set? [#opR1]_ [#opR3]_
614614
``a.xor()`` reduction XOR; is an odd number of bits set?
615-
``a.bool()`` conversion to boolean; is non-zero? [#opR2]_
615+
``a.bool()`` conversion to boolean; is non-zero? [#opR2]_ [#opR3]_
616616
============ ============================================= ======
617617

618618
.. [#opR1] Conceptually the same as applying the Python :func:`all` or :func:`any` function to the value viewed as a collection of bits.
619-
.. [#opR2] Conceptually the same as applying the Python :func:`bool` function to the value viewed as an integer.
619+
.. [#opR2] Conceptually the same as applying the Python :class:`bool` function to the value viewed as an integer.
620+
.. [#opR3] While the :meth:`Value.any()` and :meth:`Value.bool` operators return the same value, the use of ``a.any()`` implies that ``a`` is semantically a bit sequence, and the use of ``a.bool()`` implies that ``a`` is semantically a number.
620621
621622
622623
.. _lang-logicops:

0 commit comments

Comments
 (0)