summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-06-08 18:52:54 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-06-08 18:52:54 (GMT)
commit737ea82a5abd448b3e214b44d7d3c579b77e8155 (patch)
treeb0f710ba716db5247dbb6ac88e0a20ea8623f716 /Objects/complexobject.c
parent6ccc9a99dfbb2575daa8e01a8e8e3531b61a9d60 (diff)
downloadcpython-737ea82a5abd448b3e214b44d7d3c579b77e8155.zip
cpython-737ea82a5abd448b3e214b44d7d3c579b77e8155.tar.gz
cpython-737ea82a5abd448b3e214b44d7d3c579b77e8155.tar.bz2
Patch #774665: Make Python LC_NUMERIC agnostic.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index c29d48d..4023fa0 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -272,13 +272,19 @@ complex_dealloc(PyObject *op)
static void
complex_to_buf(char *buf, int bufsz, PyComplexObject *v, int precision)
{
- if (v->cval.real == 0.)
- PyOS_snprintf(buf, bufsz, "%.*gj",
- precision, v->cval.imag);
- else
- PyOS_snprintf(buf, bufsz, "(%.*g%+.*gj)",
- precision, v->cval.real,
- precision, v->cval.imag);
+ char format[32];
+ if (v->cval.real == 0.) {
+ PyOS_snprintf(format, 32, "%%.%ig", precision);
+ PyOS_ascii_formatd(buf, bufsz, format, v->cval.imag);
+ strncat(buf, "j", bufsz);
+ } else {
+ char re[64], im[64];
+
+ PyOS_snprintf(format, 32, "%%.%ig", precision);
+ PyOS_ascii_formatd(re, 64, format, v->cval.real);
+ PyOS_ascii_formatd(im, 64, format, v->cval.imag);
+ PyOS_snprintf(buf, bufsz, "(%s+%sj)", re, im);
+ }
}
static int
@@ -662,7 +668,6 @@ static PyMemberDef complex_members[] = {
static PyObject *
complex_subtype_from_string(PyTypeObject *type, PyObject *v)
{
- extern double strtod(const char *, char **);
const char *s, *start;
char *end;
double x=0.0, y=0.0, z;
@@ -774,7 +779,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
}
errno = 0;
PyFPE_START_PROTECT("strtod", return 0)
- z = strtod(s, &end) ;
+ z = PyOS_ascii_strtod(s, &end) ;
PyFPE_END_PROTECT(z)
if (errno != 0) {
PyOS_snprintf(buffer, sizeof(buffer),