diff options
author | mbkma <[email protected]> | 2020-04-08 01:11:48 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-08 01:11:48 +0200 |
commit | 8bdf0d013359d295e7b26b46d553c9525d7ed0cb (patch) | |
tree | 96235fd9d2df5736553ecc884a9f1b0050ae2365 /src/parserfunc.c | |
parent | 2e5b3891e485237a7860a84b141a770b0a867ea1 (diff) | |
download | mate-calc-8bdf0d013359d295e7b26b46d553c9525d7ed0cb.tar.bz2 mate-calc-8bdf0d013359d295e7b26b46d553c9525d7ed0cb.tar.xz |
Add modular exponentiation ability and add acccording tests
Diffstat (limited to 'src/parserfunc.c')
-rw-r--r-- | src/parserfunc.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/parserfunc.c b/src/parserfunc.c index ff5c6f4..c63ff96 100644 --- a/src/parserfunc.c +++ b/src/parserfunc.c @@ -688,10 +688,29 @@ pf_do_mod(ParseNode* self) mp_free(left); if(right) mp_free(right); - free(ans); + mp_free(ans); return NULL; } - mp_modulus_divide(left, right, ans); + if (self->left->evaluate == pf_do_x_pow_y) + { + MPNumber* base_value = (MPNumber*) (*(self->left->left->evaluate))(self->left->left); + MPNumber* exponent = (MPNumber*) (*(self->left->right->evaluate))(self->left->right); + if(!base_value || !exponent) + { + if(base_value) + mp_free(base_value); + if(exponent) + mp_free(exponent); + mp_free(ans); + return NULL; + } + mp_modular_exponentiation(base_value, exponent, right, ans); + mp_free(base_value); + mp_free(exponent); + } + else + mp_modulus_divide(left, right, ans); + mp_free(left); mp_free(right); return ans; @@ -769,7 +788,7 @@ pf_do_add(ParseNode* self) return ans; } -/*Add (x) Percentage to value. */ +/* Add (x) Percentage to value. */ void* pf_do_add_percent(ParseNode* self) { |