diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-02 12:52:14 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-02 12:52:14 +0000 |
commit | f49782f0058b0c7bdf21471a9265117089439124 (patch) | |
tree | 876590d937067ff4aab6ee348000abe3c8327d2c /py/objcomplex.c | |
parent | 471b2a8906182616dee2f5be1bf6348b0ff56337 (diff) | |
download | micropython-f49782f0058b0c7bdf21471a9265117089439124.tar.gz micropython-f49782f0058b0c7bdf21471a9265117089439124.zip |
py: Fix cmath.log10; fix printing of complex number with negative imag.
Diffstat (limited to 'py/objcomplex.c')
-rw-r--r-- | py/objcomplex.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/py/objcomplex.c b/py/objcomplex.c index 027292a17a..6a403f6269 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -58,7 +58,10 @@ STATIC void complex_print(void (*print)(void *env, const char *fmt, ...), void * print(env, "%sj", buf); } else { mp_format_float(o->real, buf, sizeof(buf), 'g', 7, '\0'); - print(env, "(%s+", buf); + print(env, "(%s", buf); + if (o->imag >= 0) { + print(env, "+"); + } mp_format_float(o->imag, buf, sizeof(buf), 'g', 7, '\0'); print(env, "%sj)", buf); } @@ -69,7 +72,10 @@ STATIC void complex_print(void (*print)(void *env, const char *fmt, ...), void * print(env, "%sj", buf); } else { sprintf(buf, "%.16g", (double)o->real); - print(env, "(%s+", buf); + print(env, "(%s", buf); + if (o->imag >= 0) { + print(env, "+"); + } sprintf(buf, "%.16g", (double)o->imag); print(env, "%sj)", buf); } |