9inline constexpr float pi = 3.14159265358979323846f;
11inline constexpr float internal_check(
float x,
float err,
float lower,
float upper)
noexcept {
14 assert(x + err >= lower && x - err <= upper);
15 return (x < lower) ? lower : ((x > upper) ? upper : x);
18inline float sin(
float x)
noexcept {
27 static const float coeffs[] = {
35 float pi_major = 3.1415927f;
36 float pi_minor = -0.00000008742278f;
38 float p11 = coeffs[5];
39 float p9 = p11 * x2 + coeffs[4];
40 float p7 = p9 * x2 + coeffs[3];
41 float p5 = p7 * x2 + coeffs[2];
42 float p3 = p5 * x2 + coeffs[1];
43 float p1 = p3 * x2 + coeffs[0];
44 float r = (x - pi_major - pi_minor) * (x + pi_major + pi_minor) * p1 * x;
48inline float cos(
float x)
noexcept {
53inline float acos(
float x)
noexcept {
56 constexpr float acos_input_err = 0.001f;
57 assert(x >= -1.f - acos_input_err && x <= 1.f + acos_input_err);
59 assert(x <= 1.f + acos_input_err);
61 }
else if(x <= -1.f) {
62 assert(x >= -1.f - acos_input_err);
65 float r = ((0.4643653210307f * x * x * x + 0.921784152891457f * x * x - 2.0178302343512f * x - 0.939115566365855f) * x + 1.5707963267949f) / ((0.295624144969963f * x * x - 1.28459062446908f) * (x * x) + 1.f);
66 assert((x >= 1.f) ? r == 0.f : r > 0.f);
70inline float sqrt(
float x)
noexcept {
75 u.i = 0x5f375a86 - (u.i >> 1);
76 u.f = u.f * (1.5f - (0.5f * x) * u.f * u.f);
77 u.f = u.f * (1.5f - (0.5f * x) * u.f * u.f);
#define assert(condition)
float cos(float x) noexcept
float sin(float x) noexcept
constexpr float internal_check(float x, float err, float lower, float upper) noexcept
float sqrt(float x) noexcept
float acos(float x) noexcept