Unit Neslib.FastMath

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Fast Math Library for Delphi.

You can set these conditional defines to modify the behavior of this library:

  • FM_COLUMN_MAJOR: Store matrices in column-major order. Be default, matrices are store in row-major order for compatibility with the Delphi RTL. However, for OpenGL applications, it makes more sense to store matrices in column- major order. Another side effect of this define is that the depth of camera matrices are clipped to -1..1 (common with OpenGL) instead of 0..1 (uses by the Delphi RTL).

  • FM_NOSIMD: Disable SIMD (SSE2, NEON, ARM64) optimizations and run all calculations using Pascal code only. You will generally only enable this define for (performance) testing, or when running on an old PC that does not have support for SSE2.

Overview

Classes, Interfaces, Objects and Records

Name Description
record TVector2 A 2-dimensional vector.
record TVector3 A 3-dimensional vector.
record TVector4 A 4-dimensional vector.
record TMatrix2 A 2x2 matrix in row-major order (M[Row, Column]).
record TMatrix3 A 3x3 matrix in row-major order (M[Row, Column]).
record TMatrix4 A 4x4 matrix in row-major order (M[Row, Column]).
record _TMatrix2Helper Adds common constants of type TMatrix2
record _TMatrix3Helper Adds common constants of type TMatrix3
record _TMatrix4Helper Adds common constants of type TMatrix4
record TQuaternion A quaternion.
record _TQuaternionHelper Adds common constants and functionality to TQuaternion
record TIVector2 A 2-dimensional vector that uses integer components instead of floating-point components.
record _TVector2Helper Adds common constants of type TVector2
record TIVector3 A 3-dimensional vector that uses integer components instead of floating-point components.
record _TVector3Helper Adds common constants of type TVector3
record TIVector4 A 4-dimensional vector that uses integer components instead of floating-point components.
record _TVector4Helper Adds common constants of type TVector4

Functions and Procedures

