Skip to content

Commit 2f21cac

Browse files
eendebakptclaude
andcommitted
gh-NNNN: Use _PyWuffs_strtod in float string parsing, replacing _Py_dg_strtod
Replace all calls to _Py_dg_strtod() with _PyWuffs_strtod() from the newly-vendored Wuffs float-parsing adapter: * Python/pystrtod.c: _PyOS_ascii_strtod() now calls _PyWuffs_strtod() (the Wuffs Eisel-Lemire + HPD parser) instead of Gay's _Py_dg_strtod(). * Objects/floatobject.c: double_round() uses _PyWuffs_strtod() for the string-to-double step when converting back from a rounded decimal string. _PyWuffs_strtod() is a correctly-rounded, Bigint-free, platform-strtod-free replacement. It uses the Eisel-Lemire fast path for ~99.9999% of inputs and falls back to the High Precision Decimal (HPD) algorithm for the remainder. Both paths are self-contained within the vendored Wuffs header. After this change _Py_dg_strtod() has no callers outside dtoa.c itself and will be removed in the next commit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 75a180f commit 2f21cac

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Objects/floatobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "pycore_stackref.h" // PyStackRef_AsPyObjectBorrow()
1818
#include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin()
1919
#include "pycore_tuple.h" // _PyTuple_FromPair
20+
#if _PY_SHORT_FLOAT_REPR == 1
21+
#include "../Python/_ryu/pystrtod_wuffs.h" // _PyWuffs_strtod
22+
#endif
2023

2124
#include <float.h> // DBL_MAX
2225
#include <stdlib.h> // strtol()
@@ -939,7 +942,7 @@ double_round(double x, int ndigits) {
939942
/* and convert the resulting string back to a double */
940943
errno = 0;
941944
_Py_SET_53BIT_PRECISION_START;
942-
rounded = _Py_dg_strtod(mybuf, NULL);
945+
rounded = _PyWuffs_strtod(mybuf, NULL);
943946
_Py_SET_53BIT_PRECISION_END;
944947
if (errno == ERANGE && fabs(rounded) >= 1.)
945948
PyErr_SetString(PyExc_OverflowError,

Python/pystrtod.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/* -*- Mode: C; c-file-style: "python" -*- */
22

33
#include <Python.h>
4-
#include "pycore_dtoa.h" // _Py_dg_strtod()
4+
#include "pycore_dtoa.h" // _Py_dg_dtoa(), _Py_dg_freedtoa()
55
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
66

7+
#if _PY_SHORT_FLOAT_REPR == 1
8+
#include "_ryu/pystrtod_wuffs.h" // _PyWuffs_strtod()
9+
#endif
10+
711
#include <locale.h> // localeconv()
812

913
/* Case-insensitive string match used for nan and inf detection; t should be
@@ -101,7 +105,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
101105
errno = 0;
102106

103107
_Py_SET_53BIT_PRECISION_START;
104-
result = _Py_dg_strtod(nptr, endptr);
108+
result = _PyWuffs_strtod(nptr, endptr);
105109
_Py_SET_53BIT_PRECISION_END;
106110

107111
if (*endptr == nptr)

0 commit comments

Comments
 (0)