Math Commands

Math Commands

Standard mathematical functions.

abs

Syntax:

double abs(num); 
int|double  num;

Returns the absolute (positively-signed) value of num.

cos

Syntax:

double cos(angle); 
double  angle;

Returns the cosine of angle (which should be given in degrees).

dotproduct

Syntax:

double dotproduct(u,  
 v); 
vector  u;
vector  v;

Calculate and return the dot product of the two vectors u and v.

exp

Syntax:

double exp(x); 
double  x;

Returns the exponential of x.

ln

Syntax:

double ln(x); 
double  x;

Returns the natural base-e logarithm of x.

log

Syntax:

double log(x); 
double  x;

Returns the base-10 logarithm of x.

nint

Syntax:

int nint(x); 
double  x;

Returns the nearest integer value to x.

normalise

Syntax:

double normalise(v); 
vector  v;

Normalises the vector v, returning the magnitude of the vector before the normalisation was performed.

For example:

vector v = { 1, 2, 3 };
double mag = normalise(v);
printf("Normalised vector is { %f, %f, %f }, old magnitude was %f\n", v.x, v.y, v.z, mag);

prints the following:

Normalised vector is { 0.267261, 0.534522, 0.801784 }, old magnitude was 3.741657

sin

Syntax:

double sin(angle); 
double  angle;

Returns the sine of angle (which should be given in degrees).

sqrt

Syntax:

double sqrt(x); 
double  x;

Returns the square root of x.

tan

Syntax:

double tan(angle); 
double  angle;

Returns the tangent of angle (which should be given in degrees).