2020-11-26 09:26:35 -06:00
|
|
|
#ifndef TEMPEST_MATH_C_MATH_HPP
|
|
|
|
|
#define TEMPEST_MATH_C_MATH_HPP
|
|
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <storm/Error.hpp>
|
|
|
|
|
|
|
|
|
|
class CMath {
|
|
|
|
|
public:
|
|
|
|
|
// Static variables
|
|
|
|
|
static constexpr float PI = 3.1415927f;
|
|
|
|
|
static constexpr float TWO_PI = 6.2831855f;
|
|
|
|
|
static constexpr float OO_TWO_PI = 1.0f / TWO_PI;
|
|
|
|
|
|
|
|
|
|
// Static functions
|
2022-12-26 14:11:24 -06:00
|
|
|
static int32_t fint(float n) {
|
|
|
|
|
return static_cast<int32_t>(n);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-26 14:13:25 -06:00
|
|
|
static int32_t fint_n(float n) {
|
|
|
|
|
return n <= 0.0f ? static_cast<int32_t>(n - 0.5f) : static_cast<int32_t>(n + 0.5f);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 09:26:35 -06:00
|
|
|
static uint32_t fuint(float n) {
|
|
|
|
|
return static_cast<uint32_t>(n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t fuint_n(float n) {
|
|
|
|
|
return static_cast<uint32_t>(n + 0.5f);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-26 14:15:57 -06:00
|
|
|
static uint32_t fuint_pi(float n) {
|
|
|
|
|
return static_cast<uint32_t>(n + 0.99994999);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 09:26:35 -06:00
|
|
|
static float sqrt(float x) {
|
|
|
|
|
STORM_ASSERT(x >= 0.0f);
|
|
|
|
|
return ::sqrt(x);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|