From 6141bc35d0d5864dde72565a56cf1fb4dc5d0f03 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sun, 23 Feb 2003 22:14:07 +0000 Subject: [PATCH] Removed the 'random' GIB builtin and replaced it with the rand() math function in the math evaluator. Added the trunc() math function as well. --- include/ops.h | 2 ++ libs/gib/exp.c | 2 ++ libs/gib/gib_builtin.c | 12 ------------ libs/gib/ops.c | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/ops.h b/include/ops.h index 397386262..cc988e56a 100644 --- a/include/ops.h +++ b/include/ops.h @@ -50,4 +50,6 @@ double Func_Acos (double *oplist, unsigned int numops); double Func_Atan (double *oplist, unsigned int numops); double Func_Sqrt (double *oplist, unsigned int numops); double Func_Abs (double *oplist, unsigned int numops); +double Func_Rand (double *oplist, unsigned int numops); +double Func_Trunc (double *oplist, unsigned int numops); #endif // __ops_h diff --git a/libs/gib/exp.c b/libs/gib/exp.c index 419006268..42ba26c05 100644 --- a/libs/gib/exp.c +++ b/libs/gib/exp.c @@ -67,6 +67,8 @@ functable_t functable[] = { {"asin", Func_Asin, 1}, {"acos", Func_Acos, 1}, {"atan", Func_Atan, 1}, + {"rand", Func_Rand, 2}, + {"trunc", Func_Trunc, 1}, {"", 0, 0} }; diff --git a/libs/gib/gib_builtin.c b/libs/gib/gib_builtin.c index 5d7c8c9b6..29095fe57 100644 --- a/libs/gib/gib_builtin.c +++ b/libs/gib/gib_builtin.c @@ -910,17 +910,6 @@ GIB_Print_f (void) Sys_Printf ("%s", GIB_Argv (1)); } -static void -GIB_Random_f (void) -{ - dstring_t *ret; - - if (GIB_Argc () != 1) - GIB_USAGE (""); - else if ((ret = GIB_Return (0))) - dsprintf (ret, "%.10g", (double) rand () / (double) RAND_MAX); -} - void GIB_Builtin_Init (qboolean sandbox) { @@ -963,5 +952,4 @@ GIB_Builtin_Init (qboolean sandbox) GIB_Builtin_Add ("file::delete", GIB_File_Delete_f); GIB_Builtin_Add ("range", GIB_Range_f); GIB_Builtin_Add ("print", GIB_Print_f); - GIB_Builtin_Add ("random", GIB_Random_f); } diff --git a/libs/gib/ops.c b/libs/gib/ops.c index 33401054d..de3b1895d 100644 --- a/libs/gib/ops.c +++ b/libs/gib/ops.c @@ -19,7 +19,10 @@ */ +#define _ISOC99_SOURCE + #include +#include #include "ops.h" @@ -184,3 +187,15 @@ Func_Abs (double *oplist, unsigned int numops) { return fabs (oplist[0]); } + +double +Func_Rand (double *oplist, unsigned int numops) +{ + return rand () * (oplist[1] - oplist[0]) / (RAND_MAX + 1.0) + oplist[0]; +} + +double +Func_Trunc (double *oplist, unsigned int numops) +{ + return (double) ((long int) oplist[0]); +}