utils: fix docstring syntax.

This commit is contained in:
Catherine 2024-01-22 22:42:44 +00:00
parent db7e64960c
commit b3639c4cc5

View file

@ -2,13 +2,15 @@ import operator
from ._utils import deprecated
__all__ = ["ceil_log2", "exact_log2", "log2_int", "bits_for"]
def ceil_log2(n):
"""Returns the integer log2 of the smallest power-of-2 greater than or equal to `n`.
"""Returns the integer log2 of the smallest power-of-2 greater than or equal to ``n``.
Raises a `ValueError` for negative inputs."""
Raises a ``ValueError`` for negative inputs.
"""
n = operator.index(n)
if n < 0:
raise ValueError("{n} is negative")
@ -18,9 +20,10 @@ def ceil_log2(n):
def exact_log2(n):
"""Returns the integer log2 of `n`, which must be an exact power of two.
"""Returns the integer log2 of ``n``, which must be an exact power of two.
Raises a `ValueError` if `n` is not a power of two."""
Raises a ``ValueError`` if ``n`` is not a power of two.
"""
n = operator.index(n)
if n <= 0 or (n & (n - 1)):
raise ValueError("{n} is not a power of 2")