summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormbkma <[email protected]>2019-05-25 23:57:10 +0200
committerraveit65 <[email protected]>2019-06-03 16:33:26 +0200
commit1caf4cda6edf9df4903045c9616abe80e7dc6373 (patch)
treec7950d911dfac777aeb8a6f01032d356dfa613d2
parent5728589745d8d5eab038f8b1a38fd52d60ff4e96 (diff)
downloadmate-calc-1caf4cda6edf9df4903045c9616abe80e7dc6373.tar.bz2
mate-calc-1caf4cda6edf9df4903045c9616abe80e7dc6373.tar.xz
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.
-rw-r--r--src/mp-serializer.c8
1 files 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);