From 1caf4cda6edf9df4903045c9616abe80e7dc6373 Mon Sep 17 00:00:00 2001 From: mbkma Date: Sat, 25 May 2019 23:57:10 +0200 Subject: mp-serializer: fix scientific presentation of complex numbers So that z = re(z) + im(z) will be displayed with the "+" in scientific notation. In mp_serializer_to_string: DISPLAY_FORMAT_AUTOMATIC I removed the workaround for this issue, so big (or small) imaginary numbers will be displayed in scientific notation again (as against fixed notation before) automatically. --- src/mp-serializer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mp-serializer.c b/src/mp-serializer.c index 2a5c3e3..413d844 100644 --- a/src/mp-serializer.c +++ b/src/mp-serializer.c @@ -175,7 +175,7 @@ mp_cast_to_string(MpSerializer *serializer, const MPNumber *x, int *n_digits) GString *s; gboolean force_sign = TRUE; MPNumber x_im; - int n_complex_digits; + int n_complex_digits = 0; mp_imaginary_component(x, &x_im); @@ -313,6 +313,8 @@ mp_cast_to_exponential_string(MpSerializer *serializer, const MPNumber *x, gbool if (strcmp(string->str, "0") == 0) g_string_assign(string, ""); + else if (!mp_is_negative(&x_im)) + g_string_append(string, "+"); s = g_string_sized_new(1024); exponent = mp_cast_to_exponential_string_real(serializer, &x_im, s, eng_format, &n_complex_digits); @@ -363,8 +365,8 @@ mp_serializer_to_string(MpSerializer *serializer, const MPNumber *x) default: case MP_DISPLAY_FORMAT_AUTOMATIC: s0 = mp_cast_to_string(serializer, x, &n_digits); - if ((n_digits <= serializer->priv->leading_digits && - mp_is_greater_equal(&xcmp, &cmp)) || mp_is_complex(x)) + if (n_digits <= serializer->priv->leading_digits && + mp_is_greater_equal(&xcmp, &cmp)) return s0; else { g_free (s0); -- cgit v1.2.1