File: complex.h

package info (click to toggle)
arrayfire 3.3.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 109,016 kB
  • sloc: cpp: 127,909; lisp: 6,878; python: 3,923; ansic: 1,051; sh: 347; makefile: 338; xml: 175
file content (123 lines) | stat: -rw-r--r-- 3,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************
 * Copyright (c) 2014, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#pragma once
#include "af/defines.h"


#ifdef __cplusplus
#include <ostream>
#include <istream>

namespace af{
#endif

#ifdef __cplusplus
extern "C" {
#endif
typedef struct af_cfloat {
    float real;
    float imag;
#ifdef __cplusplus
    af_cfloat(const float real = 0, const float imag = 0) :real(real), imag(imag) {};
#endif
} af_cfloat;

typedef struct af_cdouble {
    double real;
    double imag;
#ifdef __cplusplus
    af_cdouble(const double real = 0, const double imag = 0) :real(real), imag(imag) {}
#endif
} af_cdouble;
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
typedef af::af_cfloat   cfloat;
typedef af::af_cdouble  cdouble;

AFAPI float real(af_cfloat val);
AFAPI double real(af_cdouble val);

AFAPI float imag(af_cfloat val);
AFAPI double imag(af_cdouble val);

// +,-,*,/ for (cfloat, cfloat) and (cdouble, cdouble)
#define DEFINE_OP(OP)                                                               \
    AFAPI af::cfloat  operator OP(const af::cfloat  &lhs, const af::cfloat  &rhs);  \
    AFAPI af::cdouble operator OP(const af::cdouble &lhs, const af::cdouble &rhs);  \

DEFINE_OP(+)
DEFINE_OP(-)
DEFINE_OP(*)
DEFINE_OP(/)

#undef DEFINE_OP

// +,/ for (cfloat, double) and (cdouble, double)
#define DEFINE_OP(OP)                                                               \
    AFAPI af::cfloat  operator OP(const af::cfloat  &lhs, const     double  &rhs);  \
    AFAPI af::cdouble operator OP(const af::cdouble &lhs, const     double  &rhs);  \

DEFINE_OP(+)
DEFINE_OP(/)

#undef DEFINE_OP

#if AF_API_VERSION >= 31
// -,* for (cfloat, double) and (cdouble, double)
#define DEFINE_OP(OP)                                                               \
    AFAPI af::cfloat  operator OP(const af::cfloat  &lhs, const     double  &rhs);  \
    AFAPI af::cdouble operator OP(const af::cdouble &lhs, const     double  &rhs);  \

DEFINE_OP(-)
DEFINE_OP(*)

#undef DEFINE_OP
#endif  // AF_API_VERSION

#if AF_API_VERSION >= 31
// +, -, *, / for (double, cfloat/cdouble) and (cfloat/cdouble, cdouble/cfloat)
#define DEFINE_OP(OP)                                                               \
    AFAPI af::cfloat  operator OP(const double      &rhs, const af::cfloat  &lhs);  \
    AFAPI af::cdouble operator OP(const double      &rhs, const af::cdouble &lhs);  \
    AFAPI af::cdouble operator OP(const af::cfloat  &lhs, const af::cdouble &rhs);  \
    AFAPI af::cdouble operator OP(const af::cdouble &lhs, const af::cfloat  &rhs);  \

DEFINE_OP(+)
DEFINE_OP(-)
DEFINE_OP(*)
DEFINE_OP(/)

#undef DEFINE_OP
#endif  // AF_API_VERSION

AFAPI bool operator==(const cfloat &lhs, const cfloat &rhs);
AFAPI bool operator==(const cdouble &lhs, const cdouble &rhs);

AFAPI bool operator!=(const cfloat &lhs, const cfloat &rhs);
AFAPI bool operator!=(const cdouble &lhs, const cdouble &rhs);

AFAPI std::istream& operator>> (std::istream &is, cfloat &in);
AFAPI std::istream& operator>> (std::istream &is, cdouble &in);

AFAPI std::ostream& operator<< (std::ostream &os, const cfloat &in);
AFAPI std::ostream& operator<< (std::ostream &os, const cdouble &in);


AFAPI float abs(const cfloat &val);
AFAPI double abs(const cdouble &val);

AFAPI cfloat conj(const cfloat &val);
AFAPI cdouble conj(const cdouble &val);

}
#endif