math rads

v1
Brett 2023-12-29 19:32:16 -05:00
parent cc64e71c8d
commit 13f82dfc2f
2 changed files with 23 additions and 8 deletions

View File

@ -10,22 +10,35 @@
#include <blt/math/vectors.h>
#include <blt/math/matrix.h>
namespace blt {
namespace blt
{
static inline constexpr double PI = 3.141592653589793238462643383279502884197;
template<typename T>
static inline T toRadians(T deg)
{
constexpr double CONV = PI / 180.0;
return deg * CONV;
}
/**
* fast number integer
*/
static inline unsigned int f_randi(unsigned int seed) {
static inline unsigned int f_randi(unsigned int seed)
{
seed = (seed << 13) ^ seed;
return ((seed * (seed * seed * 15731 + 789221) + 1376312589) & 0x7fffffff);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
/**
* fast inverse sqrt
*/
static inline float fsqrt(float n){
static inline float fsqrt(float n)
{
int i;
float x, y;
x = n * 0.5f;
@ -41,7 +54,8 @@ namespace blt {
#pragma GCC diagnostic pop
static inline constexpr double pow(int b, int p) {
static inline constexpr double pow(int b, int p)
{
int collection = 1;
for (int i = 0; i < p; i++)
collection *= b;
@ -55,7 +69,8 @@ namespace blt {
* @return
*/
template<int decimal_places>
static inline double round_up(double value) {
static inline double round_up(double value)
{
constexpr double multiplier = pow(10, decimal_places);
return ((int) (value * multiplier) + 1) / multiplier;
}

@ -1 +1 @@
Subproject commit 401552da80b0971f818e648621260720ad40934e
Subproject commit 946ebad67a21212d11a0dd4deb7cdedc297d47bc