diff options
author | Eric Smith <eric@trueblade.com> | 2008-07-17 17:48:39 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2008-07-17 17:48:39 (GMT) |
commit | 454816d8bdd6ec9bb986aa31760518e622dc1ea7 (patch) | |
tree | 3ee9ce763f7c0545f625b9de580ca98722cb7080 /Objects/stringobject.c | |
parent | 4347c44f1834887602402b7eec0e82214bd6bd1d (diff) | |
download | cpython-454816d8bdd6ec9bb986aa31760518e622dc1ea7.zip cpython-454816d8bdd6ec9bb986aa31760518e622dc1ea7.tar.gz cpython-454816d8bdd6ec9bb986aa31760518e622dc1ea7.tar.bz2 |
Issue 3382: Make '%F' and float.__format__('F') convert results to upper case.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 793cc88..b161c8c 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -4320,8 +4320,12 @@ formatfloat(char *buf, size_t buflen, int flags, } if (prec < 0) prec = 6; - if (type == 'f' && fabs(x)/1e25 >= 1e25) - type = 'g'; + if ((type == 'f' || type == 'F') && (fabs(x) / 1e25) >= 1e25) { + if (type == 'f') + type = 'g'; + else + type = 'G'; + } /* Worst case length calc to ensure no buffer overrun: 'g' formats: @@ -4340,7 +4344,8 @@ formatfloat(char *buf, size_t buflen, int flags, */ if (((type == 'g' || type == 'G') && buflen <= (size_t)10 + (size_t)prec) || - (type == 'f' && buflen <= (size_t)53 + (size_t)prec)) { + ((type == 'f' || type == 'F') && + buflen <= (size_t)53 + (size_t)prec)) { PyErr_SetString(PyExc_OverflowError, "formatted float is too long (precision too large?)"); return -1; @@ -4910,8 +4915,6 @@ PyString_Format(PyObject *format, PyObject *args) case 'F': case 'g': case 'G': - if (c == 'F') - c = 'f'; pbuf = formatbuf; len = formatfloat(pbuf, sizeof(formatbuf), flags, prec, c, v); |