function Vector2: TVector2; overload; inline;
function Vector2(const A: Single): TVector2; overload; inline;
function Vector2(const A1, A2: Single): TVector2; overload; inline;
function Vector2(const AVector: TVector3): TVector2; overload; inline;
function Vector2(const AVector: TVector4): TVector2; overload; inline;
function Vector3: TVector3; overload;
function Vector3(const A: Single): TVector3; overload;
function Vector3(const A1, A2, A3: Single): TVector3; overload;
function Vector3(const A1: TVector2; const A2: Single): TVector3; overload;
function Vector3(const A1: Single; const A2: TVector2): TVector3; overload;
function Vector3(const AVector: TVector4): TVector3; overload;
function Vector4: TVector4; overload;
function Vector4(const A: Single): TVector4; overload;
function Vector4(const A1, A2, A3, A4: Single): TVector4; overload;
function Vector4(const A1: TVector2; const A2, A3: Single): TVector4; overload;
function Vector4(const A1: Single; const A2: TVector2; const A3: Single): TVector4; overload;
function Vector4(const A1, A2: Single; const A3: TVector2): TVector4; overload;
function Vector4(const A1, A2: TVector2): TVector4; overload;
function Vector4(const A1: TVector3; const A2: Single): TVector4; overload;
function Vector4(const A1: Single; const A2: TVector3): TVector4; overload;
function Quaternion: TQuaternion; overload;
function Quaternion(const AX, AY, AZ, AW: Single): TQuaternion; overload;
function Quaternion(const AAxis: TVector3; const AAngleRadians: Single): TQuaternion; overload;
function Matrix2: TMatrix2; overload;
function Matrix2(const ADiagonal: Single): TMatrix2; overload;
function Matrix2(const ARow0, ARow1: TVector2): TMatrix2; overload;
function Matrix2(const A11, A12, A21, A22: Single): TMatrix2; overload;
function Matrix2(const AMatrix: TMatrix3): TMatrix2; overload;
function Matrix2(const AMatrix: TMatrix4): TMatrix2; overload;
function Matrix3: TMatrix3; overload;
function Matrix3(const ADiagonal: Single): TMatrix3; overload;
function Matrix3(const ARow0, ARow1, ARow2: TVector3): TMatrix3; overload;
function Matrix3(const A11, A12, A13, A21, A22, A23, A31, A32, A33: Single): TMatrix3; overload;
function Matrix3(const AMatrix: TMatrix2): TMatrix3; overload;
function Matrix3(const AMatrix: TMatrix4): TMatrix3; overload;
function Matrix4: TMatrix4; overload;
function Matrix4(const ADiagonal: Single): TMatrix4; overload;
function Matrix4(const ARow0, ARow1, ARow2, ARow3: TVector4): TMatrix4; overload;
function Matrix4(const A11, A12, A13, A14, A21, A22, A23, A24, A31, A32, A33, A34, A41, A42, A43, A44: Single): TMatrix4; overload;
function Matrix4(const AMatrix: TMatrix2): TMatrix4; overload;
function Matrix4(const AMatrix: TMatrix3): TMatrix4; overload;
function IVector2: TIVector2; overload; inline;
function IVector2(const A: Integer): TIVector2; overload; inline;
function IVector2(const A1, A2: Integer): TIVector2; overload; inline;
function IVector3: TIVector3; overload;
function IVector3(const A: Integer): TIVector3; overload;
function IVector3(const A1, A2, A3: Integer): TIVector3; overload;
function IVector4: TIVector4; overload;
function IVector4(const A: Integer): TIVector4; overload;
function IVector4(const A1, A2, A3, A4: Integer): TIVector4; overload;
function Radians(const ADegrees: Single): Single; overload; inline;
function Radians(const ADegrees: TVector2): TVector2; overload;
function Radians(const ADegrees: TVector3): TVector3; overload;
function Radians(const ADegrees: TVector4): TVector4; overload;
function Degrees(const ARadians: Single): Single; overload; inline;
function Degrees(const ARadians: TVector2): TVector2; overload;
function Degrees(const ARadians: TVector3): TVector3; overload;
function Degrees(const ARadians: TVector4): TVector4; overload;
function Sin(const ARadians: Single): Single; overload; inline;
function Sin(const ARadians: TVector2): TVector2; overload; inline;
function Sin(const ARadians: TVector3): TVector3; overload; inline;
function Sin(const ARadians: TVector4): TVector4; overload; inline;
function Cos(const ARadians: Single): Single; overload; inline;
function Cos(const ARadians: TVector2): TVector2; overload; inline;
function Cos(const ARadians: TVector3): TVector3; overload; inline;
function Cos(const ARadians: TVector4): TVector4; overload; inline;
procedure SinCos(const ARadians: Single; out ASin, ACos: Single); overload;
procedure SinCos(const ARadians: TVector2; out ASin, ACos: TVector2); overload;
procedure SinCos(const ARadians: TVector3; out ASin, ACos: TVector3); overload;
procedure SinCos(const ARadians: TVector4; out ASin, ACos: TVector4); overload;
function Tan(const ARadians: Single): Single; overload; inline;
function Tan(const ARadians: TVector2): TVector2; overload; inline;
function Tan(const ARadians: TVector3): TVector3; overload; inline;
function Tan(const ARadians: TVector4): TVector4; overload; inline;
function ArcSin(const A: Single): Single; overload; inline;
function ArcSin(const A: TVector2): TVector2; overload; inline;
function ArcSin(const A: TVector3): TVector3; overload; inline;
function ArcSin(const A: TVector4): TVector4; overload; inline;
function ArcCos(const A: Single): Single; overload; inline;
function ArcCos(const A: TVector2): TVector2; overload; inline;
function ArcCos(const A: TVector3): TVector3; overload; inline;
function ArcCos(const A: TVector4): TVector4; overload; inline;
function ArcTan(const A: Single): Single; overload; inline;
function ArcTan(const A: TVector2): TVector2; overload; inline;
function ArcTan(const A: TVector3): TVector3; overload; inline;
function ArcTan(const A: TVector4): TVector4; overload; inline;
function ArcTan2(const Y, X: Single): Single; overload; inline;
function ArcTan2(const Y, X: TVector2): TVector2; overload; inline;
function ArcTan2(const Y, X: TVector3): TVector3; overload; inline;
function ArcTan2(const Y, X: TVector4): TVector4; overload; inline;
function Sinh(const A: Single): Single; overload; inline;
function Sinh(const A: TVector2): TVector2; overload; inline;
function Sinh(const A: TVector3): TVector3; overload; inline;
function Sinh(const A: TVector4): TVector4; overload; inline;
function Cosh(const A: Single): Single; overload; inline;
function Cosh(const A: TVector2): TVector2; overload; inline;
function Cosh(const A: TVector3): TVector3; overload; inline;
function Cosh(const A: TVector4): TVector4; overload; inline;
function Tanh(const A: Single): Single; overload; inline;
function Tanh(const A: TVector2): TVector2; overload; inline;
function Tanh(const A: TVector3): TVector3; overload; inline;
function Tanh(const A: TVector4): TVector4; overload; inline;
function ArcSinh(const A: Single): Single; overload; inline;
function ArcSinh(const A: TVector2): TVector2; overload; inline;
function ArcSinh(const A: TVector3): TVector3; overload; inline;
function ArcSinh(const A: TVector4): TVector4; overload; inline;
function ArcCosh(const A: Single): Single; overload; inline;
function ArcCosh(const A: TVector2): TVector2; overload; inline;
function ArcCosh(const A: TVector3): TVector3; overload; inline;
function ArcCosh(const A: TVector4): TVector4; overload; inline;
function ArcTanh(const A: Single): Single; overload; inline;
function ArcTanh(const A: TVector2): TVector2; overload; inline;
function ArcTanh(const A: TVector3): TVector3; overload; inline;
function ArcTanh(const A: TVector4): TVector4; overload; inline;
function Power(const ABase, AExponent: Single): Single; overload; inline;
function Power(const ABase, AExponent: TVector2): TVector2; overload; inline;
function Power(const ABase, AExponent: TVector3): TVector3; overload;
function Power(const ABase, AExponent: TVector4): TVector4; overload;
function Exp(const A: Single): Single; overload; inline;
function Exp(const A: TVector2): TVector2; overload; inline;
function Exp(const A: TVector3): TVector3; overload;
function Exp(const A: TVector4): TVector4; overload;
function Ln(const A: Single): Single; overload; inline;
function Ln(const A: TVector2): TVector2; overload; inline;
function Ln(const A: TVector3): TVector3; overload;
function Ln(const A: TVector4): TVector4; overload;
function Exp2(const A: Single): Single; overload; inline;
function Exp2(const A: TVector2): TVector2; overload; inline;
function Exp2(const A: TVector3): TVector3; overload;
function Exp2(const A: TVector4): TVector4; overload;
function Log2(const A: Single): Single; overload; inline;
function Log2(const A: TVector2): TVector2; overload; inline;
function Log2(const A: TVector3): TVector3; overload;
function Log2(const A: TVector4): TVector4; overload;
function Sqrt(const A: Single): Single; overload;
function Sqrt(const A: TVector2): TVector2; overload;
function Sqrt(const A: TVector3): TVector3; overload;
function Sqrt(const A: TVector4): TVector4; overload;
function InverseSqrt(const A: Single): Single; overload;
function InverseSqrt(const A: TVector2): TVector2; overload;
function InverseSqrt(const A: TVector3): TVector3; overload;
function InverseSqrt(const A: TVector4): TVector4; overload;
function FastSin(const ARadians: Single): Single; overload;
function FastSin(const ARadians: TVector2): TVector2; overload;
function FastSin(const ARadians: TVector3): TVector3; overload;
function FastSin(const ARadians: TVector4): TVector4; overload;
function FastCos(const ARadians: Single): Single; overload;
function FastCos(const ARadians: TVector2): TVector2; overload;
function FastCos(const ARadians: TVector3): TVector3; overload;
function FastCos(const ARadians: TVector4): TVector4; overload;
procedure FastSinCos(const ARadians: Single; out ASin, ACos: Single); overload;
procedure FastSinCos(const ARadians: TVector2; out ASin, ACos: TVector2); overload;
procedure FastSinCos(const ARadians: TVector3; out ASin, ACos: TVector3); overload;
procedure FastSinCos(const ARadians: TVector4; out ASin, ACos: TVector4); overload;
function FastTan(const ARadians: Single): Single; overload;
function FastTan(const ARadians: TVector2): TVector2; overload;
function FastTan(const ARadians: TVector3): TVector3; overload;
function FastTan(const ARadians: TVector4): TVector4; overload;
function FastArcTan2(const Y, X: Single): Single; overload;
function FastArcTan2(const Y, X: TVector2): TVector2; overload;
function FastArcTan2(const Y, X: TVector3): TVector3; overload;
function FastArcTan2(const Y, X: TVector4): TVector4; overload;
function FastPower(const ABase, AExponent: Single): Single; overload; inline;
function FastPower(const ABase, AExponent: TVector2): TVector2; overload; inline;
function FastPower(const ABase, AExponent: TVector3): TVector3; overload;
function FastPower(const ABase, AExponent: TVector4): TVector4; overload;
function FastExp(const A: Single): Single; overload;
function FastExp(const A: TVector2): TVector2; overload;
function FastExp(const A: TVector3): TVector3; overload;
function FastExp(const A: TVector4): TVector4; overload;
function FastLn(const A: Single): Single; overload;
function FastLn(const A: TVector2): TVector2; overload;
function FastLn(const A: TVector3): TVector3; overload;
function FastLn(const A: TVector4): TVector4; overload;
function FastLog2(const A: Single): Single; overload;
function FastLog2(const A: TVector2): TVector2; overload;
function FastLog2(const A: TVector3): TVector3; overload;
function FastLog2(const A: TVector4): TVector4; overload;
function FastExp2(const A: Single): Single; overload;
function FastExp2(const A: TVector2): TVector2; overload;
function FastExp2(const A: TVector3): TVector3; overload;
function FastExp2(const A: TVector4): TVector4; overload;
function Abs(const A: Single): Single; overload; inline;
function Abs(const A: TVector2): TVector2; overload; inline;
function Abs(const A: TVector3): TVector3; overload;
function Abs(const A: TVector4): TVector4; overload;
function Sign(const A: Single): Single; overload;
function Sign(const A: TVector2): TVector2; overload;
function Sign(const A: TVector3): TVector3; overload;
function Sign(const A: TVector4): TVector4; overload;
function Floor(const A: Single): Integer; overload; inline;
function Floor(const A: TVector2): TIVector2; overload;
function Floor(const A: TVector3): TIVector3; overload;
function Floor(const A: TVector4): TIVector4; overload;
function Trunc(const A: Single): Integer; overload; inline;
function Trunc(const A: TVector2): TIVector2; overload;
function Trunc(const A: TVector3): TIVector3; overload;
function Trunc(const A: TVector4): TIVector4; overload;
function Round(const A: Single): Integer; overload; inline;
function Round(const A: TVector2): TIVector2; overload;
function Round(const A: TVector3): TIVector3; overload;
function Round(const A: TVector4): TIVector4; overload;
function Ceil(const A: Single): Integer; overload; inline;
function Ceil(const A: TVector2): TIVector2; overload;
function Ceil(const A: TVector3): TIVector3; overload;
function Ceil(const A: TVector4): TIVector4; overload;
function Frac(const A: Single): Single; overload; inline;
function Frac(const A: TVector2): TVector2; overload;
function Frac(const A: TVector3): TVector3; overload;
function Frac(const A: TVector4): TVector4; overload;
function FMod(const A, B: Single): Single; overload; inline;
function FMod(const A: TVector2; const B: Single): TVector2; overload;
function FMod(const A, B: TVector2): TVector2; overload;
function FMod(const A: TVector3; const B: Single): TVector3; overload;
function FMod(const A, B: TVector3): TVector3; overload; inline;
function FMod(const A: TVector4; const B: Single): TVector4; overload;
function FMod(const A, B: TVector4): TVector4; overload;
function ModF(const A: Single; out B: Integer): Single; overload; inline;
function ModF(const A: TVector2; out B: TIVector2): TVector2; overload;
function ModF(const A: TVector3; out B: TIVector3): TVector3; overload;
function ModF(const A: TVector4; out B: TIVector4): TVector4; overload;
function Min(const A, B: Single): Single; overload; inline;
function Min(const A: TVector2; const B: Single): TVector2; overload;
function Min(const A, B: TVector2): TVector2; overload;
function Min(const A: TVector3; const B: Single): TVector3; overload;
function Min(const A, B: TVector3): TVector3; overload;
function Min(const A: TVector4; const B: Single): TVector4; overload;
function Min(const A, B: TVector4): TVector4; overload;
function Max(const A, B: Single): Single; overload; inline;
function Max(const A: TVector2; const B: Single): TVector2; overload;
function Max(const A, B: TVector2): TVector2; overload;
function Max(const A: TVector3; const B: Single): TVector3; overload;
function Max(const A, B: TVector3): TVector3; overload;
function Max(const A: TVector4; const B: Single): TVector4; overload;
function Max(const A, B: TVector4): TVector4; overload;
function EnsureRange(const A, AMin, AMax: Single): Single; overload;
function EnsureRange(const A: TVector2; const AMin, AMax: Single): TVector2; overload;
function EnsureRange(const A, AMin, AMax: TVector2): TVector2; overload;
function EnsureRange(const A: TVector3; const AMin, AMax: Single): TVector3; overload;
function EnsureRange(const A, AMin, AMax: TVector3): TVector3; overload;
function EnsureRange(const A: TVector4; const AMin, AMax: Single): TVector4; overload;
function EnsureRange(const A, AMin, AMax: TVector4): TVector4; overload;
function Mix(const A, B, T: Single): Single; overload; inline;
function Mix(const A, B: TVector2; const T: Single): TVector2; overload; inline;
function Mix(const A, B, T: TVector2): TVector2; overload; inline;
function Mix(const A, B: TVector3; const T: Single): TVector3; overload;
function Mix(const A, B, T: TVector3): TVector3; overload;
function Mix(const A, B: TVector4; const T: Single): TVector4; overload;
function Mix(const A, B, T: TVector4): TVector4; overload;
function Step(const AEdge, A: Single): Single; overload; inline;
function Step(const AEdge: Single; const A: TVector2): TVector2; overload;
function Step(const AEdge, A: TVector2): TVector2; overload;
function Step(const AEdge: Single; const A: TVector3): TVector3; overload;
function Step(const AEdge, A: TVector3): TVector3; overload;
function Step(const AEdge: Single; const A: TVector4): TVector4; overload;
function Step(const AEdge, A: TVector4): TVector4; overload;
function SmoothStep(const AEdge0, AEdge1, A: Single): Single; overload; inline;
function SmoothStep(const AEdge0, AEdge1: Single; const A: TVector2): TVector2; overload; inline;
function SmoothStep(const AEdge0, AEdge1, A: TVector2): TVector2; overload; inline;
function SmoothStep(const AEdge0, AEdge1: Single; const A: TVector3): TVector3; overload; inline;
function SmoothStep(const AEdge0, AEdge1, A: TVector3): TVector3; overload;
function SmoothStep(const AEdge0, AEdge1: Single; const A: TVector4): TVector4; overload;
function SmoothStep(const AEdge0, AEdge1, A: TVector4): TVector4; overload;
function FMA(const A, B, C: Single): Single; overload; inline;
function FMA(const A, B, C: TVector2): TVector2; overload;
function FMA(const A, B, C: TVector3): TVector3; overload;
function FMA(const A, B, C: TVector4): TVector4; overload;
function OuterProduct(const C, R: TVector2): TMatrix2; overload;
function OuterProduct(const C, R: TVector3): TMatrix3; overload;
function OuterProduct(const C, R: TVector4): TMatrix4; overload;
procedure DisableFloatingPointExceptions;
procedure RestoreFloatingPointExceptions;

