mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
PyOS_double_to_string, and deprecate PyOS_ascii_strtod and PyOS_ascii_atof.
This commit is contained in:
parent
75930f85df
commit
725bfd8489
10 changed files with 253 additions and 96 deletions
|
@ -62,6 +62,43 @@ The following functions provide locale-independent string to number conversions.
|
|||
|
||||
See the Unix man page :manpage:`strtod(2)` for details.
|
||||
|
||||
.. deprecated:: 3.1
|
||||
Use :cfunc:`PyOS_string_to_double` instead.
|
||||
|
||||
|
||||
.. cfunction:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception)
|
||||
|
||||
Convert a string ``s`` to a :ctype:`double`, raising a Python
|
||||
exception on failure. The set of accepted strings corresponds to
|
||||
the set of strings accepted by Python's :func:`float` constructor,
|
||||
except that ``s`` must not have leading or trailing whitespace.
|
||||
The conversion is independent of the current locale.
|
||||
|
||||
If ``endptr`` is ``NULL``, convert the whole string. Raise
|
||||
ValueError and return ``-1.0`` if the string is not a valid
|
||||
representation of a floating-point number.
|
||||
|
||||
If endptr is not ``NULL``, convert as much of the string as
|
||||
possible and set ``*endptr`` to point to the first unconverted
|
||||
character. If no initial segment of the string is the valid
|
||||
representation of a floating-point number, set ``*endptr`` to point
|
||||
to the beginning of the string, raise ValueError, and return
|
||||
``-1.0``.
|
||||
|
||||
If ``s`` represents a value that is too large to store in a float
|
||||
(for example, ``"1e500"`` is such a string on many platforms) then
|
||||
if ``overflow_exception`` is ``NULL`` return ``Py_HUGE_VAL`` (with
|
||||
an appropriate sign) and don't set any exception. Otherwise,
|
||||
``overflow_exception`` must point to a Python exception object;
|
||||
raise that exception and return ``-1.0``. In both cases, set
|
||||
``*endptr`` to point to the first character after the converted value.
|
||||
|
||||
If any other error occurs during the conversion (for example an
|
||||
out-of-memory error), set the appropriate Python exception and
|
||||
return ``-1.0``.
|
||||
|
||||
.. versionadded:: 3.1
|
||||
|
||||
|
||||
.. cfunction:: char* PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d)
|
||||
|
||||
|
@ -117,6 +154,9 @@ The following functions provide locale-independent string to number conversions.
|
|||
|
||||
See the Unix man page :manpage:`atof(2)` for details.
|
||||
|
||||
.. deprecated:: 3.1
|
||||
Use PyOS_string_to_double instead.
|
||||
|
||||
|
||||
.. cfunction:: char* PyOS_stricmp(char *s1, char *s2)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue