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