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 00047 template <class T> 00048 std::ostream& operator<<(std::ostream &os, const std::complex<T> &x) 00049 { 00050 os << x.real(); 00051 ios::fmtflags saved_format = os.setf(ios::showpos); 00052 os << x.imag(); 00053 os.setf(saved_format, ios::showpos); 00054 return os << 'i'; 00055 } 00056 00058 template <class T> 00059 std::istream& operator>>(std::istream &is, std::complex<T> &x) 00060 { 00061 T re, im; 00062 char c; 00063 is >> c; 00064 if (c == '(') { 00065 is >> re >> c; 00066 if (c == ',') { 00067 is >> im >> c; 00068 if (c == ')') { 00069 x = complex<T>(re, im); 00070 } else { 00071 is.setstate(ios_base::failbit); 00072 } 00073 } else if (c == ')') { 00074 x = complex<T>(re, T(0)); 00075 } else { 00076 is.setstate(ios_base::failbit); 00077 } 00078 } else { 00079 is.putback(c); 00080 is >> re; 00081 if (!is.eof() && ((c = is.peek()) == '+' || c == '-')) { 00082 is >> im >> c; 00083 if (c == 'i') { 00084 x = complex<T>(re, im); 00085 } else { 00086 is.setstate(ios_base::failbit); 00087 } 00088 } else { 00089 x = complex<T>(re, T(0)); 00090 } 00091 } 00092 return is; 00093 } 00094 00095 } // namespace std 00096 00097 00098 namespace itpp { 00099 00101 const double pi = 3.14159265358979323846; 00102 00104 const double m_2pi = 2 * pi; 00105 00107 const double eps = std::numeric_limits<double>::epsilon(); 00108 00111 00113 inline bool is_int(double x) 00114 { 00115 double dummy; 00116 return (modf(x, &dummy) == 0.0); 00117 } 00118 00120 inline bool is_even(int x) { return ((x&1) == 0); } 00121 00122 00124 std::string itpp_version(); 00125 00126 00128 bool check_big_endianness(); 00129 00131 00132 } //namespace itpp 00133 00134 00137 00138 #ifndef HAVE_ISNAN 00139 00143 inline int isnan(double x) 00144 { 00145 if (x != x) return 1; 00146 else return 0; 00147 } 00148 #endif 00149 00150 #ifndef HAVE_ISINF 00151 00158 inline int isinf(double x) 00159 { 00160 if ((x == x) && ((x - x) != 0.0)) 00161 return (x < 0.0 ? -1 : 1); 00162 else return 0; 00163 } 00164 #endif 00165 00166 #ifndef HAVE_FINITE 00167 00171 inline int finite(double x) 00172 { 00173 if (!isnan(x) && !isinf(x)) return 1; 00174 else return 0; 00175 } 00176 #endif 00177 00178 #ifndef HAVE_ISFINITE 00179 00183 inline int isfinite(double x) { return finite(x); } 00184 #endif 00185 00187 00188 00189 #endif // #ifndef MISC_H
Generated on Sun Sep 14 18:54:52 2008 for IT++ by Doxygen 1.5.6