IT++
4.3.1
Toggle main menu visibility
itpp
base
math
misc.h
Go to the documentation of this file.
1
28
29
#ifndef MISC_H
30
#define MISC_H
31
32
#include <complex>
33
#include <string>
34
#include <limits>
35
#include <itpp/itexports.h>
36
37
namespace
std
38
{
39
41
template
<
class
T>
42
std::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
52
template
<
class
T>
53
std::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
99
namespace
itpp
100
{
101
103
const
double
pi
= 3.14159265358979323846;
104
106
const
double
m_2pi
= 2 *
pi
;
107
109
const
double
eps
= std::numeric_limits<double>::epsilon();
110
113
115
inline
bool
is_int
(
double
x)
116
{
117
double
dummy;
118
return
(modf(x, &dummy) == 0.0);
119
}
120
122
inline
bool
is_even
(
int
x) {
return
((x&1) == 0); }
123
125
ITPP_EXPORT std::string
itpp_version
();
126
128
ITPP_EXPORT
bool
is_bigendian
();
129
131
inline
bool
check_big_endianness
() {
return
is_bigendian
(); }
132
134
135
}
//namespace itpp
136
137
138
#endif
// #ifndef MISC_H
itpp::is_bigendian
bool is_bigendian()
Returns true if machine endianness is BIG_ENDIAN.
Definition
misc.cpp:50
itpp::itpp_version
std::string itpp_version(void)
Returns IT++ library version number, e.g. "3.7.1".
Definition
misc.cpp:41
itpp::is_even
bool is_even(int x)
Return true if x is an even integer.
Definition
misc.h:122
itpp::check_big_endianness
bool check_big_endianness()
This function is deprecated. Please use is_bigendian() instead.
Definition
misc.h:131
itpp::is_int
bool is_int(double x)
Return true if x is an integer.
Definition
misc.h:115
itpp
itpp namespace
Definition
itmex.h:37
itpp::m_2pi
const double m_2pi
Constant 2*Pi.
Definition
misc.h:106
itpp::pi
const double pi
Constant Pi.
Definition
misc.h:103
itpp::eps
const double eps
Constant eps.
Definition
misc.h:109
std
STL namespace.
std::operator<<
std::ostream & operator<<(std::ostream &os, const std::complex< T > &x)
Output stream operator for complex numbers.
Definition
misc.h:42
std::operator>>
std::istream & operator>>(std::istream &is, std::complex< T > &x)
Input stream operator for complex numbers.
Definition
misc.h:53
Generated by
1.17.0