mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-31 21:43:01 +08:00
Fixes #6280 : Added right associativity to 'pow' function
This commit is contained in:
parent
91bda38d57
commit
ee982c4f6c
|
@ -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;
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue
Block a user