From: Dale Weiler Date: Mon, 17 Mar 2014 13:39:59 +0000 (-0400) Subject: Add qc_pow. X-Git-Tag: xonotic-v0.8.0~9 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=06e2cb2b1bd0302b55eeac4a07f67151eb513b18;p=xonotic%2Fgmqcc.git Add qc_pow. --- diff --git a/exec.c b/exec.c index 0bf9fdf..70011c9 100644 --- a/exec.c +++ b/exec.c @@ -822,6 +822,16 @@ static int qc_floor(qc_program_t *prog) { return 0; } +static int qc_pow(qc_program_t *prog) { + qcany_t *base, *exp, out; + CheckArgs(2); + base = GetArg(0); + exp = GetArg(1); + out._float = pow(base->_float, exp->_float); + Return(out); + return 0; +} + static prog_builtin_t qc_builtins[] = { NULL, &qc_print, /* 1 */ @@ -837,7 +847,8 @@ static prog_builtin_t qc_builtins[] = { &qc_strcmp, /* 11 */ &qc_normalize, /* 12 */ &qc_sqrt, /* 13 */ - &qc_floor /* 14 */ + &qc_floor, /* 14 */ + &qc_pow /* 15 */ }; static const char *arg0 = NULL; diff --git a/tests/defs.qh b/tests/defs.qh index 772797a..ed8a5df 100644 --- a/tests/defs.qh +++ b/tests/defs.qh @@ -17,3 +17,4 @@ float (string, string) strcmp = #11; vector (vector) normalize = #12; float (float) sqrt = #13; float (float) floor = #14; +float (float, float) pow = #15; diff --git a/tests/exponentiation.qc b/tests/exponentiation.qc index 5b8f24e..199c4af 100644 --- a/tests/exponentiation.qc +++ b/tests/exponentiation.qc @@ -1,13 +1,13 @@ -float pow(float x, float y) { - return __builtin_pow(x, y); -} - void main() { - float hundy = pow(10, 2); // 10^2 == 100 + float hundy = __builtin_pow(10, 2); // 10^2 == 100 print(ftos(hundy), "\n"); // prints: 100 + hundy = pow(10, 2); + print(ftos(hundy), "\n"); + hundy -= 90; // 100-90 = 10 print(ftos(hundy ** 2), "\n"); // prints: 100 + print(ftos(pow(hundy, 2)), "\n"); // prints: 100 hundy = 10.0f; print(ftos(__builtin_exp(hundy)), "\n"); // prints: 22026.5 diff --git a/tests/exponentiation.tmpl b/tests/exponentiation.tmpl index 0aa7f85..8609624 100644 --- a/tests/exponentiation.tmpl +++ b/tests/exponentiation.tmpl @@ -6,4 +6,6 @@ C: -std=gmqcc E: $null M: 100 M: 100 +M: 100 +M: 100 M: 22026.5