Commit fe410de2 authored by Davis King's avatar Davis King

Added is_finite()

parent 99109823
...@@ -67,6 +67,7 @@ namespace std ...@@ -67,6 +67,7 @@ namespace std
#include <algorithm> // for std::swap #include <algorithm> // for std::swap
#include <new> // for std::bad_alloc #include <new> // for std::bad_alloc
#include <cstdlib> #include <cstdlib>
#include <limits> // for std::numeric_limits for is_finite()
#include "assert.h" #include "assert.h"
#include "error.h" #include "error.h"
#include "noncopyable.h" #include "noncopyable.h"
...@@ -450,6 +451,26 @@ namespace dlib ...@@ -450,6 +451,26 @@ namespace dlib
template <> struct is_float_type<double> { const static bool value = true; }; template <> struct is_float_type<double> { const static bool value = true; };
template <> struct is_float_type<long double> { const static bool value = true; }; template <> struct is_float_type<long double> { const static bool value = true; };
// ----------------------------------------------------------------------------------------
template <
typename T
>
bool is_finite (
const T& value
)
/*!
ensures
- returns true if value is a finite value (e.g. not infinity or NaN) and false
otherwise.
!*/
{
if (is_float_type<T>::value)
return -std::numeric_limits<T>::infinity() < value && value < std::numeric_limits<T>::infinity();
else
return true;
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
/*!A is_convertible /*!A is_convertible
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment