20 #ifndef TENSOR_NUMBERS_H
21 #define TENSOR_NUMBERS_H
33 template<
typename number>
34 inline number number_zero() {
return static_cast<number
>(0); }
36 template<
typename number>
37 inline number number_one() {
return static_cast<number
>(1); }
40 inline double real(
double r) {
return r; }
41 inline double imag(
double r) {
return 0.0; }
42 inline double conj(
double r) {
return r; }
43 inline double abs2(
double r) {
return r*r; }
44 inline double abs(
double r) {
return std::abs(r); }
46 template<
class number> number square(number r) {
return r*r; }
52 typedef std::complex<double> cdouble;
54 inline double real(
const cdouble &r) {
return std::real(r); }
55 inline double imag(
const cdouble &r) {
return std::imag(r); }
56 inline cdouble
conj(
const cdouble &r) {
return std::conj(r); }
57 inline double abs(
const cdouble &r) {
return std::abs(r); }
59 inline cdouble to_complex(
const double &r) {
63 inline cdouble to_complex(
const double &r,
const double &i) {
67 inline cdouble to_complex(
const cdouble &z) {
72 inline cdouble number_zero<cdouble>() {
return to_complex(0.0); }
75 inline cdouble number_one<cdouble>() {
return to_complex(1.0); }
77 inline double abs2(cdouble z) {
return abs2(real(z)) + abs2(imag(z)); }
79 inline cdouble round(cdouble r) {
80 return to_complex(::round(real(r)),::round(imag(r)));
83 inline std::istream &operator>>(std::istream &s, cdouble &z) {
90 inline std::ostream &operator<<(std::ostream &s,
const cdouble &d) {
91 return s << real(d) <<
' ' << imag(d);
96 #endif // !TENSOR_NUMBERS_H
const RTensor conj(const RTensor &r)
Complex conjugate of a real tensor.