Types

PVector2 = ˆTVector2;
PVector3 = ˆTVector3;
PVector4 = ˆTVector4;
PMatrix2 = ˆTMatrix2;
PMatrix3 = ˆTMatrix3;
PMatrix4 = ˆTMatrix4;
PIVector2 = ˆTIVector2;
PIVector3 = ˆTIVector3;
PIVector4 = ˆTIVector4;

Constants

SINGLE_TOLERANCE = 0.000001;

Description

Functions and Procedures

function Vector2: TVector2; overload; inline;

Creates a 2D zero-vector.

Note: it is more efficient to use TVector2.Init instead.

function Vector2(const A: Single): TVector2; overload; inline;

Creates a 2D vector with the two elements (X and Y) set to A.

Note: it is more efficient to use TVector2.Init instead.

Parameters
A
the value to set the two elements to.
function Vector2(const A1, A2: Single): TVector2; overload; inline;

Creates a 2D vector with the two elements (X and Y) set to A1 and A2 respectively.

Note: it is more efficient to use TVector2.Init instead.

Parameters
A1
the value to set the first element to.
A2
the value to set the second element to.
function Vector2(const AVector: TVector3): TVector2; overload; inline;

Creates a 2D vector using the first to elements (X and Y) of a 3D vector.

Note: it is more efficient to use TVector2.Init instead.

Parameters
AVector
the source vector
function Vector2(const AVector: TVector4): TVector2; overload; inline;

Creates a 2D vector using the first two elements (X and Y) of a 4D vector.

Note: it is more efficient to use TVector2.Init instead.

Parameters
AVector
the source vector
function Vector3: TVector3; overload;

Creates a 3D zero-vector.

Note: it is more efficient to use TVector3.Init instead.

function Vector3(const A: Single): TVector3; overload;

Creates a 3D vector with the three elements (X, Y and Z) set to A.

Note: it is more efficient to use TVector3.Init instead.

Parameters
A
the value to set the three elements to.
function Vector3(const A1, A2, A3: Single): TVector3; overload;

Creates a 3D vector with the three elements (X, Y and Z) set to A1, A2 and A3 respectively.

Note: it is more efficient to use TVector3.Init instead.

Parameters
A1
the value to set the first element to.
A2
the value to set the second element to.
A3
the value to set the third element to.
function Vector3(const A1: TVector2; const A2: Single): TVector3; overload;

Creates a 3D vector with the first two elements from a 2D vector, and the third element from a scalar.

Note: it is more efficient to use TVector3.Init instead.

Parameters
A1
the vector to use for the first two elements.
A2
the value to set the third element to.
function Vector3(const A1: Single; const A2: TVector2): TVector3; overload;

Creates a 3D vector with the first element from a scaler, and the last two elements from a 2D vector.

Note: it is more efficient to use TVector3.Init instead.

Parameters
A1
the value to set the first element to.
A2
the vector to use for the last two elements.
function Vector3(const AVector: TVector4): TVector3; overload;

