Fixes #6280 : Added right associativity to 'pow' function

This commit is contained in:
Ankush Patil 2019-11-09 11:24:33 +05:30 committed by ridiculousfish
parent 91bda38d57
commit ee982c4f6c
2 changed files with 19 additions and 2 deletions

View file

@ -444,11 +444,23 @@ static te_expr *factor(state *s) {
/* <factor> = <power> {"^" <power>} */
te_expr *ret = power(s);
te_expr *insertion = 0;
while (s->type == TOK_INFIX && (s->function == (const void *)(te_fun2)pow)) {
te_fun2 t = (te_fun2)s->function;
next_token(s);
ret = NEW_EXPR(TE_FUNCTION2, ret, power(s));
ret->function = (const void *)t;
if (insertion) {
/* Make exponentiation go right-to-left. */
te_expr *insert = NEW_EXPR(TE_FUNCTION2, insertion->parameters[1], power(s));
insert->function = (const void *)t;
insertion->parameters[1] = insert;
insertion = insert;
} else {
ret = NEW_EXPR(TE_FUNCTION2, ret, power(s));
ret->function = (const void *)t;
insertion = ret;
}
}
return ret;

View file

@ -59,6 +59,11 @@ math '-10^15'
# CHECK: 100000000000000
# CHECK: -1000000000000000
math 3^0.5^2
math -2^2
# CHECK: 1.316074
# CHECK: 4
math -s0 '1.0 / 2.0'
math -s0 '3.0 / 2.0'
math -s0 '10^15 / 2.0'