maths: seperate float and double PI
This commit is contained in:
parent
1b19dadd40
commit
0a2d163bb1
2
lerp.cpp
2
lerp.cpp
@ -45,7 +45,7 @@ lerp::linear (double a, double b, double weight) {
|
||||
double
|
||||
lerp::cosine (double a, double b, double weight) {
|
||||
CHECK (weight >= 0.0 && weight <= 1.0);
|
||||
double t = (1.0 - cos (weight * PI)) * 0.5;
|
||||
double t = (1.0 - cos (weight * PI_d)) * 0.5;
|
||||
|
||||
return a * (1.0 - t) + b * t;
|
||||
}
|
||||
|
17
maths.hpp
17
maths.hpp
@ -164,24 +164,33 @@ exactly_zero (T a)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
constexpr double PI = 3.141592653589793238462643;
|
||||
// angles, trig
|
||||
constexpr double PI_d = 3.141592653589793238462643;
|
||||
constexpr float PI_f = 3.141592653589793238462643f;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
constexpr double
|
||||
to_degrees (double radians) {
|
||||
return radians * 180 / PI;
|
||||
return radians * 180 / PI_d;
|
||||
}
|
||||
|
||||
|
||||
constexpr float
|
||||
to_degrees (float radians) {
|
||||
return radians * 180 / PI_f;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
constexpr float
|
||||
to_radians (float degrees) {
|
||||
return degrees / 180 * static_cast<float> (PI);
|
||||
return degrees / 180 * static_cast<float> (PI_f);
|
||||
}
|
||||
|
||||
|
||||
constexpr double
|
||||
to_radians (double degrees) {
|
||||
return degrees / 180 * PI;
|
||||
return degrees / 180 * PI_d;
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,6 +10,9 @@ using std::numeric_limits;
|
||||
|
||||
int
|
||||
main (int, char **) {
|
||||
std::cerr.precision (15);
|
||||
std::cout.precision (15);
|
||||
|
||||
CHECK_HARD (!almost_equal (-2.0, 0.0));
|
||||
CHECK_HARD (!almost_equal (-2.f, 0.f));
|
||||
CHECK_HARD ( almost_equal ( 0.0, 0.0));
|
||||
@ -39,9 +42,10 @@ main (int, char **) {
|
||||
CHECK_EQ (sign ( numeric_limits<double>::infinity ()), 1);
|
||||
CHECK_EQ (sign (-numeric_limits<double>::infinity ()), -1);
|
||||
|
||||
CHECK_EQ (to_degrees (PI), 180);
|
||||
CHECK_EQ (to_radians (180.f), PI);
|
||||
CHECK_EQ (to_radians (180.0), PI);
|
||||
CHECK_EQ (to_degrees (PI_d), 180.0);
|
||||
CHECK_EQ (to_degrees (PI_f), 180.f);
|
||||
CHECK_EQ (to_radians (180.f), PI_f);
|
||||
CHECK_EQ (to_radians (180.0), PI_d);
|
||||
|
||||
CHECK_EQ (log2 (8u), 3);
|
||||
CHECK_EQ (log2 (1u), 0);
|
||||
|
Loading…
Reference in New Issue
Block a user