mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-27 22:22:17 +00:00
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:
parent
0367a6175d
commit
12340a6bd0
3 changed files with 25 additions and 2 deletions
8
parser.c
8
parser.c
|
@ -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
11
tests/exponentiation.qc
Normal 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
|
||||
}
|
8
tests/exponentiation.tmpl
Normal file
8
tests/exponentiation.tmpl
Normal 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
|
Loading…
Reference in a new issue