Skip to content

Math

Classes

vector

A class containing x, y and z coordinates, usually used to represent a 3d point in space.

  1. vector();

  2. vector(const vector& in vec);

  3. vector(float x, float y = 0.0, float z = 0.0);

Arguments (3):

Remarks:

An advantage with vectors is that they contain basic addition and scaling operators.

Example:

void main() {
	vector v1(5, 5, 5);
	vector v2(10, 10, 0);
	vector v3 = v1 + v2;
	alert("example", "the new vector is "+v3.x + ", " + v3.y + ", " + v3.z); // will show that the vector is 15, 15, 5.
}

Operators

opAssign

Overloads the = operator, allowing you to assign a vector to another, already existing one.

vector& opAssign(const vector &in other);

Arguments:

const vector& in other: the vector to assign to.

Example:
void main() {
	vector v1;
	vector v2(1.2, 2.3, 9.3);
	v1 = v2;
	alert("The first vector =", "(" + round(v1.x, 2) + ", " + round(v1.y, 2) + ", " + round(v1.z, 2) + ")");
}

Properties

x

Represents the x coordinate of the vector.

float vector::x;

Example:
void main() {
	vector v(2.9);
	alert("The x value of the vector is", round(v.x, 2));
}
y

Represents the y coordinate of the vector.

float vector::y;

Example:
void main() {
	vector v(2.9, 19.2);
	alert("The y value of the vector is", round(v.y, 2));
}
z

Represents the z coordinate of the vector.

float vector::z;

Example:
void main() {
	vector v(2.9, 19.2, 4.1);
	alert("The z value of the vector is", round(v.z, 2));
}

Functions

abs

Returns the absolute value of a value.

double abs(double x);

Arguments:

Returns:

The absolute value of the given value.

Example:

void main() {
	alert("Example", "The absolute value of -5 is " + abs(-5));
}

acos

Returns the arc cosine of a value in radians.

double acos(double x);

Arguments:

Returns:

The arc cosine of the given value.

Example:

void main() {
    alert("Example", "The arc cosine of 0.5 is " + acos(0.5) + " radians");
}

asin

Returns the arc sine of a value in radians.

double asin(double x);

Arguments:

Returns:

The arc sine of the given value.

Example:

void main() {
    alert("Example", "The arc sine of 0.5 is " + asin(0.5) + " radians");
}

atan

Returns the arc tangent of a value in radians.

double atan(double x);

Arguments:

Returns:

The arc tangent of the given value.

Example:

void main() {
    alert("Example", "The arc tangent of 1 is " + atan(1) + " radians");
}

atan2

Returns the arc tangent of y/x, where y and x are the coordinates of a point.

double atan2(double y, double x);

Arguments:

Returns:

The arc tangent of y/x.

Example:

void main() {
    alert("Example", "The arc tangent of (1, 2) is " + atan2(1, 2) + " radians");
}

ceil

Returns the smallest integer greater than or equal to a value.

double ceil(double x);

Arguments:

Returns:

The smallest integer greater than or equal to x.

Example:

void main() {
	alert("Example", "The ceiling of 3.14 is " + ceil(3.14));
}

cos

Returns the cosine of an angle given in radians.

double cos(double x);

Arguments:

Returns:

The cosine of the angle.

Example:

void main() {
	alert("Example", "The cosine of 45 is " + cos(45 * 3.14159 / 180) + " radians");
}

cosh

Returns the hyperbolic cosine of a value.

double cosh(double x);

Arguments:

Returns:

The hyperbolic cosine of the given value.

Example:

void main() {
    alert("Example", "The hyperbolic cosine of 2 is " + cosh(2));
}

floor

Returns the largest integer less than or equal to a value.

double floor(double x);

Arguments:

Returns:

The largest integer less than or equal to x.

Example:

void main() {
	alert("Example", "The floor of 3.14 is " + floor(3.14));
}

fraction

Returns the fractional part of a value.

double fraction(double x);

Arguments:

Returns:

The fractional part of the given value.

Example:

void main() {
	alert("Example", "The fractional part of 3.75 is " + fraction(3.75));
}

log

Returns the natural logarithm (base e) of a value.

double log(double x);

Arguments:

Returns:

The natural logarithm of the given value.

Example:

void main() {
    alert("Example", "The natural logarithm of 10 is " + log(10));
}

log10

Returns the base 10 logarithm of a value.

double log10(double x);

Arguments:

Returns:

The base 10 logarithm of the given value.

Example:

void main() {
    alert("Example", "The base 10 logarithm of 100 is " + log10(100));
}

pow

Returns x raised to the power of y.

double pow(double x, double y);

Arguments:

Returns:

x raised to the power of y.

Example:

void main() {
    alert("Example", "2 raised to the power of 3 is " + pow(2, 3));
}

round

Returns the value of a number rounded to the nearest integer.

double round(double n, int p);

Arguments:

Returns:

The value of the number rounded to the nearest integer.

Example:

void main() {
	alert("Example", "Rounding 3.14159 to 2 decimal places gives " + round(3.14159, 2));
}

sin

Returns the sine of an angle given in radians.

double sin(double x);

Arguments:

Returns:

The sine of the angle.

Example:

void main() {
	alert("Example", "The sine of 45 is " + sin(45 * 3.14159 / 180) + " radians");
}

sinh

Returns the hyperbolic sine of a value.

double sinh(double x);

Arguments:

Returns:

The hyperbolic sine of the given value.

Example:

void main() {
    alert("Example", "The hyperbolic sine of 2 is " + sinh(2));
}

sqrt

Returns the square root of a value.

double sqrt(double x);

Arguments:

Returns:

The square root of the given value.

Example:

void main() {
	alert("Example", "The square root of 16 is " + sqrt(16));
}

tan

Returns the tangent of an angle given in radians.

double tan(double x);

Arguments:

Returns:

The tangent of the angle.

Example:

void main() {
	alert("Example", "The tangent of 45 is " + tan(45 * 3.14159 / 180) + " radians");
}

tanh

Returns the hyperbolic tangent of a value.

double tanh(double x);

Arguments:

Returns:

The hyperbolic tangent of the given value.

Example:

void main() {
    alert("Example", "The hyperbolic tangent of 2 is " + tanh(2));
}

tinyexpr

Evaluate a mathematical expression using the tinyexpr library.

double tinyexpr(string expression);

Arguments:

Returns:

double: the result of the expression.

Example:

void main() {
	string expression = input_box("Expression", "Enter expression to evaluate");
	if (expression.is_empty()) exit();
	alert("Result", expression + "= " + tinyexpr(expression));
}