mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-21 10:21:03 +00:00
Add qc_pow.
This commit is contained in:
parent
581c48e337
commit
06e2cb2b1b
4 changed files with 20 additions and 6 deletions
13
exec.c
13
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,4 +6,6 @@ C: -std=gmqcc
|
|||
E: $null
|
||||
M: 100
|
||||
M: 100
|
||||
M: 100
|
||||
M: 100
|
||||
M: 22026.5
|
||||
|
|
Loading…
Reference in a new issue