Add pure annotation to simple maths and ntoh funcs
This commit is contained in:
parent
d6b943500c
commit
31796b34f6
@ -27,7 +27,7 @@
|
||||
template <typename T>
|
||||
T
|
||||
pow2 (T value)
|
||||
{ return value * value; }
|
||||
{ return value * value; }
|
||||
|
||||
template double pow2(double);
|
||||
template int pow2( int);
|
||||
@ -36,7 +36,7 @@ template int pow2( int);
|
||||
template <typename T>
|
||||
double
|
||||
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 ( int, int);
|
||||
@ -44,13 +44,13 @@ template double rootsquare ( int, int);
|
||||
|
||||
template <>
|
||||
bool
|
||||
almost_equal (float a, float b)
|
||||
almost_equal (const float &a, const float &b)
|
||||
{ return ieee_single::almost_equal (a, b); }
|
||||
|
||||
|
||||
template <>
|
||||
bool
|
||||
almost_equal (double a, double b)
|
||||
almost_equal (const double &a, const double &b)
|
||||
{ return ieee_double::almost_equal (a, b); }
|
||||
|
||||
|
||||
|
19
maths.hpp
19
maths.hpp
@ -20,15 +20,17 @@
|
||||
#ifndef __MATHS_HPP
|
||||
#define __MATHS_HPP
|
||||
|
||||
#include "annotations.hpp"
|
||||
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
pow2 (T value);
|
||||
pow2 (T value) pure;
|
||||
|
||||
|
||||
template <typename T>
|
||||
double
|
||||
rootsquare (T a, T b);
|
||||
rootsquare (T a, T b) pure;
|
||||
|
||||
|
||||
/**
|
||||
@ -40,13 +42,13 @@ rootsquare (T a, T b);
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
almost_equal (T a, T b)
|
||||
almost_equal (const T &a, const T &b)
|
||||
{ return a == b; }
|
||||
|
||||
|
||||
template <typename Ta, typename Tb>
|
||||
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),
|
||||
static_cast<decltype(a + b)>(b));
|
||||
}
|
||||
@ -54,19 +56,19 @@ almost_equal (Ta a, Tb b) {
|
||||
|
||||
template <>
|
||||
bool
|
||||
almost_equal (float a, float b);
|
||||
almost_equal (const float &a, const float &b);
|
||||
|
||||
|
||||
template <>
|
||||
bool
|
||||
almost_equal (double a, double b);
|
||||
almost_equal (const double &a, const double &b);
|
||||
|
||||
|
||||
/// Variadic minimum
|
||||
template <typename T>
|
||||
const T&
|
||||
min (const T &a)
|
||||
{ return a ; }
|
||||
{ return a; }
|
||||
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
@ -79,7 +81,7 @@ min (const T &a , const T &b , const Args &...args )
|
||||
template <typename T>
|
||||
const T&
|
||||
max (const T &a)
|
||||
{ return a ; }
|
||||
{ return a; }
|
||||
|
||||
|
||||
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...); }
|
||||
|
||||
|
||||
|
||||
#endif // __MATHS_HPP
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef __TYPES_HPP
|
||||
#define __TYPES_HPP
|
||||
|
||||
#include "annotations.hpp"
|
||||
#include "enable_if.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
@ -124,12 +125,12 @@ size_t elems(T (&)[N])
|
||||
|
||||
/// Convert a scalar from host byte order to network byte order
|
||||
template <typename T>
|
||||
T hton (T);
|
||||
T hton (T) pure;
|
||||
|
||||
|
||||
/// Convert a scalar from network byte order to host byte order
|
||||
template <typename T>
|
||||
T ntoh (T);
|
||||
T ntoh (T) pure;
|
||||
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
|
Loading…
Reference in New Issue
Block a user