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 
00022 template<typename eT>
00023 arma_inline
00024 bool
00025 arma_isfinite(eT val)
00026   {
00027   return true;
00028   }
00029 
00030 
00031 
00032 template<>
00033 arma_inline
00034 bool
00035 arma_isfinite(float x)
00036   {
00037   #if defined(ARMA_HAVE_STD_ISFINITE)
00038     {
00039     return (std::isfinite(x) != 0);
00040     }
00041   #else
00042     {
00043     const bool x_is_inf = ( (x == x) && ((x - x) != float(0)) );
00044     const bool x_is_nan = (x != x);
00045 
00046     return ( (x_is_inf == false) && (x_is_nan == false) );
00047     }
00048   #endif
00049   }
00050 
00051 
00052 
00053 template<>
00054 arma_inline
00055 bool
00056 arma_isfinite(double x)
00057   {
00058   #if defined(ARMA_HAVE_STD_ISFINITE)
00059     {
00060     return (std::isfinite(x) != 0);
00061     }
00062   #else
00063     {
00064     const bool x_is_inf = ( (x == x) && ((x - x) != double(0)) );
00065     const bool x_is_nan = (x != x);
00066 
00067     return ( (x_is_inf == false) && (x_is_nan == false) );
00068     }
00069   #endif
00070   }
00071 
00072 
00073 
00074 template<typename T>
00075 arma_inline
00076 bool
00077 arma_isfinite(const std::complex<T>& x)
00078   {
00079   if( (arma_isfinite(x.real()) == false) || (arma_isfinite(x.imag()) == false) )
00080     {
00081     return false;
00082     }
00083   else
00084     {
00085     return true;
00086     }
00087   }
00088 
00089 
00090 
00091 //! @}