View Single Post
GLaDOS GLaDOS's Avatar

JCF Member

Joined: Aug 2010

Posts: 40

GLaDOS is doing well so far

Mar 8, 2013, 11:03 AM
GLaDOS is offline
Reply With Quote
Quote:
Originally Posted by Sir Ementaler View Post
Oh, I do realize it isn't in math, but C++, which I believe AS is based on, does return infinity on division by 0.
This is implementation-dependent. I get a floating point exception when trying to perform a division by zero, using GCC.

Quote:
Originally Posted by Sir Ementaler View Post
Personally, I'm using them for min(), max(), mean() and median(), each of which is meant to have 2 or more arguments, and declaring them as double min(double x1,double x2,double x3=INFINITY,double x4=INFINITY,...) or double mean(double x1,double x2,double x3=NaN,double x4=NaN,...) was the best idea I was able to come up with.
AS allows function overloading, meaning you can have multiple functions with the same name only separated by their parameter types or counts. For example, you can do something like this:
Code:
double minGeneric(array< double > numbers) // Weird spacing because JCF insists on parsing HTML even within code tags
[ algorithm goes here ]

double min(double x1, double x2)
{
    return minGeneric({x1, x2});
}
double min(double x1, double x2, double x3)
...
double min(double x1, double x2, double x3, double x4)
...
Not sure if the code is going to work exactly like that, it's been a while since I actually did something with AngelScript.