Actually generate an ast_call for __builtin_pow for the ** operator, otherwise the operator yeilds a ast_function, making "a ** b" not work, but since it's a function, allows **(a, b). Also added tests for exponentiation operator.

This commit is contained in:
Dale Weiler 2013-03-07 23:05:40 +00:00
parent 0367a6175d
commit 12340a6bd0
3 changed files with 25 additions and 2 deletions

View file

@ -1086,7 +1086,10 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
if (CanConstFold(exprs[0], exprs[1])) {
out = (ast_expression*)parser_const_float(parser, powf(ConstF(0), ConstF(1)));
} else {
out = parser_builtin_pow(parser);
ast_call *gencall = ast_call_new(parser_ctx(parser), parser_builtin_pow(parser));
vec_push(gencall->params, exprs[0]);
vec_push(gencall->params, exprs[1]);
out = (ast_expression*)gencall;
}
break;
@ -1435,7 +1438,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
if(CanConstFold1(exprs[0]))
out = (ast_expression*)parser_const_float(parser, ~(qcint)ConstF(0));
else
out = (ast_expression*)ast_binary_new(ctx, INSTR_SUB_F, (ast_expression*)parser_const_float_neg1(parser), exprs[0]);
out = (ast_expression*)
ast_binary_new(ctx, INSTR_SUB_F, (ast_expression*)parser_const_float_neg1(parser), exprs[0]);
break;
}
#undef NotSameType

11
tests/exponentiation.qc Normal file
View file

@ -0,0 +1,11 @@
float pow(float x, float y) {
return __builtin_pow(x, y);
}
void main() {
float hundy = pow(10, 2); // 10^2 == 100
print(ftos(hundy), "\n"); // prints: 100
hundy -= 90; // 100-90 = 10
print(ftos(hundy ** 2), "\n"); // prints: 100
}

View file

@ -0,0 +1,8 @@
# used to test the builtins
I: exponentiation.qc
D: test exponentiation operator and __builtin_pow
T: -execute
C: -std=gmqcc
E: $null
M: 100
M: 100