00001 00030 #ifndef MISC_H 00031 #define MISC_H 00032 00033 #ifndef _MSC_VER 00034 # include <itpp/config.h> 00035 #else 00036 # include <itpp/config_msvc.h> 00037 #endif 00038 00039 #include <complex> 00040 #include <string> 00041 #include <limits> 00042 00043 00044 namespace std 00045 { 00046 00048 00049 #ifndef HAVE_STD_ISINF 00050 #if (HAVE_DECL_ISINF == 1) || defined(HAVE_ISINF) 00051 inline int isinf(double x) { return ::isinf(x); } 00052 #elif defined(FPCLASS) 00053 inline int isinf(double x) 00054 { 00055 if (::fpclass(a) == FP_NINF) return -1; 00056 else if (::fpclass(a) == FP_PINF) return 1; 00057 else return 0; 00058 } 00059 #else 00060 inline int isinf(double x) 00061 { 00062 if ((x == x) && ((x - x) != 0.0)) return (x < 0.0 ? -1 : 1); 00063 else return 0; 00064 } 00065 #endif // #if (HAVE_DECL_ISINF == 1) || defined(HAVE_ISINF) 00066 # define HAVE_STD_ISINF 1 00067 #endif // #ifndef HAVE_STD_ISINF 00068 00069 #ifndef HAVE_STD_ISNAN 00070 #if (HAVE_DECL_ISNAN == 1) || defined(HAVE_ISNAN) 00071 inline int isnan(double x) { return ::isnan(x); } 00072 #else 00073 inline int isnan(double x) { return ((x != x) ? 1 : 0); } 00074 #endif // #if (HAVE_DECL_ISNAN == 1) || defined(HAVE_ISNAN) 00075 # define HAVE_STD_ISNAN 1 00076 #endif // #ifndef HAVE_STD_ISNAN 00077 00078 #ifndef HAVE_STD_ISFINITE 00079 #if (HAVE_DECL_ISFINITE == 1) || defined(HAVE_ISFINITE) 00080 inline int isfinite(double x) { return ::isfinite(x); } 00081 #elif defined(HAVE_FINITE) 00082 inline int isfinite(double x) { return ::finite(x); } 00083 #else 00084 inline int isfinite(double x) 00085 { 00086 return ((!std::isnan(x) && !std::isinf(x)) ? 1 : 0); 00087 } 00088 #endif // #if (HAVE_DECL_ISFINITE == 1) || defined(HAVE_ISFINITE) 00089 # define HAVE_STD_ISFINITE 1 00090 #endif // #ifndef HAVE_STD_ISFINITE 00091 00093 00095 template <class T> 00096 std::ostream& operator<<(std::ostream &os, const std::complex<T> &x) 00097 { 00098 os << x.real(); 00099 ios::fmtflags saved_format = os.setf(ios::showpos); 00100 os << x.imag(); 00101 os.setf(saved_format, ios::showpos); 00102 return os << 'i'; 00103 } 00104 00106 template <class T> 00107 std::istream& operator>>(std::istream &is, std::complex<T> &x) 00108 { 00109 T re, im; 00110 char c; 00111 is >> c; 00112 if (c == '(') { 00113 is >> re >> c; 00114 if (c == ',') { 00115 is >> im >> c; 00116 if (c == ')') { 00117 x = complex<T>(re, im); 00118 } 00119 else { 00120 is.setstate(ios_base::failbit); 00121 } 00122 } 00123 else if (c == ')') { 00124 x = complex<T>(re, T(0)); 00125 } 00126 else { 00127 is.setstate(ios_base::failbit); 00128 } 00129 } 00130 else { 00131 is.putback(c); 00132 is >> re; 00133 if (!is.eof() && ((c = static_cast<char>(is.peek())) == '+' || c == '-')) { 00134 is >> im >> c; 00135 if (c == 'i') { 00136 x = complex<T>(re, im); 00137 } 00138 else { 00139 is.setstate(ios_base::failbit); 00140 } 00141 } 00142 else { 00143 x = complex<T>(re, T(0)); 00144 } 00145 } 00146 return is; 00147 } 00148 00149 } // namespace std 00150 00151 00153 namespace itpp 00154 { 00155 00157 const double pi = 3.14159265358979323846; 00158 00160 const double m_2pi = 2 * pi; 00161 00163 const double eps = std::numeric_limits<double>::epsilon(); 00164 00167 00169 inline bool is_int(double x) 00170 { 00171 double dummy; 00172 return (modf(x, &dummy) == 0.0); 00173 } 00174 00176 inline bool is_even(int x) { return ((x&1) == 0); } 00177 00178 00180 std::string itpp_version(); 00181 00182 00184 bool check_big_endianness(); 00185 00187 00188 } //namespace itpp 00189 00190 00191 #endif // #ifndef MISC_H
Generated on Thu Apr 23 20:06:40 2009 for IT++ by Doxygen 1.5.8