Creates a 3D vector using the first three elements (X, Y and Z) of a 4D vector.

Note: it is more efficient to use TVector3.Init instead.

Parameters
AVector
the source vector
function Vector4: TVector4; overload;

Creates a 4D zero-vector.

Note: it is more efficient to use TVector4.Init instead.

function Vector4(const A: Single): TVector4; overload;

Creates a 4D vector with the four elements (X, Y, Z and W) set to A.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A
the value to set the four elements to.
function Vector4(const A1, A2, A3, A4: Single): TVector4; overload;

Creates a 4D vector with the four elements (X, Y, Z and W) set to A1, A2, A3 and A4 respectively.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A1
the value to set the first element to.
A2
the value to set the second element to.
A3
the value to set the third element to.
A4
the value to set the fourth element to.
function Vector4(const A1: TVector2; const A2, A3: Single): TVector4; overload;

Creates a 4D vector with the first two elements from a 2D vector, and the last two elements from two scalars.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A1
the vector to use for the first two elements.
A2
the value to set the third element to.
A3
the value to set the fourth element to.
function Vector4(const A1: Single; const A2: TVector2; const A3: Single): TVector4; overload;

Creates a 4D vector with the first and last elements from two scalars, and the middle two elements from a 2D vector.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A1
the value to set the first element to.
A2
the vector to use for the second and third elements.
A3
the value to set the fourth element to.
function Vector4(const A1, A2: Single; const A3: TVector2): TVector4; overload;

Creates a 4D vector with the first two elements from two scalars and the last two elements from a 2D vector.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A1
the value to set the first element to.
A2
the value to set the second element to.
A3
the vector to use for the last two elements.
function Vector4(const A1, A2: TVector2): TVector4; overload;

Creates a 4D vector with the first two elements and last two elements from two 2D vectors.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A1
the vector to use for the first two elements.
A2
the vector to use for the last two elements.
function Vector4(const A1: TVector3; const A2: Single): TVector4; overload;

Creates a 4D vector with the first three elements from a 3D vector, and the fourth element from a scalar.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A1
the vector to use for the first three elements.
A2
the value to set the fourth element to.
function Vector4(const A1: Single; const A2: TVector3): TVector4; overload;

Creates a 4D vector with the first element from a scaler, and the last three elements from a 3D vector.

Note: it is more efficient to use TVector4.Init instead.

Parameters
A1
the value to set the first element to.
A2
the vector to use for the last three elements.
function Quaternion: TQuaternion; overload;

Creates an identity quaternion (with X, Y and Z set to 0 and W set to 1).

Note: it is more efficient to use TQuaternion.Init instead.

function Quaternion(const AX, AY, AZ, AW: Single): TQuaternion; overload;

Creates a quaternion with the given components.

Note: it is more efficient to use TQuaternion.Init instead.

Parameters
AX
the X-component.
AY
the Y-component.
AZ
the Z-component.
AW
the W-component.
function Quaternion(const AAxis: TVector3; const AAngleRadians: Single): TQuaternion; overload;

Creates a quaternion from the given axis vector and the angle around that axis in radians.

Note: it is more efficient to use TQuaternion.Init instead.

Parameters
AAxis
The axis.
AAngleRadians
The angle in radians.
function Matrix2: TMatrix2; overload;

Creates a 2x2 identity matrix

Note: it is more efficient to use TMatrix2.Init instead.

function Matrix2(const ADiagonal: Single): TMatrix2; overload;

Creates a 2x2 matrix fill with zeros and sets the diagonal.

Note: it is more efficient to use TMatrix2.Init instead.

Parameters
ADiagonal
the value to use for the diagonal. Use 1 for an identity matrix.
function Matrix2(const ARow0, ARow1: TVector2): TMatrix2; overload;

Creates a 2x2 matrix using two row vectors.

Note: it is more efficient to use TMatrix2.Init instead.

Parameters
ARow0
the first row of the matrix.
ARow1
the second row of the matrix.
function Matrix2(const A11, A12, A21, A22: Single): TMatrix2; overload;

Creates a 2x2 matrix with explicit values.

Parameters: A11-A12: the values of the matrix elements, in row-major order.

Note: it is more efficient to use TMatrix2.Init instead.

function Matrix2(const AMatrix: TMatrix3): TMatrix2; overload;

Creates a 2x2 using the top-left corner of a 3x3 matrix. The remaining values of the source matrix are not used.

Note: it is more efficient to use TMatrix2.Init instead.

Parameters
AMatrix
the source 3x3 matrix.
function Matrix2(const AMatrix: TMatrix4): TMatrix2; overload;

Creates a 2x2 using the top-left corner of a 4x4 matrix. The remaining values of the source matrix are not used.

Note: it is more efficient to use TMatrix2.Init instead.

Parameters
AMatrix
the source 4x4 matrix.
function Matrix3: TMatrix3; overload;

Creates a 3x3 identity matrix

Note: it is more efficient to use TMatrix3.Init instead.

function Matrix3(const ADiagonal: Single): TMatrix3; overload;

Creates a 3x3 matrix fill with zeros and sets the diagonal.

Note: it is more efficient to use TMatrix3.Init instead.

Parameters
ADiagonal
the value to use for the diagonal. Use 1 for an identity matrix.
function Matrix3(const ARow0, ARow1, ARow2: TVector3): TMatrix3; overload;

Creates a 3x3 matrix using three row vectors.

Note: it is more efficient to use TMatrix3.Init instead.

Parameters
ARow0
the first row of the matrix.
ARow1
the second row of the matrix.
ARow2
the third row of the matrix.
function Matrix3(const A11, A12, A13, A21, A22, A23, A31, A32, A33: Single): TMatrix3; overload;

Creates a 3x3 matrix with explicit values.

Parameters: A11-A33: the values of the matrix elements, in row-major order.

Note: it is more efficient to use TMatrix3.Init instead.

function Matrix3(const AMatrix: TMatrix2): TMatrix3; overload;

Creates a 3x3 matrix by copying a 2x2 matrix to the top-left corner of the 3x3 matrix, and setting the remaining elements according to an identity matrix.

Note: it is more efficient to use TMatrix3.Init instead.

Parameters
AMatrix
the source 2x2 matrix.
function Matrix3(const AMatrix: TMatrix4): TMatrix3; overload;

Creates a 3x3 using the top-left corner of a 4x4 matrix. The remaining values of the source matrix are not used.

Note: it is more efficient to use TMatrix3.Init instead.

Parameters
AMatrix
the 4x4 source matrix.
function Matrix4: TMatrix4; overload;

Creates a 4x4 identity matrix

Note: it is more efficient to use TMatrix4.Init instead.

function Matrix4(const ADiagonal: Single): TMatrix4; overload;

Creates a 4x4 matrix fill with zeros and sets the diagonal.

Note: it is more efficient to use TMatrix4.Init instead.

Parameters
ADiagonal
the value to use for the diagonal. Use 1 for an identity matrix.
function Matrix4(const ARow0, ARow1, ARow2, ARow3: TVector4): TMatrix4; overload;

Creates a 4x4 matrix using four row vectors.

Note: it is more efficient to use TMatrix4.Init instead.

Parameters
ARow0
the first row of the matrix.
ARow1
the second row of the matrix.
ARow2
the third row of the matrix.
ARow3
the fourth row of the matrix.
function Matrix4(const A11, A12, A13, A14, A21, A22, A23, A24, A31, A32, A33, A34, A41, A42, A43, A44: Single): TMatrix4; overload;

Creates a 4x4 matrix with explicit values.

Parameters: A11-A44: the values of the matrix elements, in row-major order.

