Pages: [1] 2
  Print  
Author Topic: choose(), mean(), median()  (Read 5690 times)
Offline (Male) RetroX
Posted on: October 08, 2008, 05:57:05 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Male) Rusky
Reply #1 Posted on: October 09, 2008, 04:47:54 PM

Resident Troll
Joined: Feb 2008
Posts: 960
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
they'd work with fractions if you used double:

double mean(double num1, double num2, ...)
{
    va_list choices;
    va_start(choices, num1);
    double total;
    double count;
   
    for (double i = arg1; i != -1; i = va_arg(choices, double))
    {
        total += i;
        count += 1;
    }
   
    va_end(choices);
    return total / j;
}
Logged
Offline (Male) RetroX
Reply #2 Posted on: October 09, 2008, 07:33:51 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Yeah, but they don't work with all types.  Although if you include the script with the var structure in it before the scripts, you could use var and do it for all types.
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Unknown gender) death-droid
Reply #3 Posted on: October 14, 2008, 04:50:20 AM
Member
Joined: Aug 2008
Posts: 19

View Profile
The functions dont actually compile under enigma
Logged
Offline (Male) Rusky
Reply #4 Posted on: October 14, 2008, 06:12:26 PM

Resident Troll
Joined: Feb 2008
Posts: 960
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
do you ever take the mean or median of anything but numbers? and with choose, do you do it with anything but numbers or objects, which are represented by numbers? why would you want to use var? you don't take the mean of strings. that just doesn't make sense. and if double works, why limit yourself to int just because you didn't use var?
seriously, what goes on in that head of yours? O_o

and they should compile if you set it up right.
Logged
Offline (Unknown gender) OniLink10
Reply #5 Posted on: October 15, 2008, 07:00:19 PM
Member
Joined: Jul 2008
Posts: 68

View Profile Email
The functions dont actually compile under enigma
R u saying that Enigma is Interpreted? Cause it's not.
Logged
Offline (Male) Josh @ Dreamland
Reply #6 Posted on: October 17, 2008, 06:43:30 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
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
Offline (Male) RetroX
Reply #7 Posted on: October 17, 2008, 09:49:04 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
You could just do what Game Maker does, and include 64 arguments and just not require all of them somehow.
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Unknown gender) score_under
Reply #8 Posted on: October 26, 2008, 03:39:12 PM

Member
Joined: Aug 2008
Posts: 308

View Profile
You could just do what Game Maker does, and include 64 arguments and just not require all of them somehow.
As far as I know, it in fact passes a structure of 6 dwords (3 doubles?), 0xF (never seems to change for me), and another 6-dword structure to every function. This way it can use one of the dwords as an argument count, and the others as arguments.
Logged
Offline (Male) RetroX
Reply #9 Posted on: November 17, 2008, 07:23:47 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Or, it just doesn't use any special code at all and checks for the number of commas used. =P
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Unknown gender) score_under
Reply #10 Posted on: November 19, 2008, 06:01:19 PM

Member
Joined: Aug 2008
Posts: 308

View Profile
Wrong.

I've actually placed a breakpoint on these functions to try this out, so I should know. And Game Maker compiles the functions into some sort of bytecode, like Java does.
Logged
Offline (Male) Josh @ Dreamland
Reply #11 Posted on: November 29, 2008, 11:37:33 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
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
Offline (Unknown gender) score_under
Reply #12 Posted on: November 30, 2008, 11:18:53 AM

Member
Joined: Aug 2008
Posts: 308

View Profile
GM "compiles" things into a token tree. At load time. Instead of beforehand. Or it'd be just slightly more secure.
And this, my friends, is a huge spoiler on how to hack every game maker game in existence without using That One Program.
Logged
Offline (Male) Rusky
Reply #13 Posted on: December 01, 2008, 05:23:37 PM

Resident Troll
Joined: Feb 2008
Posts: 960
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
You didn't know that?
Logged
Offline (Unknown gender) score_under
Reply #14 Posted on: December 03, 2008, 02:09:31 PM

Member
Joined: Aug 2008
Posts: 308

View Profile
I knew it, but most didn't.
Logged
Pages: [1] 2
  Print