summaryrefslogtreecommitdiff
path: root/src/mp-serializer.c
diff options
context:
space:
mode:
authormbkma <[email protected]>2019-05-25 23:57:10 +0200
committerraveit65 <[email protected]>2019-06-03 16:19:51 +0200
commit5d8846ee43d02abbfa844657e13ab555676bcff9 (patch)
tree381693adc63e1b405843d2540dff96c815f850e9 /src/mp-serializer.c
parentf20f7d5c0c0286cf3d6b4b85b8dd5779f2bc3dcc (diff)
downloadmate-calc-5d8846ee43d02abbfa844657e13ab555676bcff9.tar.bz2
mate-calc-5d8846ee43d02abbfa844657e13ab555676bcff9.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.
Diffstat (limited to 'src/mp-serializer.c')
-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);