IT++ Logo
misc.h
Go to the documentation of this file.
1
29#ifndef MISC_H
30#define MISC_H
31
32#include <complex>
33#include <string>
34#include <limits>
35#include <itpp/itexports.h>
36
37namespace std
38{
39
41template <class T>
42std::ostream& operator<<(std::ostream &os, const std::complex<T> &x)
43{
44 os << x.real();
45 ios::fmtflags saved_format = os.setf(ios::showpos);
46 os << x.imag();
47 os.setf(saved_format, ios::showpos);
48 return os << 'i';
49}
50
52template <class T>
53std::istream& operator>>(std::istream &is, std::complex<T> &x)
54{
55 T re, im;
56 char c;
57 is >> c;
58 if (c == '(') {
59 is >> re >> c;
60 if (c == ',') {
61 is >> im >> c;
62 if (c == ')') {
63 x = complex<T>(re, im);
64 }
65 else {
66 is.setstate(ios_base::failbit);
67 }
68 }
69 else if (c == ')') {
70 x = complex<T>(re, T(0));
71 }
72 else {
73 is.setstate(ios_base::failbit);
74 }
75 }
76 else {
77 is.putback(c);
78 is >> re;
79 if (!is.eof() && ((c = static_cast<char>(is.peek())) == '+' || c == '-')) {
80 is >> im >> c;
81 if (c == 'i') {
82 x = complex<T>(re, im);
83 }
84 else {
85 is.setstate(ios_base::failbit);
86 }
87 }
88 else {
89 x = complex<T>(re, T(0));
90 }
91 }
92 return is;
93}
94
95} // namespace std
96
97
99namespace itpp
100{
101
103const double pi = 3.14159265358979323846;
104
106const double m_2pi = 2 * pi;
107
109const double eps = std::numeric_limits<double>::epsilon();
110
113
115inline bool is_int(double x)
116{
117 double dummy;
118 return (modf(x, &dummy) == 0.0);
119}
120
122inline bool is_even(int x) { return ((x&1) == 0); }
123
125ITPP_EXPORT std::string itpp_version();
126
128ITPP_EXPORT bool is_bigendian();
129
131inline bool check_big_endianness() { return is_bigendian(); }
132
134
135} //namespace itpp
136
137
138#endif // #ifndef MISC_H
bool is_bigendian()
Returns true if machine endianness is BIG_ENDIAN.
Definition: misc.cpp:50
std::string itpp_version(void)
Returns IT++ library version number, e.g. "3.7.1".
Definition: misc.cpp:41
bool is_even(int x)
Return true if x is an even integer.
Definition: misc.h:122
bool check_big_endianness()
This function is deprecated. Please use is_bigendian() instead.
Definition: misc.h:131
bool is_int(double x)
Return true if x is an integer.
Definition: misc.h:115
itpp namespace
Definition: itmex.h:37
const double m_2pi
Constant 2*Pi.
Definition: misc.h:106
const double pi
Constant Pi.
Definition: misc.h:103
const double eps
Constant eps.
Definition: misc.h:109
STL namespace.
std::ostream & operator<<(std::ostream &os, const std::complex< T > &x)
Output stream operator for complex numbers.
Definition: misc.h:42
std::istream & operator>>(std::istream &is, std::complex< T > &x)
Input stream operator for complex numbers.
Definition: misc.h:53

Generated on Tue Aug 17 2021 10:59:15 for IT++ by Doxygen 1.9.4