diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-05-03 20:33:40 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-05-03 20:33:40 (GMT) |
commit | 725bfd8489e444aedd8dfd686a27ffc308657155 (patch) | |
tree | 99d4e0cc2953794a67a5cff491e1897723a119ff /Doc/c-api/conversion.rst | |
parent | 75930f85df76472686a8c4eb587a2a70562f61fe (diff) | |
download | cpython-725bfd8489e444aedd8dfd686a27ffc308657155.zip cpython-725bfd8489e444aedd8dfd686a27ffc308657155.tar.gz cpython-725bfd8489e444aedd8dfd686a27ffc308657155.tar.bz2 |
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.
Diffstat (limited to 'Doc/c-api/conversion.rst')
-rw-r--r-- | Doc/c-api/conversion.rst | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Doc/c-api/conversion.rst b/Doc/c-api/conversion.rst index 52fe197..403c183 100644 --- a/Doc/c-api/conversion.rst +++ b/Doc/c-api/conversion.rst @@ -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) |