]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Add qc_pow.
authorDale Weiler <killfieldengine@gmail.com>
Mon, 17 Mar 2014 13:39:59 +0000 (09:39 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Mon, 17 Mar 2014 13:39:59 +0000 (09:39 -0400)
exec.c
tests/defs.qh
tests/exponentiation.qc
tests/exponentiation.tmpl

diff --git a/exec.c b/exec.c
index 0bf9fdf4c484c8363dfedb89da0e7e17cd06c71b..70011c977f06ecd7c83f1a36ca1a705064dad414 100644 (file)
--- 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;
index 772797a13f43a2e2a5330f3d1c1920740e74d582..ed8a5df96b552bd1ded7923e5e994f457f120e35 100644 (file)
@@ -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;
index 5b8f24e155b776f570202d5d2789ead95ba71bf9..199c4af1acbed7df669f43f85cec813258bd320b 100644 (file)
@@ -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
index 0aa7f85525cd06f64b76f5d6ae926060132e6111..8609624f3afa1dc24500ba7e42169fbd683dc99a 100644 (file)
@@ -6,4 +6,6 @@ C: -std=gmqcc
 E: $null
 M: 100
 M: 100
+M: 100
+M: 100
 M: 22026.5