diff --git a/include/gp/math/ieee754/fp_math.hpp b/include/gp/math/ieee754/fp_math.hpp index 3a0b50b..2ca5a6f 100644 --- a/include/gp/math/ieee754/fp_math.hpp +++ b/include/gp/math/ieee754/fp_math.hpp @@ -20,7 +20,7 @@ namespace gp{ template<> - float abs(float value) { + constexpr float abs(float value) { static_assert(sizeof(float) == 4, "bad float size"); union { float fp; @@ -32,7 +32,7 @@ namespace gp{ } template<> - double abs(double value) { + constexpr double abs(double value) { static_assert(sizeof(double) == 8, "bad double size"); union { double fp; @@ -47,7 +47,7 @@ namespace gp{ T floor(T); template<> - float floor(float value) { + constexpr float floor(float value) { static_assert(sizeof(float) == 4, "bad float size"); if( value >= 16777216 @@ -66,7 +66,7 @@ namespace gp{ } template<> - double floor(double value) { + constexpr double floor(double value) { static_assert(sizeof(double) == 8, "bad double size"); if( value >= 9007199254740992 @@ -85,7 +85,7 @@ namespace gp{ } template<> - float sign(float value) { + constexpr float sign(float value) { static_assert(sizeof(float) == 4, "bad float size"); if(!value) return 0; union { @@ -98,7 +98,7 @@ namespace gp{ } template<> - double sign(double value) { + constexpr double sign(double value) { static_assert(sizeof(double) == 8, "bad double size"); if(!value) return 0; union { @@ -121,7 +121,7 @@ namespace gp{ * @return T the sin of the value (the sign may be off idk I don't remember) */ template - T sin_taylor(T value) { + constexpr T sin_taylor(T value) { const T acc = T{1}/T{accuracy}; T B = value; T C = 1; @@ -140,7 +140,7 @@ namespace gp{ * @param v * @return float */ - inline float sin(float v) { + constexpr inline float sin(float v) { // limit the range between -pi and +pi v += pi; v = v - 2*pi*floor(v/(2*pi)); @@ -158,7 +158,7 @@ namespace gp{ * @param v * @return double */ - inline double sin(double v) { + constexpr inline double sin(double v) { v += pi; v = v - 2*pi*floor(v/(2*pi)); v -= pi; @@ -169,22 +169,22 @@ namespace gp{ // TODO: replace with an actual implementation - inline float cos(float v) { + constexpr inline float cos(float v) { return sin(v+pi/2); } // TODO: replace with an actual implementation - inline double cos(double v) { + constexpr inline double cos(double v) { return sin(v+pi/2); } // TODO: replace with an actual implementation - inline float tan(float v) { + constexpr inline float tan(float v) { return sin(v)/cos(v); } // TODO: replace with an actual implementation - inline double tan(double v) { + constexpr inline double tan(double v) { return sin(v)/cos(v); }