summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormbkma <[email protected]>2021-03-18 20:59:16 +0100
committerRobert Antoni Buj Gelonch <[email protected]>2021-03-19 09:40:27 +0100
commit2dd5cac39d37c8f15ddc3d702e79bba11d8ad8ad (patch)
tree610904a28ce92dee81e760747a95f1f42b06762d
parent2e4b911386a88cfb3d34e8578d0f728f684d13e5 (diff)
downloadmate-calc-2dd5cac39d37c8f15ddc3d702e79bba11d8ad8ad.tar.bz2
mate-calc-2dd5cac39d37c8f15ddc3d702e79bba11d8ad8ad.tar.xz
mp-serializer: init MPNumbers outside of loop
-rw-r--r--src/mp-serializer.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/mp-serializer.c b/src/mp-serializer.c
index af45944..cd72eee 100644
--- a/src/mp-serializer.c
+++ b/src/mp-serializer.c
@@ -89,10 +89,10 @@ mp_to_string_real(MpSerializer *serializer, const MPNumber *x, int base, gboolea
/* Write out the integer component least significant digit to most */
mp_set_from_mp(&integer_component, &temp);
i = 0;
+ MPNumber t = mp_new();
+ MPNumber t2 = mp_new();
+ MPNumber t3 = mp_new();
do {
- MPNumber t = mp_new();
- MPNumber t2 = mp_new();
- MPNumber t3 = mp_new();
long d;
if (serializer->priv->base == 10 && serializer->priv->show_tsep && i == serializer->priv->tsep_count) {
@@ -119,10 +119,10 @@ mp_to_string_real(MpSerializer *serializer, const MPNumber *x, int base, gboolea
(*n_digits)++;
mp_set_from_mp(&t, &temp);
- mp_clear(&t);
- mp_clear(&t2);
- mp_clear(&t3);
} while (!mp_is_zero(&temp));
+ mp_clear(&t);
+ mp_clear(&t2);
+ mp_clear(&t3);
last_non_zero = string->len;
@@ -130,9 +130,9 @@ mp_to_string_real(MpSerializer *serializer, const MPNumber *x, int base, gboolea
/* Write out the fractional component */
mp_set_from_mp(&fractional_component, &temp);
+ MPNumber digit = mp_new();
for (i = serializer->priv->trailing_digits; i > 0 && !mp_is_zero(&temp); i--) {
int d;
- MPNumber digit = mp_new();
mp_multiply_integer(&temp, base, &temp);
mp_floor(&temp, &digit);
@@ -143,8 +143,8 @@ mp_to_string_real(MpSerializer *serializer, const MPNumber *x, int base, gboolea
if(d != 0)
last_non_zero = string->len;
mp_subtract(&temp, &digit, &temp);
- mp_clear(&digit);
}
+ mp_clear(&digit);
/* Strip trailing zeroes */
if (!serializer->priv->show_zeroes || serializer->priv->trailing_digits == 0)