cmath_wrap.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 
00018 //! \addtogroup cmath_wrap
00019 //! @{
00020 
00021 
00022 
00023 template<typename eT>
00024 arma_inline
00025 bool
00026 arma_isfinite(eT val)
00027   {
00028   return true;
00029   }
00030 
00031 
00032 
00033 template<>
00034 arma_inline
00035 bool
00036 arma_isfinite(float x)
00037   {
00038   #if defined(ARMA_HAVE_STD_ISFINITE)
00039     {
00040     return (std::isfinite(x) != 0);
00041     }
00042   #else
00043     {
00044     const bool x_is_inf = ( (x == x) && ((x - x) != float(0)) );
00045     const bool x_is_nan = (x != x);
00046 
00047     return ( (x_is_inf == false) && (x_is_nan == false) );
00048     }
00049   #endif
00050   }
00051 
00052 
00053 
00054 template<>
00055 arma_inline
00056 bool
00057 arma_isfinite(double x)
00058   {
00059   #if defined(ARMA_HAVE_STD_ISFINITE)
00060     {
00061     return (std::isfinite(x) != 0);
00062     }
00063   #else
00064     {
00065     const bool x_is_inf = ( (x == x) && ((x - x) != double(0)) );
00066     const bool x_is_nan = (x != x);
00067 
00068     return ( (x_is_inf == false) && (x_is_nan == false) );
00069     }
00070   #endif
00071   }
00072 
00073 
00074 
00075 template<typename T>
00076 arma_inline
00077 bool
00078 arma_isfinite(const std::complex<T>& x)
00079   {
00080   if( (arma_isfinite(x.real()) == false) || (arma_isfinite(x.imag()) == false) )
00081     {
00082     return false;
00083     }
00084   else
00085     {
00086     return true;
00087     }
00088   }
00089 
00090 
00091 
00092 //! @}