Note: it is more efficient to use TMatrix4.Init instead.

function Matrix4(const AMatrix: TMatrix2): TMatrix4; overload;

Creates a 4x4 matrix by copying a 2x2 matrix to the top-left corner of the 4x4 matrix, and setting the remaining elements according to an identity matrix.

Note: it is more efficient to use TMatrix4.Init instead.

Parameters
AMatrix
the source 2x2 matrix.
function Matrix4(const AMatrix: TMatrix3): TMatrix4; overload;

Creates a 4x4 matrix by copying a 3x3 matrix to the top-left corner of the 4x4 matrix, and setting the remaining elements according to an identity matrix.

Note: it is more efficient to use TMatrix4.Init instead.

Parameters
AMatrix
the source 3x3 matrix.
function IVector2: TIVector2; overload; inline;

Creates a 2D zero-vector.

Note: it is more efficient to use TIVector2.Init instead.

function IVector2(const A: Integer): TIVector2; overload; inline;

Creates a 2D vector with the two elements (X and Y) set to A.

Note: it is more efficient to use TIVector2.Init instead.

Parameters
A
the value to set the two elements to.
function IVector2(const A1, A2: Integer): TIVector2; overload; inline;

Creates a 2D vector with the two elements (X and Y) set to A1 and A2 respectively.

Note: it is more efficient to use TIVector2.Init instead.

Parameters
A1
the value to set the first element to.
A2
the value to set the second element to.
function IVector3: TIVector3; overload;

Creates a 3D zero-vector.

Note: it is more efficient to use TIVector3.Init instead.

function IVector3(const A: Integer): TIVector3; overload;

Creates a 3D vector with the three elements (X, Y and Z) set to A.

Note: it is more efficient to use TIVector3.Init instead.

Parameters
A
the value to set the three elements to.
function IVector3(const A1, A2, A3: Integer): TIVector3; overload;

Creates a 3D vector with the three elements (X, Y and Z) set to A1, A2 and A3 respectively.

Note: it is more efficient to use TIVector3.Init instead.

Parameters
A1
the value to set the first element to.
A2
the value to set the second element to.
A3
the value to set the third element to.
function IVector4: TIVector4; overload;

Creates a 4D zero-vector.

Note: it is more efficient to use TIVector4.Init instead.

function IVector4(const A: Integer): TIVector4; overload;

Creates a 4D vector with the four elements (X, Y, Z and W) set to A.

Note: it is more efficient to use TIVector4.Init instead.

Parameters
A
the value to set the four elements to.
function IVector4(const A1, A2, A3, A4: Integer): TIVector4; overload;

Creates a 4D vector with the four elements (X, Y, Z and W) set to A1, A2, A3 and A4 respectively.

Note: it is more efficient to use TIVector4.Init instead.

Parameters
A1
the value to set the first element to.
A2
the value to set the second element to.
A3
the value to set the third element to.
A4
the value to set the fourth element to.
function Radians(const ADegrees: Single): Single; overload; inline;
function Radians(const ADegrees: TVector2): TVector2; overload;
function Radians(const ADegrees: TVector3): TVector3; overload;
function Radians(const ADegrees: TVector4): TVector4; overload;

Converts degrees to radians.

Parameters
ADegrees
number of degrees.
Returns

ADegrees converted to radians.

function Degrees(const ARadians: Single): Single; overload; inline;
function Degrees(const ARadians: TVector2): TVector2; overload;
function Degrees(const ARadians: TVector3): TVector3; overload;
function Degrees(const ARadians: TVector4): TVector4; overload;

Converts radians to degrees.

Parameters
ARadians
number of radians.
Returns

ARadians converted to degrees.

function Sin(const ARadians: Single): Single; overload; inline;
function Sin(const ARadians: TVector2): TVector2; overload; inline;
function Sin(const ARadians: TVector3): TVector3; overload; inline;
function Sin(const ARadians: TVector4): TVector4; overload; inline;

Calculates the sine of an angle.

Note: You probably want to use FastSin instead, which is much faster but still very accurate to about +/-4000 radians (or +/-230,000 degrees).

Parameters
ARadians
the angle in radians.
Returns

The sine of the given angle.

function Cos(const ARadians: Single): Single; overload; inline;
function Cos(const ARadians: TVector2): TVector2; overload; inline;
function Cos(const ARadians: TVector3): TVector3; overload; inline;
function Cos(const ARadians: TVector4): TVector4; overload; inline;

Calculates the cosine of an angle.

Note: You probably want to use FastCos instead, which is much faster but still very accurate to about +/-4000 radians (or +/-230,000 degrees).

Parameters
ARadians
the angle in radians.
Returns

The cosine of the given angle.

procedure SinCos(const ARadians: Single; out ASin, ACos: Single); overload;
procedure SinCos(const ARadians: TVector2; out ASin, ACos: TVector2); overload;
procedure SinCos(const ARadians: TVector3; out ASin, ACos: TVector3); overload;
procedure SinCos(const ARadians: TVector4; out ASin, ACos: TVector4); overload;

Calculates the sine and cosine of an angle. This is faster than calling Sin and Cos separately.

Note: You probably want to use FastSinCos instead, which is much faster but still very accurate to about +/-4000 radians (or +/-230,000 degrees).

Parameters
ARadians
the angle in radians.
ASin
is set to the sine of the angle.
ACos
is set to the cosine of the angle.
function Tan(const ARadians: Single): Single; overload; inline;
function Tan(const ARadians: TVector2): TVector2; overload; inline;
function Tan(const ARadians: TVector3): TVector3; overload; inline;
function Tan(const ARadians: TVector4): TVector4; overload; inline;

Calculates the tangent of an angle.

Note: You probably want to use FastTan instead, which is much faster but still very accurate to about +/-4000 radians (or +/-230,000 degrees).

Parameters
ARadians
the angle in radians.
Returns

The tangent of the given angle.

function ArcSin(const A: Single): Single; overload; inline;
function ArcSin(const A: TVector2): TVector2; overload; inline;
function ArcSin(const A: TVector3): TVector3; overload; inline;
function ArcSin(const A: TVector4): TVector4; overload; inline;

Calculates the angle whose sine is A.

Parameters
A
the sine whose angle to calculate. Results are undefined if (A < -1) or (A > 1).
Returns

The angle in radians, in the range [-Pi/2..Pi/2]

function ArcCos(const A: Single): Single; overload; inline;
function ArcCos(const A: TVector2): TVector2; overload; inline;
function ArcCos(const A: TVector3): TVector3; overload; inline;
function ArcCos(const A: TVector4): TVector4; overload; inline;

Calculates the angle whose cosine is A.

Parameters
A
the cosine whose angle to calculate. Results are undefined if (A < -1) or (A > 1).
Returns

The angle in radians, in the range [0..Pi]

function ArcTan(const A: Single): Single; overload; inline;
function ArcTan(const A: TVector2): TVector2; overload; inline;
function ArcTan(const A: TVector3): TVector3; overload; inline;
function ArcTan(const A: TVector4): TVector4; overload; inline;

Calculates the angle whose tangent is A.

Parameters
A
the tangent whose angle to calculate.
Returns

The angle in radians, in the range [-Pi/2..Pi/2]

function ArcTan2(const Y, X: Single): Single; overload; inline;
function ArcTan2(const Y, X: TVector2): TVector2; overload; inline;
function ArcTan2(const Y, X: TVector3): TVector3; overload; inline;
function ArcTan2(const Y, X: TVector4): TVector4; overload; inline;

Calculates the principal value of the arctangent of Y/X, expressed in radians.

Parameters
Y
proportion of the Y-coordinate.
X
proportion of the X-coordinate.
Returns

