maths: seperate float and double PI

This commit is contained in:
Danny Robson 2015-01-21 23:39:23 +11:00
parent 1b19dadd40
commit 0a2d163bb1
3 changed files with 21 additions and 8 deletions

View File

@ -45,7 +45,7 @@ lerp::linear (double a, double b, double weight) {
double double
lerp::cosine (double a, double b, double weight) { lerp::cosine (double a, double b, double weight) {
CHECK (weight >= 0.0 && weight <= 1.0); 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; return a * (1.0 - t) + b * t;
} }

View File

@ -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 constexpr double
to_degrees (double radians) { 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 constexpr float
to_radians (float degrees) { to_radians (float degrees) {
return degrees / 180 * static_cast<float> (PI); return degrees / 180 * static_cast<float> (PI_f);
} }
constexpr double constexpr double
to_radians (double degrees) { to_radians (double degrees) {
return degrees / 180 * PI; return degrees / 180 * PI_d;
} }

View File

@ -10,6 +10,9 @@ using std::numeric_limits;
int int
main (int, char **) { main (int, char **) {
std::cerr.precision (15);
std::cout.precision (15);
CHECK_HARD (!almost_equal (-2.0, 0.0)); CHECK_HARD (!almost_equal (-2.0, 0.0));
CHECK_HARD (!almost_equal (-2.f, 0.f)); CHECK_HARD (!almost_equal (-2.f, 0.f));
CHECK_HARD ( almost_equal ( 0.0, 0.0)); 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 (sign (-numeric_limits<double>::infinity ()), -1); CHECK_EQ (sign (-numeric_limits<double>::infinity ()), -1);
CHECK_EQ (to_degrees (PI), 180); CHECK_EQ (to_degrees (PI_d), 180.0);
CHECK_EQ (to_radians (180.f), PI); CHECK_EQ (to_degrees (PI_f), 180.f);
CHECK_EQ (to_radians (180.0), PI); CHECK_EQ (to_radians (180.f), PI_f);
CHECK_EQ (to_radians (180.0), PI_d);
CHECK_EQ (log2 (8u), 3); CHECK_EQ (log2 (8u), 3);
CHECK_EQ (log2 (1u), 0); CHECK_EQ (log2 (1u), 0);