diff options
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) { |