diff --git a/maths.hpp b/maths.hpp index 1cbb37e9..9293fbcd 100644 --- a/maths.hpp +++ b/maths.hpp @@ -154,6 +154,13 @@ to_degrees (double radians) { return radians * 180 / PI; } +//----------------------------------------------------------------------------- +constexpr float +to_radians (float degrees) { + return degrees / 180 * static_cast (PI); +} + + constexpr double to_radians (double degrees) { return degrees / 180 * PI; diff --git a/test/maths/maths.cpp b/test/maths/maths.cpp index 4d70735f..69eb3c67 100644 --- a/test/maths/maths.cpp +++ b/test/maths/maths.cpp @@ -40,7 +40,8 @@ main (int, char **) { CHECK_EQ (sign (-numeric_limits::infinity ()), -1); CHECK_EQ (to_degrees (PI), 180); - CHECK_EQ (to_radians (180), PI); + CHECK_EQ (to_radians (180.f), PI); + CHECK_EQ (to_radians (180.0), PI); CHECK_EQ (log2 (8u), 3); CHECK_EQ (log2 (1u), 0);