- Main Page
- Tutorials
- Functions
- Release Notes
- Examples

complex.h
Go to the documentation of this file.
1 /*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10 #pragma once
11 #include "af/defines.h"
12
13
14 #ifdef __cplusplus
15 #include <ostream>
16 #include <istream>
17
18 namespace af{
19 #endif
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 typedef struct af_cfloat {
25 float real;
26 float imag;
27 #ifdef __cplusplus
28 af_cfloat(const float real = 0, const float imag = 0) :real(real), imag(imag) {};
29 #endif
30 } af_cfloat;
31
32 typedef struct af_cdouble {
33 double real;
34 double imag;
35 #ifdef __cplusplus
36 af_cdouble(const double real = 0, const double imag = 0) :real(real), imag(imag) {}
37 #endif
38 } af_cdouble;
39 #ifdef __cplusplus
40 }
41 #endif
42
43 #ifdef __cplusplus
44 typedef af::af_cfloat cfloat;
45 typedef af::af_cdouble cdouble;
46
47 AFAPI float real(af_cfloat val);
48 AFAPI double real(af_cdouble val);
49
50 AFAPI float imag(af_cfloat val);
51 AFAPI double imag(af_cdouble val);
52
53 // +,-,*,/ for (cfloat, cfloat) and (cdouble, cdouble)
54 #define DEFINE_OP(OP) \
55 AFAPI af::cfloat operator OP(const af::cfloat &lhs, const af::cfloat &rhs); \
56 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const af::cdouble &rhs); \
57
58 DEFINE_OP(+)
59 DEFINE_OP(-)
60 DEFINE_OP(*)
61 DEFINE_OP(/)
62
63 #undef DEFINE_OP
64
65 // +,/ for (cfloat, double) and (cdouble, double)
66 #define DEFINE_OP(OP) \
67 AFAPI af::cfloat operator OP(const af::cfloat &lhs, const double &rhs); \
68 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const double &rhs); \
69
70 DEFINE_OP(+)
71 DEFINE_OP(/)
72
73 #undef DEFINE_OP
74
75 #if AF_API_VERSION >= 31
76 // -,* for (cfloat, double) and (cdouble, double)
77 #define DEFINE_OP(OP) \
78 AFAPI af::cfloat operator OP(const af::cfloat &lhs, const double &rhs); \
79 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const double &rhs); \
80
81 DEFINE_OP(-)
82 DEFINE_OP(*)
83
84 #undef DEFINE_OP
85 #endif // AF_API_VERSION
86
87 #if AF_API_VERSION >= 31
88 // +, -, *, / for (double, cfloat/cdouble) and (cfloat/cdouble, cdouble/cfloat)
89 #define DEFINE_OP(OP) \
90 AFAPI af::cfloat operator OP(const double &rhs, const af::cfloat &lhs); \
91 AFAPI af::cdouble operator OP(const double &rhs, const af::cdouble &lhs); \
92 AFAPI af::cdouble operator OP(const af::cfloat &lhs, const af::cdouble &rhs); \
93 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const af::cfloat &rhs); \
94
95 DEFINE_OP(+)
96 DEFINE_OP(-)
97 DEFINE_OP(*)
98 DEFINE_OP(/)
99
100 #undef DEFINE_OP
101 #endif // AF_API_VERSION
102
103 AFAPI bool operator==(const cfloat &lhs, const cfloat &rhs);
104 AFAPI bool operator==(const cdouble &lhs, const cdouble &rhs);
105
106 AFAPI bool operator!=(const cfloat &lhs, const cfloat &rhs);
107 AFAPI bool operator!=(const cdouble &lhs, const cdouble &rhs);
108
109 AFAPI std::istream& operator>> (std::istream &is, cfloat &in);
110 AFAPI std::istream& operator>> (std::istream &is, cdouble &in);
111
112 AFAPI std::ostream& operator<< (std::ostream &os, const cfloat &in);
113 AFAPI std::ostream& operator<< (std::ostream &os, const cdouble &in);
114
115
116 AFAPI float abs(const cfloat &val);
117 AFAPI double abs(const cdouble &val);
118
119 AFAPI cfloat conj(const cfloat &val);
120 AFAPI cdouble conj(const cdouble &val);
121
122 }
123 #endif
af
Definition: algorithm.h:14
af::af_cdouble::imag
double imag
Definition: complex.h:34
af::operator==
AFAPI array operator==(const array &lhs, const array &rhs)
Performs an equality operation on two arrays or an array and a value.
af::conj
AFAPI cfloat conj(const cfloat &val)
af::af_cdouble
Definition: complex.h:32
af::cfloat
af::af_cfloat cfloat
Definition: complex.h:44
af::af_cfloat::af_cfloat
af_cfloat(const float real=0, const float imag=0)
Definition: complex.h:28
af::operator>>
AFAPI array operator>>(const array &lhs, const array &rhs)
Performs an right shift operation on two arrays or an array and a value.
defines.h
af::af_cfloat::imag
float imag
Definition: complex.h:26
af::imag
AFAPI array imag(const array &in)
C++ Interface for getting imaginary part from complex array.
af::operator!=
AFAPI array operator!=(const array &lhs, const array &rhs)
Performs an inequality operation on two arrays or an array and a value.
af::af_cdouble
struct af::af_cdouble af_cdouble
af::real
AFAPI array real(const array &in)
C++ Interface for getting real part from complex array.
AFAPI
#define AFAPI
Definition: defines.h:31
af::operator<<
AFAPI array operator<<(const array &lhs, const array &rhs)
Performs an left shift operation on two arrays or an array and a value.
af::af_cdouble::real
double real
Definition: complex.h:33
af::af_cfloat
Definition: complex.h:24
af::af_cfloat::real
float real
Definition: complex.h:25
af::abs
AFAPI array abs(const array &in)
C++ Interface for absolute value.
af::af_cdouble::af_cdouble
af_cdouble(const double real=0, const double imag=0)
Definition: complex.h:36
af::af_cfloat
struct af::af_cfloat af_cfloat
af::cdouble
af::af_cdouble cdouble
Definition: complex.h:45
DEFINE_OP
#define DEFINE_OP(OP)
Definition: complex.h:89