Removed the 'random' GIB builtin and replaced it with the rand() math

function in the math evaluator.  Added the trunc() math function as well.
This commit is contained in:
Brian Koropoff 2003-02-23 22:14:07 +00:00
parent 36774a612d
commit 6141bc35d0
4 changed files with 19 additions and 12 deletions

View file

@ -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

View file

@ -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}
};

View file

@ -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);
}

View file

@ -19,7 +19,10 @@
*/
#define _ISOC99_SOURCE
#include <math.h>
#include <stdlib.h>
#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]);
}