From f309c5dbd0fc15daba92342a88b7a7345473ea6b Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 13 Jan 2015 18:32:30 +1100 Subject: [PATCH] maths: add float overload of to_radians --- maths.hpp | 7 +++++++ test/maths/maths.cpp | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) 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);