comparison src/paranormal/libcalc/function.c @ 1175:7ae024f5d91b trunk

[svn] - libcalc (paranormal virtual evaluation machine): add rand() instruction, global registers (global_reg0-reg99).
author nenolod
date Fri, 08 Jun 2007 10:56:12 -0700
parents a9f1bd76a3e6
children 44d28af95a23
comparison
equal deleted inserted replaced
1174:8aab955fb114 1175:7ae024f5d91b
71 int y = (int)pop (stack); 71 int y = (int)pop (stack);
72 int x = (int)pop (stack); 72 int x = (int)pop (stack);
73 return (y == 0) ? 0 : (x / y); 73 return (y == 0) ? 0 : (x / y);
74 } 74 }
75 75
76 static double f_rand (ex_stack *stack) {
77 return rand() % pop (stack);
78 }
79
76 /* */ 80 /* */
77 81
78 static const func_t init[] = { 82 static const func_t init[] = {
79 { "sin", f_sin }, 83 { "sin", f_sin },
80 { "cos", f_cos }, 84 { "cos", f_cos },
83 { "acos", f_acos }, 87 { "acos", f_acos },
84 { "atan", f_atan }, 88 { "atan", f_atan },
85 { "log", f_log }, 89 { "log", f_log },
86 { "if", f_if }, 90 { "if", f_if },
87 { "div", f_div } 91 { "div", f_div }
92 { "rand", f_rand }
88 }; 93 };
89 94
90 int function_lookup (const char *name) { 95 int function_lookup (const char *name) {
91 int i; 96 int i;
92 97