The angle in radians, in the range [-Pi..Pi]

function Sinh(const A: Single): Single; overload; inline;
function Sinh(const A: TVector2): TVector2; overload; inline;
function Sinh(const A: TVector3): TVector3; overload; inline;
function Sinh(const A: TVector4): TVector4; overload; inline;

Calculates a hyperbolic sine.

Parameters
A
the value.
Returns

The hyperbolic sine of A.

function Cosh(const A: Single): Single; overload; inline;
function Cosh(const A: TVector2): TVector2; overload; inline;
function Cosh(const A: TVector3): TVector3; overload; inline;
function Cosh(const A: TVector4): TVector4; overload; inline;

Calculates a hyperbolic cosine.

Parameters
A
the value.
Returns

The hyperbolic cosine of A.

function Tanh(const A: Single): Single; overload; inline;
function Tanh(const A: TVector2): TVector2; overload; inline;
function Tanh(const A: TVector3): TVector3; overload; inline;
function Tanh(const A: TVector4): TVector4; overload; inline;

Calculates a hyperbolic tangent.

Parameters
A
the value.
Returns

The hyperbolic tangent of A.

function ArcSinh(const A: Single): Single; overload; inline;
function ArcSinh(const A: TVector2): TVector2; overload; inline;
function ArcSinh(const A: TVector3): TVector3; overload; inline;
function ArcSinh(const A: TVector4): TVector4; overload; inline;

Calculates an inverse hyperbolic sine.

Parameters
A
the value.
Returns

The inverse hyperbolic sine of A.

function ArcCosh(const A: Single): Single; overload; inline;
function ArcCosh(const A: TVector2): TVector2; overload; inline;
function ArcCosh(const A: TVector3): TVector3; overload; inline;
function ArcCosh(const A: TVector4): TVector4; overload; inline;

Calculates an inverse hyperbolic cosine.

Parameters
A
the value.
Returns

The inverse hyperbolic cosine of A.

function ArcTanh(const A: Single): Single; overload; inline;
function ArcTanh(const A: TVector2): TVector2; overload; inline;
function ArcTanh(const A: TVector3): TVector3; overload; inline;
function ArcTanh(const A: TVector4): TVector4; overload; inline;

Calculates an inverse hyperbolic tangent.

Parameters
A
the value.
Returns

The inverse hyperbolic tangent of A.

function Power(const ABase, AExponent: Single): Single; overload; inline;
function Power(const ABase, AExponent: TVector2): TVector2; overload; inline;
function Power(const ABase, AExponent: TVector3): TVector3; overload;
function Power(const ABase, AExponent: TVector4): TVector4; overload;

Calculates ABase raised to the AExponent power.

Note: Consider using FastPower instead, which is much faster, but at a maximum relative error of about 0.2%.

Parameters
ABase
the base value. Must be >= 0.
AExponent
the exponent value.
Returns

ABase raised to the AExponent power. Results are undefined if both ABase=0 and AExponent<=0.

function Exp(const A: Single): Single; overload; inline;
function Exp(const A: TVector2): TVector2; overload; inline;
function Exp(const A: TVector3): TVector3; overload;
function Exp(const A: TVector4): TVector4; overload;

Calculates a natural exponentiation (that is, e raised to a given power).

Note: Consider using FastExp instead, which is much faster, but at a maximum absolute error of about 0.00001.

Parameters
A
the value
Returns

The natural exponentation of A (e raised to the power of A).

function Ln(const A: Single): Single; overload; inline;
function Ln(const A: TVector2): TVector2; overload; inline;
function Ln(const A: TVector3): TVector3; overload;
function Ln(const A: TVector4): TVector4; overload;

Calculates a natural logarithm.

Note: Consider using FastLn instead, which is much faster, but at a maximum absolute error of about 0.00003.

Parameters
A
the value. Results are undefined if A <= 0.
Returns

The natural logarithm of A (that is, the value B so that A equals e raised to the power of B)

function Exp2(const A: Single): Single; overload; inline;
function Exp2(const A: TVector2): TVector2; overload; inline;
function Exp2(const A: TVector3): TVector3; overload;
function Exp2(const A: TVector4): TVector4; overload;

Calculates 2 raised to a power.

Note: Consider using FastExp2 instead, which is much faster, but less accurate.

Parameters
A
the value
Returns

2 raised to the power of A.

function Log2(const A: Single): Single; overload; inline;
function Log2(const A: TVector2): TVector2; overload; inline;
function Log2(const A: TVector3): TVector3; overload;
function Log2(const A: TVector4): TVector4; overload;

Calculates a base 2 logarithm.

Note: Consider using FastLog2 instead, which is much faster, but at a maximum absolute error of about 0.0002.

Parameters
A
the value. Results are undefined if A <= 0.
Returns

The base 2 logarithm of A (that is, the value B so that A equals 2 raised to the power of B)

function Sqrt(const A: Single): Single; overload;
function Sqrt(const A: TVector2): TVector2; overload;
function Sqrt(const A: TVector3): TVector3; overload;
function Sqrt(const A: TVector4): TVector4; overload;

Calculates a square root.

Note: If you plan to divide a certain value by the returned square root, then consider using InverseSqrt instead. That version is usually faster to calculate and you can replace an expensive division with a faster multiplication.

Parameters
A
the value. Results are undefined if A < 0.
Returns

The square root of A.

function InverseSqrt(const A: Single): Single; overload;
function InverseSqrt(const A: TVector2): TVector2; overload;
function InverseSqrt(const A: TVector3): TVector3; overload;
function InverseSqrt(const A: TVector4): TVector4; overload;

Calculates an inverse square root.

Note: You can use this function if you need to divide a given value by a square root. The inverse square root is usually faster to calculate, and you can replace an expensive division with a faster multiplication.

Note: The SIMD optimized versions of these functions use an approximation, resulting in a very small error.

Parameters
A
the value. Results are undefined if A <= 0.
Returns

1/Sqrt(A)

function FastSin(const ARadians: Single): Single; overload;
function FastSin(const ARadians: TVector2): TVector2; overload;
function FastSin(const ARadians: TVector3): TVector3; overload;
function FastSin(const ARadians: TVector4): TVector4; overload;

Calculates the sine of an angle.

Note: This function provides excellent precisions when ARadians is about the range [-4000..4000] (about +/-230,000 degrees)

Parameters
ARadians
the angle in radians.
Returns

The (approximate) sine of the given angle.

function FastCos(const ARadians: Single): Single; overload;
function FastCos(const ARadians: TVector2): TVector2; overload;
function FastCos(const ARadians: TVector3): TVector3; overload;
function FastCos(const ARadians: TVector4): TVector4; overload;

Calculates the cosine of an angle.

Note: This function provides excellent precisions when ARadians is about the range [-4000..4000] (about +/-230,000 degrees)

Parameters
ARadians
the angle in radians.
Returns

The (approximate) cosine of the given angle.

procedure FastSinCos(const ARadians: Single; out ASin, ACos: Single); overload;
procedure FastSinCos(const ARadians: TVector2; out ASin, ACos: TVector2); overload;
procedure FastSinCos(const ARadians: TVector3; out ASin, ACos: TVector3); overload;
procedure FastSinCos(const ARadians: TVector4; out ASin, ACos: TVector4); overload;

Calculates the sine and cosine of an angle. This is faster than calling FastSin and FastCos separately.

Note: This function provides excellent precisions when ARadians is about the range [-4000..4000] (about +/-230,000 degrees)

