This is an old revision of the document!
fixed MATH_E
– the number E.fixed PI
– the number π (pi).fixed SQRT_2
– square root of 2fixed LOG2_E
– value of log2(e).fixed LOG2_10
– value of log2(10);
num abs(num x)
Returns the absolute value of x.
Example
abs(2.0) == 2.0; abs(-123) == 123;
num clamp(num x, num a, num b)
Limits x to the range [a; b]. If x falls in the range, returns x. If x is less than a, returns a. If x is greater than b, returns b.
Example
clamp(7, 6, 8) == 7; clamp(0.1, 0.2, 0.3) == 0.2;
int cmp(num a, num b)
Compares two numbers and returns the result:
1
– a is greater than b-1
– a is less than b0
– a and b are equal
any cond(bool condition, any a, any b)
Returns a if the condition is true, b otherwise.
It's a simulation of the ternary operator ?: in ACS.
int y = cond(x, DoSomething(), DoSomethingElse())
as both DoSomething()
and DoSomethingElse()
will be called.
num max(num a, num b)
Returns the greater of two numbers.
Example
max(3, 5) == 5; max(8.0, 7.5) == 8.0;
num min(num a, num b)
Returns the lesser of two numbers.
Example
min(3, 5) == 3; min(8.0, 7.5) == 7.5;
int sgn(num x)
Returns the sign of x.
1
– x is positive-1
– x is negative0
– x is zeroExample
sgn(12.3) == 1; sgn(0) == 0; sgn(-7) == -1;
any, any swap(any a, any b)
Swaps two variables. Is a function to improve readability.
swap(x, y); x = r1; y = r2;
instead of
tmp = x; x = y; y = tmp;
There are four rounding modes:
Rounding table:
x round(x) floor(x) ceil(x) trunc(x) ----- -------- -------- -------- -------- 2.3 2 2 3 2 3.8 4 3 4 3 5.5 6 5 6 5 -2.3 -2 -3 -2 -2 -3.8 -4 -4 -3 -3 -5.5 -5 -6 -5 -5
Every rounding mode is available as two functions. The ones with the “i” in the name return an integer, while the ones without the “i” return a fixed.
fixed ceil(fixed x)
int iceil(fixed x)
Returns x rounded up.
fixed floor(fixed x)
int ifloor(fixed x)
Returns x rounded down.
fixed round(fixed x)
int iround(fixed x)
Returns x rounded to the closest integer.
fixed trunc(fixed x)
int itrunc(fixed x)
Returns x with fractional part removed.
fixed IntDiv(int a, int b)
Divides two integers and returns a fixed-point result. Allows division of any 2 integers whose ratio is not higher than 32767.
fixed lerp(fixed a, fixed b, fixed alpha)
Performs linear interpolation (or extrapolation) between two numbers and returns the result.
Examples
lerp(a, b, 0.0) == a; lerp(a, b, 1.0) == b; lerp(a, b, 0.5) == (a + b) / 2; // Average of a and b.
// Simple animation. for (int time = 0; time < 1.0; time += 0.05) { int x = lerp(x1, x2, time); int y = lerp(y1, y2, time); DrawSomething(x, y); Delay(1); }
num gcf(num a, num b)
Returns the greatest common factor of two numbers. The returned factor will be negative if one or both numbers are negative.
Example
gcf(18, 24) == 6; gcf(18.0, 24.0) == 6.0; gcf(-18, -24) == -6;
num mod(num a, num b)
Returns a % b
, but the result is always positive. Only positive b values are supported.
Example
mod(2, 5) == 3; mod(-3, 5) == 3;
num npo2(num x)
Rounds the number up to the Next Power Of 2. The input must be positive.
Example
npo2(17) == 32; npo2(6.5) == 8.0;
int zan_Sqrt(int number)
fixed zan_FixedSqrt(fixed number)
Zandronum implementations of corresponding ZDoom 2.7.0-only functions.
All logarithm functions come in two versions: fixed-point and integer.
All logarithm functions return fixed-point values.
i
.
fixed ln(fixed x)
fixed iln(int x)
Returns the natual logaritm (base e) of the given number.
ln
instead of log
like in C because ZDoom already has a function called Log
that is used for logging.
fixed log2(fixed x)
fixed ilog2(int x)
Returns the logarithm in base 2 of the given number.
fixed log10(fixed x)
fixed ilog10(int x)
Returns the logarithm in base 10 of the given number.
fixed logb(fixed x, fixed base)
fixed ilogb(int x, fixed base)
Returns the logarithm in an arbitrary fixed-point base. Base must be a fixed number greater than 1.0.
Sin and cos are already in ZDoom.
fixed tan(angle x)
Returns the tangent of x.
fixed cot(angle x)
Returns the cotangent of x.
fixed sec(angle x)
Returns the secant of x.
fixed cosec(angle x)
Returns the cosecant of x.
angle asin(fixed x)
Returns the arcsine of x.
angle acos(fixed x)
Returns the arccosine of x.
angle atan(fixed x)
Returns the arctangent of x.
angle acot(fixed x)
Returns the arccotangent of x.
angle asec(fixed x)
Returns the arcsecant of x.
angle acosec(fixed x)
Returns the arccosecant of x.
fixed dot2(fixed x1, fixed y1, fixed x2, fixed y2)
Returns the dot product of two 2D vectors.
fixed dot3(fixed x1, fixed y1, fixed z1, fixed x2, fixed y2, fixed z2)
Returns the dot product of two 3D vectors.
fixed length2d(fixed x, fixed y)
Returns the length of the given 2D vector. This is a Zandronum replacement for VectorLength.
fixed length2d2(int x, int y)
Returns the squared length of the given 2D vector.
fixed length3d(fixed x, fixed y, fixed z)
Returns the length of the given 3D vector.
fixed length3d2(int x, int y, int z)
Returns the squared length of the given 3D vector.
fixed, fixed normalize2d(fixed x, fixed y)
Normalizes the given 2D vector and returns the result.
fixed, fixed, fixed normalize3d(fixed x, fixed y, fixed z)
Normalizes the given 3D vector and returns the result.
fixed, fixed RotatePoint(fixed x, fixed y, fixed originX, fixed originY, angle angle)
Rotates the given point (x; y) around the given origin by the given angle and returns the resulting coordinates of the point.
fixed, fixed RotateVector(fixed x, fixed y, angle angle)
Rotates the vector by the given angle and returns its new coordinates.
This function returns multiple values.
Example
RotateVector(x, y, angle); int newX = r1; int newY = r2;
angle, angle VectorToAngles(fixed x, fixed y, fixed z)
Converts a vector to a pair of angles (yaw and pitch) that point to the same direction.
This function returns multiple values.
Example
// Make the player look along the vector VectorToAngles(1.0, 2.0, 3.0); int angle = r1; int pitch = r2; SetActorAngle(tid, angle); SetActorPitch(tid, -pitch); // Note that actor pitch is inverted in ZDoom.
LookAtPoint
instead of the example code above.