maths: add constexpr to min,max,to_{radian,degree}

This commit is contained in:
Danny Robson 2015-01-13 18:32:01 +11:00
parent 9e18b9b57a
commit a691f3b748

View File

@ -146,49 +146,54 @@ exactly_zero (T a)
{ return exactly_equal (a, static_cast<T> (0)); } { return exactly_equal (a, static_cast<T> (0)); }
const double PI = 3.141592653589793238462643; //-----------------------------------------------------------------------------
constexpr double PI = 3.141592653589793238462643;
inline double constexpr double
to_degrees (double radians) { to_degrees (double radians) {
return radians * 180 / PI; return radians * 180 / PI;
} }
inline double constexpr double
to_radians (double degrees) { to_radians (double degrees) {
return degrees / 180 * PI; return degrees / 180 * PI;
} }
//-----------------------------------------------------------------------------
/// Variadic minimum /// Variadic minimum
template <typename T> template <typename T>
const T& constexpr T
min (const T &a) min (const T a)
{ return a; } { return a; }
template <typename T, typename U, typename ...Args> template <typename T, typename U, typename ...Args>
typename std::common_type<T, U>::type constexpr typename std::common_type<T, U>::type
min (const T a , const U b , const Args &...args ) min (const T a , const U b , const Args &...args )
{ return min ( b < a ? b : a, args...); } { return min ( b < a ? b : a, args...); }
//-----------------------------------------------------------------------------
/// Variadic maximum /// Variadic maximum
template <typename T> template <typename T>
const T& constexpr T
max (const T &a) max (const T a)
{ return a; } { return a; }
template <typename T, typename ...Args> template <typename T, typename ...Args>
const T& constexpr T
max (const T &a , const T &b , const Args &...args ) max (const T a , const T b , const Args &...args )
{ return max ( b > a ? b : a, args...); } { return max ( b > a ? b : a, args...); }
//-----------------------------------------------------------------------------
template <typename T> template <typename T>
int sign (T val); int sign (T val);
//-----------------------------------------------------------------------------
template <typename T, typename U, typename V> template <typename T, typename U, typename V>
T T
limit (const T &&val, const U &&hi, const V &&lo) { limit (const T &&val, const U &&hi, const V &&lo) {