mirror of
https://github.com/python/cpython.git
synced 2025-08-24 18:55:00 +00:00
bpo-45995: add "z" format specifer to coerce negative 0 to zero (GH-30049)
Add "z" format specifier to coerce negative 0 to zero. See https://github.com/python/cpython/issues/90153 (originally https://bugs.python.org/issue45995) for discussion. This covers `str.format()` and f-strings. Old-style string interpolation is not supported. Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
parent
dd207a6ac5
commit
b0b836b20c
16 changed files with 368 additions and 43 deletions
|
@ -14372,7 +14372,7 @@ formatfloat(PyObject *v, struct unicode_format_arg_t *arg,
|
|||
double x;
|
||||
Py_ssize_t len;
|
||||
int prec;
|
||||
int dtoa_flags;
|
||||
int dtoa_flags = 0;
|
||||
|
||||
x = PyFloat_AsDouble(v);
|
||||
if (x == -1.0 && PyErr_Occurred())
|
||||
|
@ -14383,9 +14383,9 @@ formatfloat(PyObject *v, struct unicode_format_arg_t *arg,
|
|||
prec = 6;
|
||||
|
||||
if (arg->flags & F_ALT)
|
||||
dtoa_flags = Py_DTSF_ALT;
|
||||
else
|
||||
dtoa_flags = 0;
|
||||
dtoa_flags |= Py_DTSF_ALT;
|
||||
if (arg->flags & F_NO_NEG_0)
|
||||
dtoa_flags |= Py_DTSF_NO_NEG_0;
|
||||
p = PyOS_double_to_string(x, arg->ch, prec, dtoa_flags, NULL);
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue