cmath_wrap.hpp

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