py: Fix printing of complex number when imaginary part is nan
parent
1db3577bcb
commit
709955b601
|
@ -59,7 +59,7 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
|
||||||
} else {
|
} else {
|
||||||
mp_format_float(o->real, buf, sizeof(buf), 'g', 7, '\0');
|
mp_format_float(o->real, buf, sizeof(buf), 'g', 7, '\0');
|
||||||
mp_printf(print, "(%s", buf);
|
mp_printf(print, "(%s", buf);
|
||||||
if (o->imag >= 0) {
|
if (o->imag >= 0 || isnan(o->imag)) {
|
||||||
mp_print_str(print, "+");
|
mp_print_str(print, "+");
|
||||||
}
|
}
|
||||||
mp_format_float(o->imag, buf, sizeof(buf), 'g', 7, '\0');
|
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 {
|
} else {
|
||||||
sprintf(buf, "%.16g", (double)o->real);
|
sprintf(buf, "%.16g", (double)o->real);
|
||||||
mp_printf(print, "(%s", buf);
|
mp_printf(print, "(%s", buf);
|
||||||
if (o->imag >= 0) {
|
if (o->imag >= 0 || isnan(o->imag)) {
|
||||||
mp_print_str(print, "+");
|
mp_print_str(print, "+");
|
||||||
}
|
}
|
||||||
sprintf(buf, "%.16g", (double)o->imag);
|
sprintf(buf, "%.16g", (double)o->imag);
|
||||||
|
|
|
@ -43,6 +43,11 @@ print("%.5g" % abs(1j + 2))
|
||||||
# float on lhs should delegate to complex
|
# float on lhs should delegate to complex
|
||||||
print(1.2 + 3j)
|
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
|
# convert bignum to complex on rhs
|
||||||
ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))
|
ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue