RetroX
|
|
Posted on: October 08, 2008, 05:57:05 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
Well, I've looked at a C++ tutorial, and decided to finish up the math functions. WARNING: I have not tested this, although I am pretty sure it will work. First, go to fnames.txt and add the following to the bottom of the file: int choose(int arg1, int arg2, ...) int mean(int arg1, int arg2, ...) int median(int arg1, int arg2, ...) Now, go to GMmathnc.h in ENIGMAsystem/SHELL/Universal_System and add this to the bottom of the file: // May not be necessary; just in case ENIGMA doesn't include them already #include <stdarg.h>
int choose(int num1, int num2, ...) { va_list choices; int i; int j=0; int array[]; va_start(choices,num1); for (i=arg1;i!=-1;i=va_arg(choices,int)) { array[j]=i; j+=1; } va_end(ap); return array[random(j)]; }
int mean(int num1, int num2, ...) { va_list choices; int i; int j=0; int total=0; va_start(choices,num1); for (i=arg1;i!=-1;i=va_arg(choices,int)) { total+=i; j+=1; } va_end(ap); return total/j; }
int median(int num1, int num2, ...) { va_list choices; int i; int j=0; int array[]; va_start(choices,num1); for (i=arg1;i!=-1;i=va_arg(choices,int)) { array[j]=i; j+=1; } va_end(ap); return array[(int)((j-1)/2)]; } PLEASE NOTE: - The above functions only work with integers (no decimals/fractions). - While they may not work in the setup I have provided, I am very positive that the scripts will work, and Josh may feel free to implement these into R4.
|
|
« Last Edit: October 08, 2008, 05:58:38 pm by RetroX »
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars?
|
|
|
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #6 Posted on: October 17, 2008, 06:43:30 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
I didn't look far into stdarg, but my main concerns were that it doesn't give a method of determining the number of arguments in the list.
I corrected that by parsing in the number of arguments as the first argument in the function. I just never got around to the coded part of that.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #11 Posted on: November 29, 2008, 11:37:33 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
GM "compiles" things into a token tree. At load time. Instead of beforehand. Or it'd be just slightly more secure.
Either way, stdargs can't take custom classes anyway, iirc. So even under ideal conditions, if I could determine arg count, this wouldn't work. =\
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
|
|