diff --git a/include/zeus/Math.hpp b/include/zeus/Math.hpp index 9036a00..937efd8 100644 --- a/include/zeus/Math.hpp +++ b/include/zeus/Math.hpp @@ -6,6 +6,7 @@ #undef M_PI #define M_PI 3.14159265358979323846 /* pi */ +#define M_PIF 3.14159265358979323846f /* pi */ #undef M_PI_2 #define M_PI_2 1.57079632679489661923 /* pi/2 */ #undef M_PI_4 @@ -55,10 +56,10 @@ inline T max(T a, T b) { return a > b ? a : b; } template inline T clamp(T a, T val, T b) {return max(a, min(b, val));} -inline float radToDeg(float rad) {return rad * 180.f / M_PI;} -inline float degToRad(float deg) {return deg * M_PI / 180.f;} -inline double radToDeg(double rad) {return rad * 180.0 / M_PI;} -inline double degToRad(double deg) {return deg * M_PI / 180.0;} +inline float radToDeg(float rad) {return rad * (180.f / M_PIF);} +inline float degToRad(float deg) {return deg * (M_PIF / 180.f);} +inline double radToDeg(double rad) {return rad * (180.0 / M_PI);} +inline double degToRad(double deg) {return deg * (M_PI / 180.0);} CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary); diff --git a/src/CVector3f.cpp b/src/CVector3f.cpp index 3e85624..91d6667 100644 --- a/src/CVector3f.cpp +++ b/src/CVector3f.cpp @@ -11,8 +11,8 @@ const CVector3f CVector3f::skNegOne = CVector3f(-1.0); const CVector3f CVector3f::skZero; const CVector3f kUpVec(0.0, 0.0, 1.0); -const CVector3f kRadToDegVec(180.0f / M_PI); -const CVector3f kDegToRadVec(M_PI / 180.0f); +const CVector3f kRadToDegVec(180.0f / M_PIF); +const CVector3f kDegToRadVec(M_PIF / 180.0f); float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b) { diff --git a/src/Math.cpp b/src/Math.cpp index ad1bde8..200434b 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -160,7 +160,7 @@ float fastArcCosF(float val) * the approximation below won't provide any benefit, * and we simply fall back to the standard implementation */ - if (std::fabs(val) >= 0.925000011920929) + if (std::fabs(val) >= 0.925000011920929f) return std::acos(val); /* Fast Arc Cosine approximation using Taylor Polynomials @@ -215,47 +215,47 @@ int ceilingPowerOfTwo(int x) float fastCosF(float val) { - if (std::fabs(val) > M_PI) + if (std::fabs(val) > M_PIF) { float rVal = float(uint32_t(val)); - val = -((rVal * val) - 6.2831855); - if (val <= M_PI && val < -M_PI) - val += 6.2831855; + val = -((rVal * val) - 6.2831855f); + if (val <= M_PIF && val < -M_PIF) + val += 6.2831855f; else - val -= 6.2831855; + val -= 6.2831855f; } float sq = val * val; float b = sq * sq; - val = sq + -0.4999803; - val = (b * val) + 0.041620344; + val = sq + -0.4999803f; + val = (b * val) + 0.041620344f; b = b * sq; - val = (b * val) + -0.0013636103; + val = (b * val) + -0.0013636103f; b = b * sq; - val = (b * val) + 0.000020169435; + val = (b * val) + 0.000020169435f; return val; } float fastSinF(float val) { - if (std::fabs(val) > M_PI) + if (std::fabs(val) > M_PIF) { float rVal = float(uint32_t(val)); - val = -((rVal * val) - 6.2831855); - if (val <= M_PI && val < -M_PI) - val += 6.2831855; + val = -((rVal * val) - 6.2831855f); + if (val <= M_PIF && val < -M_PIF) + val += 6.2831855f; else - val -= 6.2831855; + val -= 6.2831855f; } float sq = val * val; - float ret = val * 0.99980587; + float ret = val * 0.99980587f; val = val * sq; - ret = (val * ret) + -0.16621658; + ret = (val * ret) + -0.16621658f; val = val * sq; - ret = (val * ret) + 0.0080871079; + ret = (val * ret) + 0.0080871079f; val = val * sq; - ret = (val * ret) + -0.00015297699; + ret = (val * ret) + -0.00015297699f; return ret; } @@ -263,7 +263,7 @@ float getCatmullRomSplinePoint(float a, float b, float c, float d, float t) { if (t <= 0.0f) return b; - if (t >= 1.0) + if (t >= 1.0f) return c; const float t2 = t * t; @@ -279,7 +279,7 @@ CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const { if (t <= 0.0f) return b; - if (t >= 1.0) + if (t >= 1.0f) return c; const float t2 = t * t;