summaryrefslogtreecommitdiff
path: root/src/mate-calc.c
diff options
context:
space:
mode:
authormbkma <[email protected]>2020-03-05 13:06:45 +0100
committerraveit65 <[email protected]>2020-03-08 21:40:41 +0100
commitb0117b1d5ae73916c6f0d289be1f693bb5f46824 (patch)
tree4751c73751ed9951ae5a1c5b93f04c84593c6974 /src/mate-calc.c
parent91962719d06ce16d8bc3523872b83fae4d151e10 (diff)
downloadmate-calc-b0117b1d5ae73916c6f0d289be1f693bb5f46824.tar.bz2
mate-calc-b0117b1d5ae73916c6f0d289be1f693bb5f46824.tar.xz
Port to GNU MPFR/MPC Library
For further information please visit: https://www.mpfr.org/ http://www.multiprecision.org/mpc
Diffstat (limited to 'src/mate-calc.c')
-rw-r--r--src/mate-calc.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mate-calc.c b/src/mate-calc.c
index 0c2645c..7dc20d8 100644
--- a/src/mate-calc.c
+++ b/src/mate-calc.c
@@ -45,7 +45,7 @@ solve(const char *equation)
{
MPEquationOptions options;
MPErrorCode error;
- MPNumber result;
+ MPNumber result = mp_new();
char *result_str;
memset(&options, 0, sizeof(options));
@@ -57,15 +57,18 @@ solve(const char *equation)
error = mp_equation_parse(equation, &options, &result, NULL);
if(error == PARSER_ERR_MP) {
fprintf(stderr, "Error: %s\n", mp_get_error());
+ mp_clear(&result);
exit(1);
}
else if(error != 0) {
fprintf(stderr, "Error: %s\n", mp_error_code_to_string(error));
+ mp_clear(&result);
exit(1);
}
else {
result_str = mp_serializer_to_string(mp_serializer_new(MP_DISPLAY_FORMAT_AUTOMATIC, 10, 9), &result);
printf("%s\n", result_str);
+ mp_clear(&result);
exit(0);
}
}