From 8a56a6107dec16b7876721283de2f56e7a9e3169 Mon Sep 17 00:00:00 2001 From: Rolfe Power Date: Wed, 15 Apr 2020 05:05:37 -0400 Subject: Fix empty string return for canceling complex expressions --- src/mp-serializer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mp-serializer.c b/src/mp-serializer.c index 4debd83..3967cbc 100644 --- a/src/mp-serializer.c +++ b/src/mp-serializer.c @@ -209,7 +209,10 @@ mp_to_string(MpSerializer *serializer, const MPNumber *x, int *n_digits) if (n_complex_digits > *n_digits) *n_digits = n_complex_digits; if (strcmp(s->str, "0") == 0 || strcmp(s->str, "+0") == 0 || strcmp(s->str, "−0") == 0) { - /* Ignore */ + /* Ignore unless the real part was also zero and string was cleared*/ + if (string->len == 0) { + g_string_append(string, "0"); + } } else if (strcmp(s->str, "1") == 0) { g_string_append(string, "i"); -- cgit v1.2.1