Bladeren bron

Constexpr everything in fp_math

master
Ludovic 'Archivist' Lagouardette 3 jaren geleden
bovenliggende
commit
ddf7a07534
1 gewijzigde bestanden met toevoegingen van 13 en 13 verwijderingen
  1. +13
    -13
      include/gp/math/ieee754/fp_math.hpp

+ 13
- 13
include/gp/math/ieee754/fp_math.hpp Bestand weergeven

@ -20,7 +20,7 @@ namespace gp{
template<>
float abs<float>(float value) {
">constexpr float abs<float>(float value) {
static_assert(sizeof(float) == 4, "bad float size");
union {
float fp;
@ -32,7 +32,7 @@ namespace gp{
}
template<>
double abs<double>(double value) {
">constexpr double abs<double>(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>(float value) {
">constexpr float floor<float>(float value) {
static_assert(sizeof(float) == 4, "bad float size");
if(
value >= 16777216
@ -66,7 +66,7 @@ namespace gp{
}
template<>
double floor<double>(double value) {
">constexpr double floor<double>(double value) {
static_assert(sizeof(double) == 8, "bad double size");
if(
value >= 9007199254740992
@ -85,7 +85,7 @@ namespace gp{
}
template<>
float sign<float>(float value) {
">constexpr float sign<float>(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>(double value) {
">constexpr double sign<double>(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<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};
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<float>;
v = v - 2*pi<float>*floor(v/(2*pi<float>));
@ -158,7 +158,7 @@ namespace gp{
* @param v
* @return double
*/
inline double sin(double v) {
">constexpr inline double sin(double v) {
v += pi<double>;
v = v - 2*pi<double>*floor(v/(2*pi<double>));
v -= pi<double>;
@ -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<float>/2);
}
// TODO: replace with an actual implementation
inline double cos(double v) {
">constexpr inline double cos(double v) {
return sin(v+pi<double>/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);
}

Laden…
Annuleren
Opslaan