Add pure annotation to simple maths and ntoh funcs

This commit is contained in:
Danny Robson 2011-07-16 15:53:53 +10:00
parent d6b943500c
commit 31796b34f6
3 changed files with 17 additions and 15 deletions

View File

@ -27,7 +27,7 @@
template <typename T> template <typename T>
T T
pow2 (T value) pow2 (T value)
{ return value * value; } { return value * value; }
template double pow2(double); template double pow2(double);
template int pow2( int); template int pow2( int);
@ -36,7 +36,7 @@ template int pow2( int);
template <typename T> template <typename T>
double double
rootsquare (T a, T b) rootsquare (T a, T b)
{ return sqrt (pow2 (a) + pow2 (b)); } { return sqrt (pow2 (a) + pow2 (b)); }
template double rootsquare (double, double); template double rootsquare (double, double);
template double rootsquare ( int, int); template double rootsquare ( int, int);
@ -44,13 +44,13 @@ template double rootsquare ( int, int);
template <> template <>
bool bool
almost_equal (float a, float b) almost_equal (const float &a, const float &b)
{ return ieee_single::almost_equal (a, b); } { return ieee_single::almost_equal (a, b); }
template <> template <>
bool bool
almost_equal (double a, double b) almost_equal (const double &a, const double &b)
{ return ieee_double::almost_equal (a, b); } { return ieee_double::almost_equal (a, b); }

View File

@ -20,15 +20,17 @@
#ifndef __MATHS_HPP #ifndef __MATHS_HPP
#define __MATHS_HPP #define __MATHS_HPP
#include "annotations.hpp"
template <typename T> template <typename T>
T T
pow2 (T value); pow2 (T value) pure;
template <typename T> template <typename T>
double double
rootsquare (T a, T b); rootsquare (T a, T b) pure;
/** /**
@ -40,13 +42,13 @@ rootsquare (T a, T b);
template <typename T> template <typename T>
bool bool
almost_equal (T a, T b) almost_equal (const T &a, const T &b)
{ return a == b; } { return a == b; }
template <typename Ta, typename Tb> template <typename Ta, typename Tb>
bool bool
almost_equal (Ta a, Tb b) { almost_equal (const Ta &a, const Tb &b) {
return almost_equal <decltype(a + b)> (static_cast<decltype(a + b)>(a), return almost_equal <decltype(a + b)> (static_cast<decltype(a + b)>(a),
static_cast<decltype(a + b)>(b)); static_cast<decltype(a + b)>(b));
} }
@ -54,19 +56,19 @@ almost_equal (Ta a, Tb b) {
template <> template <>
bool bool
almost_equal (float a, float b); almost_equal (const float &a, const float &b);
template <> template <>
bool bool
almost_equal (double a, double b); almost_equal (const double &a, const double &b);
/// Variadic minimum /// Variadic minimum
template <typename T> template <typename T>
const T& const T&
min (const T &a) min (const T &a)
{ return a ; } { return a; }
template <typename T, typename ...Args> template <typename T, typename ...Args>
@ -79,7 +81,7 @@ min (const T &a , const T &b , const Args &...args )
template <typename T> template <typename T>
const T& const T&
max (const T &a) max (const T &a)
{ return a ; } { return a; }
template <typename T, typename ...Args> template <typename T, typename ...Args>
@ -88,5 +90,4 @@ max (const T &a , const T &b , const Args &...args )
{ return max ( b > a ? b : a, args...); } { return max ( b > a ? b : a, args...); }
#endif // __MATHS_HPP #endif // __MATHS_HPP

View File

@ -1,6 +1,7 @@
#ifndef __TYPES_HPP #ifndef __TYPES_HPP
#define __TYPES_HPP #define __TYPES_HPP
#include "annotations.hpp"
#include "enable_if.hpp" #include "enable_if.hpp"
#include <cstdint> #include <cstdint>
@ -124,12 +125,12 @@ size_t elems(T (&)[N])
/// Convert a scalar from host byte order to network byte order /// Convert a scalar from host byte order to network byte order
template <typename T> template <typename T>
T hton (T); T hton (T) pure;
/// Convert a scalar from network byte order to host byte order /// Convert a scalar from network byte order to host byte order
template <typename T> template <typename T>
T ntoh (T); T ntoh (T) pure;
template <typename T, typename ...Args> template <typename T, typename ...Args>