IT++ Logo
misc.h
Go to the documentation of this file.
00001 
00029 #ifndef MISC_H
00030 #define MISC_H
00031 
00032 #include <complex>
00033 #include <string>
00034 #include <limits>
00035 
00036 
00037 namespace std
00038 {
00039 
00041 template <class T>
00042 std::ostream& operator<<(std::ostream &os, const std::complex<T> &x)
00043 {
00044   os << x.real();
00045   ios::fmtflags saved_format = os.setf(ios::showpos);
00046   os << x.imag();
00047   os.setf(saved_format, ios::showpos);
00048   return os << 'i';
00049 }
00050 
00052 template <class T>
00053 std::istream& operator>>(std::istream &is, std::complex<T> &x)
00054 {
00055   T re, im;
00056   char c;
00057   is >> c;
00058   if (c == '(') {
00059     is >> re >> c;
00060     if (c == ',') {
00061       is >> im >> c;
00062       if (c == ')') {
00063         x = complex<T>(re, im);
00064       }
00065       else {
00066         is.setstate(ios_base::failbit);
00067       }
00068     }
00069     else if (c == ')') {
00070       x = complex<T>(re, T(0));
00071     }
00072     else {
00073       is.setstate(ios_base::failbit);
00074     }
00075   }
00076   else {
00077     is.putback(c);
00078     is >> re;
00079     if (!is.eof() && ((c = static_cast<char>(is.peek())) == '+' || c == '-')) {
00080       is >> im >> c;
00081       if (c == 'i') {
00082         x = complex<T>(re, im);
00083       }
00084       else {
00085         is.setstate(ios_base::failbit);
00086       }
00087     }
00088     else {
00089       x = complex<T>(re, T(0));
00090     }
00091   }
00092   return is;
00093 }
00094 
00095 } // namespace std
00096 
00097 
00099 namespace itpp
00100 {
00101 
00103 const double pi = 3.14159265358979323846;
00104 
00106 const double m_2pi = 2 * pi;
00107 
00109 const double eps = std::numeric_limits<double>::epsilon();
00110 
00113 
00115 inline bool is_int(double x)
00116 {
00117   double dummy;
00118   return (modf(x, &dummy) == 0.0);
00119 }
00120 
00122 inline bool is_even(int x) { return ((x&1) == 0); }
00123 
00125 std::string itpp_version();
00126 
00128 bool is_bigendian();
00129 
00131 inline bool check_big_endianness() { return is_bigendian(); }
00132 
00134 
00135 } //namespace itpp
00136 
00137 
00138 #endif // #ifndef MISC_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceForge Logo

Generated on Wed Jul 27 2011 16:27:04 for IT++ by Doxygen 1.7.4