maths: comment sections

This commit is contained in:
Danny Robson 2015-01-21 23:35:08 +11:00
parent c02ad57660
commit d3c300053b

View File

@ -29,9 +29,11 @@ abs (T value)
{ return value > 0 ? value : -value; } { return value > 0 ? value : -value; }
//-----------------------------------------------------------------------------
// Exponentials
template <typename T> template <typename T>
constexpr T constexpr T
pow2 (T value) pow2 [[gnu::pure]] (T value)
{ return value * value; } { return value * value; }
@ -40,6 +42,8 @@ bool
is_pow2 [[gnu::pure]] (T value); is_pow2 [[gnu::pure]] (T value);
//-----------------------------------------------------------------------------
// Logarithms
template <typename T> template <typename T>
T T
log2 [[gnu::pure]] (T val); log2 [[gnu::pure]] (T val);
@ -50,11 +54,15 @@ T
log2up [[gnu::pure]] (T val); log2up [[gnu::pure]] (T val);
//-----------------------------------------------------------------------------
// Roots
template <typename T> template <typename T>
double double
rootsquare [[gnu::pure]] (T a, T b); rootsquare [[gnu::pure]] (T a, T b);
//-----------------------------------------------------------------------------
// Rounding
template <typename T, typename U> template <typename T, typename U>
typename std::common_type<T, U>::type typename std::common_type<T, U>::type
align [[gnu::pure]] (T value, U size); align [[gnu::pure]] (T value, U size);
@ -65,29 +73,33 @@ T
round_pow2 [[gnu::pure]] (T value); round_pow2 [[gnu::pure]] (T value);
template <typename T>
bool
is_integer [[gnu::pure]] (const T& value);
template <typename T>
unsigned
digits [[gnu::pure]] (const T& value);
template <typename T, typename U> template <typename T, typename U>
T T
divup (const T a, const U b) divup (const T a, const U b)
{ return (a + b - 1) / b; } { return (a + b - 1) / b; }
/** //-----------------------------------------------------------------------------
* Check if two floating point numbers are approximately equal. Returns true // Classification
* if the difference is less than a percentage of each individual value. template <typename T>
* bool
* @e maximum percentage difference for equal values is_integer [[gnu::pure]] (const T& value);
*/
//-----------------------------------------------------------------------------
// Properties
template <typename T>
unsigned
digits [[gnu::pure]] (const T& value);
//-----------------------------------------------------------------------------
template <typename T>
int sign (T val);
//-----------------------------------------------------------------------------
// Comparisons
template <typename T> template <typename T>
bool bool
almost_equal (const T &a, const T &b) almost_equal (const T &a, const T &b)
@ -149,6 +161,7 @@ exactly_zero (T a)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
constexpr double PI = 3.141592653589793238462643; constexpr double PI = 3.141592653589793238462643;
//-----------------------------------------------------------------------------
constexpr double constexpr double
to_degrees (double radians) { to_degrees (double radians) {
return radians * 180 / PI; return radians * 180 / PI;
@ -206,20 +219,18 @@ max (const T a, const U b, Args ...args)
return max (a > b ? a : b, std::forward<Args> (args)...); return max (a > b ? a : b, std::forward<Args> (args)...);
} }
//-----------------------------------------------------------------------------
template <typename T>
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)
{
return val > hi ? hi: return val > hi ? hi:
val < lo ? lo: val < lo ? lo:
std::move (val); std::move (val);
} }
#include "maths.ipp" #include "maths.ipp"
#endif // __MATHS_HPP #endif // __MATHS_HPP