Parameters
ARadians
the angle in radians.
ASin
is set to the (approximate) sine of the angle.
ACos
is set to the (approximate) cosine of the angle.
function FastTan(const ARadians: Single): Single; overload;
function FastTan(const ARadians: TVector2): TVector2; overload;
function FastTan(const ARadians: TVector3): TVector3; overload;
function FastTan(const ARadians: TVector4): TVector4; overload;

Calculates the tangent of an angle.

Note: This function provides excellent precisions when ARadians is about the range [-4000..4000] (about +/-230,000 degrees)

Parameters
ARadians
the angle in radians.
Returns

The (approximate) tangent of the given angle.

function FastArcTan2(const Y, X: Single): Single; overload;
function FastArcTan2(const Y, X: TVector2): TVector2; overload;
function FastArcTan2(const Y, X: TVector3): TVector3; overload;
function FastArcTan2(const Y, X: TVector4): TVector4; overload;

Calculates the principal value of the arctangent of Y/X, expressed in radians.

Parameters
Y
proportion of the Y-coordinate.
X
proportion of the X-coordinate.
Returns

The (approximate) angle in radians, in the range [-Pi..Pi]

function FastPower(const ABase, AExponent: Single): Single; overload; inline;
function FastPower(const ABase, AExponent: TVector2): TVector2; overload; inline;
function FastPower(const ABase, AExponent: TVector3): TVector3; overload;
function FastPower(const ABase, AExponent: TVector4): TVector4; overload;

Calculates ABase raised to the AExponent power.

Note: The error depends on the magnitude of the result. The relative error is at most about 0.2%

Parameters
ABase
the base value. Must be >= 0.
AExponent
the exponent value.
Returns

(Approximate) ABase raised to the AExponent power. Results are undefined if both ABase=0 and AExponent<=0.

function FastExp(const A: Single): Single; overload;
function FastExp(const A: TVector2): TVector2; overload;
function FastExp(const A: TVector3): TVector3; overload;
function FastExp(const A: TVector4): TVector4; overload;

Calculates a natural exponentiation (that is, e raised to a given power).

Note: Maximum absolute error is about 0.00001

Parameters
A
the value
Returns

The (approximate) natural exponentation of A (e raised to the power of A)

function FastLn(const A: Single): Single; overload;
function FastLn(const A: TVector2): TVector2; overload;
function FastLn(const A: TVector3): TVector3; overload;
function FastLn(const A: TVector4): TVector4; overload;

Calculates a natural logarithm.

Note: Maximum absolute error is about 0.00003.

Parameters
A
the value. Results are undefined if A <= 0.
Returns

The (approximate) natural logarithm of A (that is, the value B so that A equals e raised to the power of B)

function FastLog2(const A: Single): Single; overload;
function FastLog2(const A: TVector2): TVector2; overload;
function FastLog2(const A: TVector3): TVector3; overload;
function FastLog2(const A: TVector4): TVector4; overload;

Calculates a base 2 logarithm.

Note: Maximum absolute error is about 0.0002

Parameters
A
the value. Results are undefined if A <= 0.
Returns

The (approximate) base 2 logarithm of A (that is, the value B so that A equals 2 raised to the power of B)

function FastExp2(const A: Single): Single; overload;
function FastExp2(const A: TVector2): TVector2; overload;
function FastExp2(const A: TVector3): TVector3; overload;
function FastExp2(const A: TVector4): TVector4; overload;

Calculates 2 raised to a power.

Note: If A needs to be outside of the range [-127..127], then use Exp2 instead.

Parameters
A
the value. Must be in the range [-127..127] for valid results.
Returns

(Approximate) 2 raised to the power of A.

function Abs(const A: Single): Single; overload; inline;
function Abs(const A: TVector2): TVector2; overload; inline;
function Abs(const A: TVector3): TVector3; overload;
function Abs(const A: TVector4): TVector4; overload;

Calculates an absolute value.

Parameters
A
the value.
Returns

A if A >= 0, otherwise -A.

function Sign(const A: Single): Single; overload;
function Sign(const A: TVector2): TVector2; overload;
function Sign(const A: TVector3): TVector3; overload;
function Sign(const A: TVector4): TVector4; overload;

Calculates the sign of a value.

Parameters
A
the value.
Returns

-1.0 if A < 0, 0.0 if A = 0, or 1.0 if A > 0.

function Floor(const A: Single): Integer; overload; inline;
function Floor(const A: TVector2): TIVector2; overload;
function Floor(const A: TVector3): TIVector3; overload;
function Floor(const A: TVector4): TIVector4; overload;

Rounds a value towards negative infinity.

Parameters
A
the value.
Returns

A value equal to the nearest integer that is less than or equal to A.

function Trunc(const A: Single): Integer; overload; inline;
function Trunc(const A: TVector2): TIVector2; overload;
function Trunc(const A: TVector3): TIVector3; overload;
function Trunc(const A: TVector4): TIVector4; overload;

Rounds a value towards 0.

Parameters
A
the value.
Returns

The value A rounded towards 0. That is, with its fractional part removed.

function Round(const A: Single): Integer; overload; inline;
function Round(const A: TVector2): TIVector2; overload;
function Round(const A: TVector3): TIVector3; overload;
function Round(const A: TVector4): TIVector4; overload;

Rounds a value towards its nearest integer.

Parameters
A
the value.
Returns

The integer value closest to A. If A is exactly between two integer values (if the fraction is 0.5), then the result is the even number.

function Ceil(const A: Single): Integer; overload; inline;
function Ceil(const A: TVector2): TIVector2; overload;
function Ceil(const A: TVector3): TIVector3; overload;
function Ceil(const A: TVector4): TIVector4; overload;

Rounds a value towards positive infinity.

Parameters
A
the value.
Returns

A value equal to the nearest integer that is greater than or equal to A.

function Frac(const A: Single): Single; overload; inline;
function Frac(const A: TVector2): TVector2; overload;
function Frac(const A: TVector3): TVector3; overload;
function Frac(const A: TVector4): TVector4; overload;

Returns the fractional part of a number.

Parameters
A
the value.
Returns

The fractional part of A, calculated as to A - Trunc(A)

function FMod(const A, B: Single): Single; overload; inline;
function FMod(const A: TVector2; const B: Single): TVector2; overload;
function FMod(const A, B: TVector2): TVector2; overload;
function FMod(const A: TVector3; const B: Single): TVector3; overload;
function FMod(const A, B: TVector3): TVector3; overload; inline;
function FMod(const A: TVector4; const B: Single): TVector4; overload;
function FMod(const A, B: TVector4): TVector4; overload;

Modulus. Calculates the remainder of a floating-point division.

Note: When used with vectors, B can be a scalar or a vector.

Parameters
A
the dividend.
B
the divisor.
Returns

The remainder of A / B, calculated as A - B * Trunc(A / B)

function ModF(const A: Single; out B: Integer): Single; overload; inline;
function ModF(const A: TVector2; out B: TIVector2): TVector2; overload;
function ModF(const A: TVector3; out B: TIVector3): TVector3; overload;
function ModF(const A: TVector4; out B: TIVector4): TVector4; overload;

Splits a floating-point value into its integer and fractional parts.

Note: Both the return value and output parameter B will have the same sign as A.

Parameters
A
the value to split.
B
is set to the integer part of A
Returns

The fractional part of A.

function Min(const A, B: Single): Single; overload; inline;
function Min(const A: TVector2; const B: Single): TVector2; overload;
function Min(const A, B: TVector2): TVector2; overload;
function Min(const A: TVector3; const B: Single): TVector3; overload;
function Min(const A, B: TVector3): TVector3; overload;
function Min(const A: TVector4; const B: Single): TVector4; overload;
function Min(const A, B: TVector4): TVector4; overload;

Calculates the minimum of two values.

