summaryrefslogtreecommitdiff
path: root/src/mp-serializer.c
diff options
context:
space:
mode:
authormbkma <[email protected]>2019-04-23 20:32:55 +0200
committerraveit65 <[email protected]>2019-04-24 23:13:05 +0200
commit76f8baf8847ba93dcdc8e1fbfe1bee28cbae74a7 (patch)
tree74df649093dba5c7529a0b61fbe0d2f445a42404 /src/mp-serializer.c
parent54b767543ee0544ef08ab20baf05ecd768dc88a9 (diff)
downloadmate-calc-76f8baf8847ba93dcdc8e1fbfe1bee28cbae74a7.tar.bz2
mate-calc-76f8baf8847ba93dcdc8e1fbfe1bee28cbae74a7.tar.xz
display small numbers in scientific notation
in number format: automatic
Diffstat (limited to 'src/mp-serializer.c')
-rw-r--r--src/mp-serializer.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mp-serializer.c b/src/mp-serializer.c
index 560aa64..2a5c3e3 100644
--- a/src/mp-serializer.c
+++ b/src/mp-serializer.c
@@ -352,14 +352,19 @@ mp_cast_to_exponential_string(MpSerializer *serializer, const MPNumber *x, gbool
gchar *
mp_serializer_to_string(MpSerializer *serializer, const MPNumber *x)
{
+ MPNumber cmp, xcmp;
gchar *s0;
int n_digits = 0;
-
+ mp_set_from_integer(10, &cmp);
+ mp_xpowy_integer(&cmp, -(serializer->priv->trailing_digits), &cmp);
+ mp_real_component(x, &xcmp);
+ mp_abs(&xcmp, &xcmp);
switch(serializer->priv->format) {
default:
case MP_DISPLAY_FORMAT_AUTOMATIC:
s0 = mp_cast_to_string(serializer, x, &n_digits);
- if (n_digits <= serializer->priv->leading_digits)
+ if ((n_digits <= serializer->priv->leading_digits &&
+ mp_is_greater_equal(&xcmp, &cmp)) || mp_is_complex(x))
return s0;
else {
g_free (s0);