4#include "foundation/DataTypes.h"
19 const static float PI;
29 template<Arithmetic T>
32 return value * (
PI / 180.0f);
38 template<Arithmetic T>
41 return value * ((
PI / 180.0f) * 0.5f);
47 template<Arithmetic T>
48 constexpr static int32
Ceil(T value)
50 int32 intPart =
static_cast<int32
>(value);
51 if (value ==
static_cast<T
>(intPart))
56 return value > 0 ? intPart + 1 : intPart;
62 template<Arithmetic T>
63 constexpr static T
Tan(T value)
71 template<Arithmetic T>
72 constexpr static T
Sin(T value)
80 template<Arithmetic T>
81 constexpr static T
Cos(T value)
89 template<Arithmetic T>
90 constexpr static T
Abs(T value)
98 template<Arithmetic T>
118 template<Arithmetic T>
119 constexpr static T
Sqrt(T value)
127 template<Arithmetic T>
128 constexpr static T
Lerp(T from, T to, T amount)
130 return from + (to - from) * amount;
136 template<Arithmetic T>
144 for (int32 i = 0; i < 100; ++i)
164 template<Arithmetic T>
167 if (n == 0 || n == 1)
172 for (int32 i = 2; i <= n; ++i)
182 template<Arithmetic T>
185 if (x < -1.0 || x > 1.0)
192 for (int32 i = 1; i < 100; ++i)
194 term *= x * x * (2 * n - 1) * (2 * n - 1) / (2 * n * (2 * n + 1));
205 template<Arithmetic T>
208 return magnitude * (signbit(sign) ? -1.0 : 1.0);
214 template<Arithmetic T>
223 return atan(y / x) +
PI;
227 return atan(y / x) -
PI;
244 template<Arithmetic T>
245 constexpr static T
Clamp(T value, T min, T max)
247 const T& t = value < min ? min : value;
248 return t > max ? max : t;
A utility which contains essential mathematical functions and constants.
Definition Math.h:14
static constexpr T Sin(T value)
Mathematical function that computes the sine of an angle (in radians).
Definition Math.h:72
static constexpr T Atan(T x)
Mathematical function that computes the arctangent of a value using a Taylor series.
Definition Math.h:137
static constexpr T Copysign(T magnitude, T sign)
Mathematical function that returns a value with the magnitude of the first argument and the sign of t...
Definition Math.h:206
static const float Epsilon
Mathematical constant equal to 1e-6f.
Definition Math.h:24
static constexpr T HalfRadians(T value)
Mathematical function that converts degrees to half-radians.
Definition Math.h:39
static constexpr T Lerp(T from, T to, T amount)
Mathematical function that linearly interpolates between two values based on a weight.
Definition Math.h:128
static constexpr T Atan2(T x, T y)
Mathematical function that computes the arctangent of y/x using signs to determine the correct quadra...
Definition Math.h:215
static constexpr T Abs(T value)
Mathematical function that returns the absolute value of the input.
Definition Math.h:90
static constexpr T Tan(T value)
Mathematical function that computes the tangent of an angle (in radians).
Definition Math.h:63
static constexpr T Asin(T x)
Mathematical function that computes the arcsine of a value using a power series.
Definition Math.h:183
static constexpr T Clamp(T value, T min, T max)
Mathematical function that clamps a value between a minimum and maximum.
Definition Math.h:245
static constexpr T Radians(T value)
Mathematical function that converts degrees to radians.
Definition Math.h:30
static constexpr T Cos(T value)
Mathematical function that computes the cosine of an angle (in radians).
Definition Math.h:81
static constexpr T Sqrt(T value)
Mathematical function that computes the square root of the input.
Definition Math.h:119
static constexpr T Inverse(T value)
Mathematical function that returns the value with its sign inverted.
Definition Math.h:99
static constexpr int32 Ceil(T value)
Mathematical function that returns the smallest integer greater than or equal to the input.
Definition Math.h:48
static constexpr T Factorical(int32 n)
Mathematical function that computes the factorial of an integer.
Definition Math.h:165
static const float PI
Mathematical constant approximately equal to 3.14159, that is ratio of a circle's circumference to it...
Definition Math.h:19