Note: When used with vectors, B can be a scalar or a vector.

Parameters
A
the first value.
B
the second value.
Returns

The minimum of A and B.

function Max(const A, B: Single): Single; overload; inline;
function Max(const A: TVector2; const B: Single): TVector2; overload;
function Max(const A, B: TVector2): TVector2; overload;
function Max(const A: TVector3; const B: Single): TVector3; overload;
function Max(const A, B: TVector3): TVector3; overload;
function Max(const A: TVector4; const B: Single): TVector4; overload;
function Max(const A, B: TVector4): TVector4; overload;

Calculates the maximum of two values.

Note: When used with vectors, B can be a scalar or a vector.

Parameters
A
the first value.
B
the second value.
Returns

The maximum of A and B.

function EnsureRange(const A, AMin, AMax: Single): Single; overload;
function EnsureRange(const A: TVector2; const AMin, AMax: Single): TVector2; overload;
function EnsureRange(const A, AMin, AMax: TVector2): TVector2; overload;
function EnsureRange(const A: TVector3; const AMin, AMax: Single): TVector3; overload;
function EnsureRange(const A, AMin, AMax: TVector3): TVector3; overload;
function EnsureRange(const A: TVector4; const AMin, AMax: Single): TVector4; overload;
function EnsureRange(const A, AMin, AMax: TVector4): TVector4; overload;

Clamps a given value into a range.

Note: When used with vectors, AMin and AMax can be scalars or vectors.

Parameters
A
the value to clamp.
AMin
the minimum value of the range.
AMax
the maximum value of the range. Must be >= AMin.
Returns

A clamped to the range [AMin..AMax]. Results are undefined if AMin > AMax. No error checking is performed for this situation.

function Mix(const A, B, T: Single): Single; overload; inline;
function Mix(const A, B: TVector2; const T: Single): TVector2; overload; inline;
function Mix(const A, B, T: TVector2): TVector2; overload; inline;
function Mix(const A, B: TVector3; const T: Single): TVector3; overload;
function Mix(const A, B, T: TVector3): TVector3; overload;
function Mix(const A, B: TVector4; const T: Single): TVector4; overload;
function Mix(const A, B, T: TVector4): TVector4; overload;

Calculates a linear blend between two values, using on a progress value.

Note: When used with vectors, T can be a scalar or a vector.

Parameters
A
the first value.
B
the second value.
T
the progress value, usually between 0.0 and 1.0.
Returns

A value interpolated between A and B, as controlled by T. If T=0, then A is returned. If T=1 then B is returned. For values in between 0 and 1, the result is linearly interpolated with the formula "A * (1 - T) + (B * T)".

function Step(const AEdge, A: Single): Single; overload; inline;
function Step(const AEdge: Single; const A: TVector2): TVector2; overload;
function Step(const AEdge, A: TVector2): TVector2; overload;
function Step(const AEdge: Single; const A: TVector3): TVector3; overload;
function Step(const AEdge, A: TVector3): TVector3; overload;
function Step(const AEdge: Single; const A: TVector4): TVector4; overload;
function Step(const AEdge, A: TVector4): TVector4; overload;

Step function.

Note: When used with vectors, AEdge can be a scalar or a vector.

Parameters
AEdge
the edge value.
A
the value to check.
Returns

0.0 if A < AEdge. Otherwise it returns 1.0.

function SmoothStep(const AEdge0, AEdge1, A: Single): Single; overload; inline;
function SmoothStep(const AEdge0, AEdge1: Single; const A: TVector2): TVector2; overload; inline;
function SmoothStep(const AEdge0, AEdge1, A: TVector2): TVector2; overload; inline;
function SmoothStep(const AEdge0, AEdge1: Single; const A: TVector3): TVector3; overload; inline;
function SmoothStep(const AEdge0, AEdge1, A: TVector3): TVector3; overload;
function SmoothStep(const AEdge0, AEdge1: Single; const A: TVector4): TVector4; overload;
function SmoothStep(const AEdge0, AEdge1, A: TVector4): TVector4; overload;

Performs smooth Hermite interpolation between 0 and 1.

Note: The interpolation is calculated using the algorithm:

      T := EnsureRange((A - AEdge0) / (AEdge1 - AEdge0), 0, 1);
      Result := T * T * (3 - 2 * T);

Results are undefined if AEdge0 >= AEdge1. When used with vectors, AEdge0 and AEdge1 can be scalars or vectors.

Parameters
AEdge0
the left value of the edge.
AEdge1
the right value of the edge.
A
the value used to control the interpolation.
Returns

0.0 if A <= AEdge0 and 1.0 if A >= AEdge1. Otherwise it performs a smooth Hermite interpolation between 0 and 1, based on the position of A between AEdge0 and AEdge1. This is useful in cases where you would want a threshold function with a smooth transition (as compared to the Step function). The graph would show a curve increasing slowly from 0.0, the speeding up towards 0.5 and finally slowing down towards 1.0.

function FMA(const A, B, C: Single): Single; overload; inline;
function FMA(const A, B, C: TVector2): TVector2; overload;
function FMA(const A, B, C: TVector3): TVector3; overload;
function FMA(const A, B, C: TVector4): TVector4; overload;

Fused Multiply and Add (if available).

Note: On ARM platforms (iOS and Android), the calculation is performed with as a single (fused) operation. This provides better precision (because it skips the intermediate rounding).

On other platforms, this is not really a fused operation, but just a separate muliplication and addition.

Parameters
A
the first value.
B
the second value.
C
the third value.
Returns

(A * B) + C

function OuterProduct(const C, R: TVector2): TMatrix2; overload;
function OuterProduct(const C, R: TVector3): TMatrix3; overload;
function OuterProduct(const C, R: TVector4): TMatrix4; overload;

Treats the first parameter C as a column vector (matrix with one column) and the second parameter R as a row vector (matrix with one row) and does a linear algebraic matrix multiply C * R, yielding a matrix whose number of rows and columns matches that of the two vectors.

Parameters
C
the column vector.
R
the row vector.
Returns

The outer product of C and R.

procedure DisableFloatingPointExceptions;

Disables floating-point exceptions. Instead invalid floating-point operations will return one of the following values:

  • 0: if underflow occurs (if the value is smaller than can be represented using floating-point). For example by evaluating "0.5 * MinSingle".

  • MaxSingle/MaxDouble: if there is not enough precision available. For example by evaluating "MaxSingle + 1".

  • +/-INF: when a division by zero or overflow occurs. For example by evaluating "Value / 0" or "MaxSingle * 2".

  • +/-NAN: when an invalid operation occurs. For example by evaluating "Sqrt(-1)"

Note: On some platforms, this only disables exceptions on the thread that calls this routine. So in multi-threaded scenarios, it is best to call this routine in the Execute block of every thread where you want to ignore floating point exceptions.

Note: For more fine-grained control over which exception types to disable, use the SetExceptionMask and/or SetSSEExceptionMask functions in the System.Math unit.

procedure RestoreFloatingPointExceptions;

Restore the floating-point exception flags to the state before you called DisableFloatingPointExceptions

Types

PVector2 = ˆTVector2;
 
PVector3 = ˆTVector3;
 
PVector4 = ˆTVector4;
 
PMatrix2 = ˆTMatrix2;
 
PMatrix3 = ˆTMatrix3;
 
PMatrix4 = ˆTMatrix4;
 
PIVector2 = ˆTIVector2;
 
PIVector3 = ˆTIVector3;
 
PIVector4 = ˆTIVector4;
 

Constants

SINGLE_TOLERANCE = 0.000001;

Default tolerance for comparing small floating-point values.


Generated by PasDocEx, based on PasDoc 0.14.0.