Common mathematical functions.
MathFunc.h | Common mathematical functions. |
#define DOT2 | Computes the dot product of two 2D vectors, the elements are accessed using array notation. |
#define DOT3 | Computes the dot product of two 3D vectors, the elements are accessed using array notation. |
#define ABSDOT3 | Computes the dot product of two 3D vectors, but takes the absolute value of each element before summation. |
#define DOT3_xyz | Computes the dot product of a float3 and another vector given by three floats. |
#define DOT3STRIDED | Computes the dot product of two 3D vectors, but with the elements of the second vector being scattered noncontiguous in memory. |
#define DOT4 | Computes the dot product of two 4D vectors, the elements are accessed using array notation. |
#define DOT4STRIDED | Computes the dot product of two 4D vectors, but with the elements of the second vector being scattered noncontiguous in memory. |
#define DOT4POS | Computes the dot product of a 4D vector and a 3D position vector (w == 1). |
#define DOT4POS_xyz | Computes the dot product of a 4D vector and a position vector (x,y,z,1). |
#define DOT4DIR | Computes the dot product of a 4D vector and a direction vector (x,y,z,0). |
#define DOT4DIR_xyz | Computes the dot product of a 4D vector and a direction vector (x,y,z,0). |
#define MATH_SKIP_WORD | |
#define MATH_NEXT_WORD_IS | |
DegToRad(degrees) (+1 overload) | Converts the given amount of degrees into radians. |
RadToDeg(radians) (+1 overload) | Converts the given amount of radians into degrees. |
Sin(angleRadians) | Computes the function sin(x). |
Cos(angleRadians) | Computes the function cos(x). |
Tan(angleRadians) | Computes the function tan(x). |
SinCos(...) | Simultaneously computes both sin(x) and cos(x), which yields a small performance increase over to computing them separately. |
SinCos2(...) | Computes sin and cos of the .x and .y components of angleRadians, stored to the corresponding components of outSin and outCos. |
SinCos3(...) | Computes sin and cos of the .x, .y and .z components of angleRadians, stored to the corresponding components of outSin and outCos. |
SinCos4(...) | Computes sin and cos of the four components of angleRadians, stored to the corresponding components of outSin and outCos. |
Asin(x) | Computes the function arcsin(x), in radians. |
Acos(x) | Computes the function arccos(x), in radians. |
Atan(x) | Computes the function arctan(x), in radians. |
Atan2(y,x) | Computes the signed (principal value) arc-tangent of y/x, in radians. |
Sinh(x) | Computes the hyperbolic sine of x. |
Cosh(x) | Computes the hyperbolic cosine of x. |
Tanh(x) | Computes the hyperbolic tangent of x. |
IsPow2(number) (+3 overloads) | Returns true if the given number is a power of 2. |
RoundUpPow2(number) (+3 overloads) | Returns the smallest power-of-2 number (1,2,4,8,16,32,...) greater or equal than the given number. |
RoundDownPow2(number) (+3 overloads) | Returns the largest power-of-2 number (1,2,4,8,16,32,...) smaller or equal than the given number. |
RoundIntUpToMultipleOfPow2(x,n) (+1 overload) | Returns the given number rounded up to the next multiple of n. |
PowInt(base,exponent) | Raises the given base to an integral exponent. |
Pow(base,exponent) | Raises the given base to a float exponent. |
Exp(exponent) | Returns e (the constant 2.71828...) raised to the given power. |
Log(base,value) | Computes a logarithm of the given value in the specified base. |
Log2(value) | Computes a logarithm in base-2. |
Ln(value) | Computes a logarithm in the natural base (using e=2.71828... as the base) |
Log10(value) | Computes a logarithm in base-10. |
Ceil(f) | Returns f rounded up to the next integer, as float. |
CeilInt(f) | Returns f rounded up to the next integer, as integer. |
Floor(f) | Returns f rounded down to the previous integer, as float. |
FloorInt(f) | Returns f rounded down to the previous integer, as integer. |
Round(f) | Returns f rounded to the nearest integer, as float. |
RoundInt(f) | Returns f rounded to the nearest integer, as integer. |
Sign(f) | Returns -1 or 1 depending on the sign of f. |
SignOrZero(f,epsilon) | Returns 0 if f is zero up to the given epsilon. Otherwise returns -1 or 1 depending on the sign of f. |
Lerp(a,b,t) | Linearly interpolates between a and b. |
LerpMod(a,b,mod,t) | Linearly interpolates from a to b, under the modulus mod. |
InvLerp(a,b,x) | Computes the lerp factor a and b have to be Lerp()ed to get x. |
Step(y,x) | See http://msdn.microsoft.com/en-us/library/bb509665(v=VS.85).aspx. |
SmoothStep(min,max,x) | See http://msdn.microsoft.com/en-us/library/bb509658(v=vs.85).aspx. |
PingPongMod(x,mod) | Limits x to the range [0, mod], but instead of wrapping around from mod to 0, the result will move back from mod to 0 as x goes from mod to 2*mod. |
Mod(x,mod) (+1 overload) | Computes a floating-point modulus. |
ModPos(x,mod) (+1 overload) | Computes a floating-point modulus, but restricts the output to the range [0, mod[. |
Frac(x) | Returns the fractional part of x. |
Sqrt(x) | Returns the square root of x. |
SqrtFast(x) | Computes a fast approximation of the square root of x. |
RSqrt(x) | Returns 1/Sqrt(x). (The reciprocal of the square root of x) |
RSqrtFast(x) | SSE implementation of reciprocal square root. |
Recip(x) | Returns 1/x, the reciprocal of x. |
RecipFast(x) | Returns 1/x, the reciprocal of x, using a fast approximation (SSE rcp instruction). |
Factorial(n) | Calculates n! at runtime. Use class FactorialT<N> to evaluate factorials at compile-time. |
CombinatorialRec(n,k) | Calculates (N nCr K) at runtime with recursion, running time is exponential to n. |
CombinatorialTab(n,k) | Calculates (N nCr K) at runtime, running time is proportional to n*k. |
Clamp(val,floor,ceil) | Clamps the given input value to the range [min, max]. |
Clamp01(val) | Clamps the given input value to the range [0, 1]. |
Min(a,b) | Computes the smaller of two values. |
Max(a,b) (+1 overload) | Computes the larger of two values. |
Min(a,b,c) (+1 overload) | Computes the smallest of three values. |
Max(a,b,c) | Computes the largest of three values. |
Min(a,b,c,d) | Computes the smallest of four values. |
Max(a,b,c,d) | Computes the largest of four values. |
Swap(a,b) | Swaps the two values. |
GreaterThan(a,b) | Returns true if a > b. |
LessThan(a,b) | Returns true if a < b. |
Abs(a) (+1 overload) | Returns the absolute value of a. |
Equal(a,b) (+3 overloads) | Returns true if a and b are equal, using operator ==(). |
EqualAbs(a,b,epsilon) | Compares the two values for equality, allowing the given amount of absolute error. |
RelativeError(a,b) | Computes the relative error of the two variables. |
EqualRel(a,b,maxRelError) | Compares the two values for equality, allowing the given amount of relative error. |
EqualUlps(a,b,maxUlps) | Compares two floats interpreted as integers, see http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm Warning: This comparison is not safe with NANs or INFs. |
IsFinite() | Returns true if the given value is not an inf or a nan. |
IsFinite< float >(f) | |
IsFinite< double >(d) | |
IsNan(f) (+1 overload) | Returns true if the given value is a not-a-number. |
IsInf(f) (+1 overload) | Returns true if the given value is +inf or -inf. |
IsFinite< long double >(value) | |
IsInf(value) | |
IsNan(value) | |
SerializeFloat(f,dstStr) | Serializes a float to a string. |
DeserializeFloat(str,outEndStr) | Deserializes a float from the given string. |
DeserializeDouble(str,outEndStr) | Deserializes a double from the given string. |