8000 [3.12] Document PyOS_strtoul and PyOS_strtol (GH-114048) by miss-islington · Pull Request #114618 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.12] Document PyOS_strtoul and PyOS_strtol (GH-114048) #114618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2024
Merged
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
36 changes: 36 additions & 0 deletions Doc/c-api/conversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,42 @@ The return value (*rv*) for these functions should be interpreted as follows:

The following functions provide locale-independent string to number conversions.

.. c:function:: unsigned long PyOS_strtoul(const char *str, char **ptr, int base)

Convert the initial part of the string in ``str`` to an :c:expr:`unsigned
long` value according to the given ``base``, which must be between ``2`` and
``36`` inclusive, or be the special value ``0``.

Leading white space and case of characters are ignored. If ``base`` is zero
it looks for a leading ``0b``, ``0o`` or ``0x`` to tell which base. If
these are absent it defaults to ``10``. Base must be 0 or between 2 and 36
(inclusive). If ``ptr`` is non-``NULL`` it will contain a pointer to the
end of the scan.

If the converted value falls out of range of corresponding return type,
range error occurs (:c:data:`errno` is set to :c:macro:`!ERANGE`) and
:c:macro:`!ULONG_MAX` is returned. If no conversion can be performed, ``0``
is returned.

See also the Unix man page :manpage:`strtoul(3)`.

.. versionadded:: 3.2


.. c:function:: long PyOS_strtol(const char *str, char **ptr, int base)

Convert the initial part of the string in ``str`` to an :c:expr:`long` value
according to the given ``base``, which must be between ``2`` and ``36``
inclusive, or be the special value ``0``.

Same as :c:func:`PyOS_strtoul`, but return a :c:expr:`long` value instead
and :c:macro:`LONG_MAX` on overflows.

See also the Unix man page :manpage:`strtol(3)`.

.. versionadded:: 3.2


.. c:function:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception)

Convert a string ``s`` to a :c:expr:`double`, raising a Python
Expand Down
0