Provides mathematical functions and utilities, primarily focused on fixed-point arithmetic.
More...
|
#define | M_E 2.71828182845904523536028747135266250 /* e */ |
|
#define | M_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ |
|
#define | M_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ |
|
#define | M_LN2 0.693147180559945309417232121458176568 /* loge(2) */ |
|
#define | M_LN10 2.30258509299404568401799145468436421 /* loge(10) */ |
|
#define | M_PI 3.14159265358979323846264338327950288 /* pi */ |
|
#define | M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */ |
|
#define | M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */ |
|
#define | M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */ |
|
#define | M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */ |
|
#define | M_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */ |
|
#define | M_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */ |
|
#define | M_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */ |
|
#define | MAXFLOAT 0x1.fffffep+127f |
|
|
std::string | tostr (const fx8 &val) |
|
std::string | tostr (const Vec &val) |
|
std::string | tostr (const Rect &val) |
|
const fx8 & | _min (const fx8 &lhs_, const fx8 &rhs_) |
| Get the minimum of two fixed-point values.
|
|
const fx8 & | _max (const fx8 &lhs_, const fx8 &rhs_) |
| Get the maximum of two fixed-point values.
|
|
const fx8 & | _lim (const fx8 &x_, const fx8 &lhs_, const fx8 &rhs_) |
| Limit a fixed-point value within a specified range.
|
|
const fx8 | _abs (const fx8 &x_) |
| Get the absolute value of a fixed-point number.
|
|
template<typename T , typename U , typename V > |
T | lim (const T &x_, const U &lhs_, const V &rhs_) |
| Limit a value within a specified range.
|
|
s16 | sin_12 (u32 th) |
| Calculate the sine of an angle using a 12-bit angle representation.
|
|
s16 | cos_12 (u32 th) |
| Calculate the cosine of an angle using a 12-bit angle representation.
|
|
fx8 | rad_cos_12 (fx8 rad, u32 th) |
| Calculate the cosine of an angle and scale a fixed-point value by it.
|
|
fx8 | rad_sin_12 (fx8 rad, u32 th) |
| Calculate the sine of an angle and scale a fixed-point value by it.
|
|
fx8 | genrand_min_max_fx8 (fx8 min_, fx8 max_) |
| Generate a random fixed-point number within a specified range.
|
|
uint32_t | qmod (uint32_t x, uint32_t N) |
| Computes the remainder of x divided by N using an optimized method.
|
|
uint32_t | qdiv (uint32_t x, uint32_t N) |
| Computes the quotient of x divided by N using an optimized method.
|
|
|
constexpr fx8 | FX8_E = fx8(696, 256) |
|
constexpr fx8 | FX8_LOG2E = fx8(369, 256) |
|
constexpr fx8 | FX8_LOG10E = fx8(111, 256) |
|
constexpr fx8 | FX8_LN2 = fx8(178, 256) |
|
constexpr fx8 | FX8_LN10 = fx8(590, 256) |
|
constexpr fx8 | FX8_1_PI = fx8(82, 256) |
|
constexpr fx8 | FX8_2_PI = fx8(163, 256) |
|
constexpr fx8 | FX8_2_SQRTPI = fx8(289, 256) |
|
constexpr fx8 | FX8_SQRT2 = fx8(362, 256) |
|
constexpr fx8 | FX8_SQRT1_2 = fx8(181, 256) |
|
constexpr fx8 | FX8_2PI = fx8(1608, 256) |
|
constexpr fx8 | FX8_PI = fx8(804, 256) |
|
constexpr fx8 | FX8_PI_2 = fx8(402, 256) |
|
constexpr fx8 | FX8_PI_3 = fx8(268, 256) |
|
constexpr fx8 | FX8_PI_4 = fx8(201, 256) |
|
constexpr fx8 | FX8_PI_5 = fx8(161, 256) |
|
constexpr fx8 | FX8_PI_6 = fx8(134, 256) |
|
constexpr fx8 | FX8_PI_7 = fx8(115, 256) |
|
constexpr fx8 | FX8_PI_8 = fx8(100, 256) |
|
constexpr fx8 | FX8_PI_9 = fx8(89, 256) |
|
constexpr fx8 | FX8_PI_10 = fx8(80, 256) |
|
constexpr fx8 | FX8_PI_11 = fx8(73, 256) |
|
constexpr fx8 | FX8_PI_12 = fx8(67, 256) |
|
constexpr fx8 | FX8_PI_13 = fx8(62, 256) |
|
constexpr fx8 | FX8_PI_14 = fx8(57, 256) |
|
constexpr fx8 | FX8_PI_15 = fx8(54, 256) |
|
constexpr fx8 | FX8_PI_16 = fx8(50, 256) |
|
constexpr fx12 | FX12_E = fx12(11135, 4096) |
|
constexpr fx12 | FX12_LOG2E = fx12(5912, 4096) |
|
constexpr fx12 | FX12_LOG10E = fx12(1785, 4096) |
|
constexpr fx12 | FX12_LN2 = fx12(2831, 4096) |
|
constexpr fx12 | FX12_LN10 = fx12(9438, 4096) |
|
constexpr fx12 | FX12_1_PI = fx12(1317, 4096) |
|
constexpr fx12 | FX12_2_PI = fx12(2634, 4096) |
|
constexpr fx12 | FX12_2_SQRTPI = fx12(4613, 4096) |
|
constexpr fx12 | FX12_SQRT2 = fx12(5793, 4096) |
|
constexpr fx12 | FX12_SQRT1_2 = fx12(2896, 4096) |
|
constexpr fx12 | FX12_PI = fx12(12868, 4096) |
|
constexpr fx12 | FX12_PI_2 = fx12(6434, 4096) |
|
constexpr fx12 | FX12_PI_3 = fx12(4290, 4096) |
|
constexpr fx12 | FX12_PI_4 = fx12(3217, 4096) |
|
constexpr fx12 | FX12_PI_5 = fx12(2574, 4096) |
|
constexpr fx12 | FX12_PI_6 = fx12(2145, 4096) |
|
constexpr fx12 | FX12_PI_7 = fx12(1838, 4096) |
|
constexpr fx12 | FX12_PI_8 = fx12(1609, 4096) |
|
constexpr fx12 | FX12_PI_9 = fx12(1432, 4096) |
|
constexpr fx12 | FX12_PI_10 = fx12(1287, 4096) |
|
constexpr fx12 | FX12_PI_11 = fx12(1171, 4096) |
|
constexpr fx12 | FX12_PI_12 = fx12(1072, 4096) |
|
constexpr fx12 | FX12_PI_13 = fx12(989, 4096) |
|
constexpr fx12 | FX12_PI_14 = fx12(919, 4096) |
|
constexpr fx12 | FX12_PI_15 = fx12(858, 4096) |
|
constexpr fx12 | FX12_PI_16 = fx12(804, 4096) |
|
Provides mathematical functions and utilities, primarily focused on fixed-point arithmetic.
This module offers a set of mathematical functions and utilities, including trigonometric calculations, fixed-point number operations, and random number generation using the Mersenne Twister algorithm. It is particularly useful in resource-constrained environments, such as embedded systems or game development.
The module includes:
- Trigonometric functions using a 12-bit angle representation
- Random number generation within a specified range for fixed-point numbers
- Mathematical constants like M_PI, M_E, etc.
- Utility functions for fixed-point arithmetic
- A structure for representing rectangles with fixed-point coordinates
Note: This module relies on fixed-point number representations using the fx8
and fx12
types.
Example usage:
#include <iostream>
int main() {
std::cout << "Random value: " << random_value << std::endl;
u32 angle = 1024;
std::cout << "sin(90 degrees): " << sin_result << std::endl;
std::cout << "cos(90 degrees): " << cos_result << std::endl;
return 0;
}
Provides mathematical functions and utilities, primarily focused on fixed-point arithmetic.
fx8 rad_sin_12(fx8 rad, u32 th)
Calculate the sine of an angle and scale a fixed-point value by it.
Definition submath.cpp:1052
fx8 genrand_min_max_fx8(fx8 min_, fx8 max_)
Generate a random fixed-point number within a specified range.
Definition submath.cpp:1060
fx8 rad_cos_12(fx8 rad, u32 th)
Calculate the cosine of an angle and scale a fixed-point value by it.
Definition submath.cpp:1044