Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions Doc/library/math.integer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ These functions accept integers and objects that implement the
:meth:`~object.__index__` method which is used to convert the object to an integer
number.

The following functions are provided by this module. All return values are
computed exactly and are integers.
The following functions are provided by this module.
Unless stated otherwise below,
all return values are computed exactly and are integers.


.. function:: comb(n, k, /)
Expand Down Expand Up @@ -46,6 +47,20 @@ computed exactly and are integers.
returns ``0``.


.. function:: isprime(n, /)

Return ``True`` if *n* is a prime number, ``False`` otherwise.

A prime number is a natural number greater than 1
that is not a product of two smaller natural numbers.
Negative numbers, ``0`` and ``1`` are not prime.

The argument must be less than 2\ :sup:`64`;
raises :exc:`OverflowError` otherwise.

.. versionadded:: next


.. function:: isqrt(n, /)

Return the integer square root of the nonnegative integer *n*. This is the
Expand Down Expand Up @@ -83,3 +98,21 @@ computed exactly and are integers.
and the function returns ``n!``.

Raises :exc:`ValueError` if either of the arguments are negative.


.. function:: primes(start=2, stop=None)

Return an iterator of the prime numbers *p* with ``start <= p < stop``,
in increasing order.
If *stop* is ``None`` (the default), the iteration does not stop.

Roughly equivalent to
``(p for p in itertools.count(start) if isprime(p))``
for the unbounded form.

The bounds must be less than 2\ :sup:`64`;
raises :exc:`OverflowError` otherwise.
Unbounded iteration raises :exc:`OverflowError`
if the candidates reach that limit.

.. versionadded:: next
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ math
(Contributed by Jeff Epler in :gh:`150534`.)


math.integer
------------

* Added :func:`math.integer.isprime` for primality testing of integers
less than 2**64 and
:func:`math.integer.primes` for iterating over prime numbers.
(Contributed by Serhiy Storchaka in :gh:`153222`.)


os
--

Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(stdout)
STRUCT_FOR_ID(step)
STRUCT_FOR_ID(steps)
STRUCT_FOR_ID(stop)
STRUCT_FOR_ID(store_name)
STRUCT_FOR_ID(strategy)
STRUCT_FOR_ID(strftime)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading