BLT/include/blt/math/math.h

55 lines
1.5 KiB
C
Raw Normal View History

2023-01-10 10:45:11 -05:00
/*
* Created by Brett on 09/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_MATH_H
#define BLT_MATH_H
#include <blt/math/vectors.h>
#include <blt/math/matrix.h>
2023-02-07 22:34:10 -05:00
2023-01-10 10:45:11 -05:00
namespace blt {
2023-03-14 17:30:22 -04:00
constexpr float EPSILON = 0.0001f;
static inline constexpr bool f_equal(float v1, float v2) {
return v1 >= v2 - EPSILON && v1 <= v2 + EPSILON;
}
/**
* fast number integer
*/
2023-03-01 00:05:26 -05:00
static inline unsigned int f_randi(unsigned int seed) {
seed = (seed << 13) ^ seed;
return ((seed * (seed * seed * 15731 + 789221) + 1376312589) & 0x7fffffff);
}
/**
* fast inverse sqrt
*/
2023-03-01 00:05:26 -05:00
static inline float fsqrt(float n){
int i;
float x, y;
x = n * 0.5f;
y = n;
i = * (int*) &y;
i = 0x5f3759df - (i >> 1);
y = * (float*) &i;
y = y * (1.5f - (x * y * y));
y = y * (1.5f - (x * y * y));
return y;
}
2023-01-10 10:45:11 -05:00
2023-02-07 22:34:10 -05:00
// inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) {
// return out << "\rMatrix4x4{" << v.m00() << ", " << v.m01() << ", " << v.m02() << ", " << v.m03() << "} \n"\
// << " {" << v.m10() << ", " << v.m11() << ", " << v.m12() << ", " << v.m13() << "} \n"\
// << " {" << v.m20() << ", " << v.m21() << ", " << v.m22() << ", " << v.m23() << "} \n"\
// << " {" << v.m30() << ", " << v.m31() << ", " << v.m32() << ", " << v.m33() << "} \n";
// }
2023-01-10 10:45:11 -05:00
}
#endif //BLT_MATH_H