py: Fix printing of complex number when imaginary part is nan

modussl
stijn 2015-05-13 21:35:58 +02:00 committed by Damien George
parent 1db3577bcb
commit 709955b601
2 changed files with 7 additions and 2 deletions

View File

@ -59,7 +59,7 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
} else {
mp_format_float(o->real, buf, sizeof(buf), 'g', 7, '\0');
mp_printf(print, "(%s", buf);
if (o->imag >= 0) {
if (o->imag >= 0 || isnan(o->imag)) {
mp_print_str(print, "+");
}
mp_format_float(o->imag, buf, sizeof(buf), 'g', 7, '\0');
@ -73,7 +73,7 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
} else {
sprintf(buf, "%.16g", (double)o->real);
mp_printf(print, "(%s", buf);
if (o->imag >= 0) {
if (o->imag >= 0 || isnan(o->imag)) {
mp_print_str(print, "+");
}
sprintf(buf, "%.16g", (double)o->imag);

View File

@ -43,6 +43,11 @@ print("%.5g" % abs(1j + 2))
# float on lhs should delegate to complex
print(1.2 + 3j)
# check printing of inf/nan
print(float('nan') * 1j)
print(float('inf') * (1 + 1j))
print(float('-inf') * (1 + 1j))
# convert bignum to complex on rhs
ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))