29#ifndef SAF_COMPLEX_H_INCLUDED
30#define SAF_COMPLEX_H_INCLUDED
32#if defined(__cplusplus)
34 typedef std::complex<float> float_complex;
35 typedef std::complex<double> double_complex;
40 inline float_complex cmplxf(
float re,
float im) {
return float_complex(re, im); }
41 inline float_complex ccaddf(float_complex x, float_complex y) {
return x + y; }
42 inline float_complex craddf(float_complex x,
float y) {
return x + y; }
43 inline float_complex ccsubf(float_complex x, float_complex y) {
return x - y; }
44 inline float_complex crsubf(float_complex x,
float y) {
return x - y; }
45 inline float_complex ccmulf(float_complex x, float_complex y) {
return x * y; }
46 inline float_complex cccmulf(float_complex x, float_complex y, float_complex z) {
return x * y * z; }
47 inline float_complex crmulf(float_complex x,
float y) {
return x * y; }
48 inline float_complex ccdivf(float_complex x, float_complex y) {
return x / y; }
49 inline float_complex crdivf(float_complex x,
float y) {
return x / y; }
54 inline double_complex cmplx(
double re,
double im) {
return double_complex(re, im);}
55 inline double_complex ccadd(double_complex x, double_complex y) {
return x + y; }
56 inline double_complex cradd(double_complex x,
double y) {
return x + y; }
57 inline double_complex ccsub(double_complex x, double_complex y) {
return x - y; }
58 inline double_complex crsub(double_complex x,
double y) {
return x - y; }
59 inline double_complex ccmul(double_complex x, double_complex y) {
return x * y; }
60 inline double_complex cccmul(double_complex x, double_complex y, double_complex z) {
return x * y * z; }
61 inline double_complex crmul(double_complex x,
double y) {
return x * y; }
62 inline double_complex ccdiv(double_complex x, double_complex y) {
return x / y; }
63 inline double_complex crdiv(double_complex x,
double y) {
return x / y; }
66#elif __STDC_VERSION__ >= 199901L
70 typedef float _Complex float_complex;
71 typedef double _Complex double_complex;
76 float_complex cmplxf(
float re,
float im);
77 float_complex ccaddf(float_complex x, float_complex y);
78 float_complex craddf(float_complex x,
float y);
79 float_complex ccsubf(float_complex x, float_complex y);
80 float_complex crsubf(float_complex x,
float y);
81 float_complex ccmulf(float_complex x, float_complex y);
82 float_complex cccmulf(float_complex x, float_complex y, float_complex z);
83 float_complex crmulf(float_complex x,
float y);
84 float_complex ccdivf(float_complex x, float_complex y);
85 float_complex crdivf(float_complex x,
float y);
90 double_complex cmplx(
double re,
double im);
91 double_complex ccadd(double_complex x, double_complex y);
92 double_complex cradd(double_complex x,
double y);
93 double_complex ccsub(double_complex x, double_complex y);
94 double_complex crsub(double_complex x,
double y);
95 double_complex ccmul(double_complex x, double_complex y);
96 double_complex cccmul(double_complex x, double_complex y, double_complex z);
97 double_complex crmul(double_complex x,
double y);
98 double_complex ccdiv(double_complex x, double_complex y);
99 double_complex crdiv(double_complex x,
double y);
102#elif _MSC_VER >= 1900
107 typedef _Fcomplex float_complex;
108 typedef _Dcomplex double_complex;
113 inline float_complex cmplxf(
float re,
float im) {
115 z._Val[0] = re; z._Val[1] = im;
119 inline float_complex ccaddf(float_complex x, float_complex y) {
121 z._Val[0] = x._Val[0] + y._Val[0]; z._Val[1] = x._Val[1] + y._Val[1];
125 inline float_complex craddf(float_complex x,
float y) {
127 z._Val[0] = x._Val[0] + y; z._Val[1] = x._Val[1];
131 inline float_complex ccsubf(float_complex x, float_complex y) {
133 z._Val[0] = x._Val[0] - y._Val[0]; z._Val[1] = x._Val[1] - y._Val[1];
137 inline float_complex crsubf(float_complex x,
float y) {
139 z._Val[0] = x._Val[0] - y; z._Val[1] = x._Val[1];
143 inline float_complex ccmulf(float_complex x, float_complex y) {
144 return _FCmulcc(x, y);
147 inline float_complex cccmulf(float_complex x, float_complex y, float_complex z) {
148 return _FCmulcc(_FCmulcc(x, y), z);
151 inline float_complex crmulf(float_complex x,
float y) {
152 return _FCmulcr(x, y);
155 inline float_complex ccdivf(float_complex x, float_complex y) {
157 z._Val[0] = (x._Val[0] * y._Val[0] + x._Val[1] * y._Val[1]) / (y._Val[0] * y._Val[0] + y._Val[1] * y._Val[1] );
158 z._Val[1] = (x._Val[1] * y._Val[0] - x._Val[0] * y._Val[1]) / (y._Val[0] * y._Val[0] + y._Val[1] * y._Val[1] );
162 inline float_complex crdivf(float_complex x,
float y) {
164 z._Val[0] = x._Val[0] / y;
165 z._Val[1] = x._Val[1] / y;
172 inline double_complex cmplx(
double re,
double im) {
174 z._Val[0] = re; z._Val[1] = im;
178 inline double_complex ccadd(double_complex x, double_complex y) {
180 z._Val[0] = x._Val[0] + y._Val[0]; z._Val[1] = x._Val[1] + y._Val[1];
184 inline double_complex cradd(double_complex x,
double y) {
186 z._Val[0] = x._Val[0] + y; z._Val[1] = x._Val[1];
190 inline double_complex ccsub(double_complex x, double_complex y) {
192 z._Val[0] = x._Val[0] - y._Val[0]; z._Val[1] = x._Val[1] - y._Val[1];
196 inline double_complex crsub(double_complex x,
double y) {
198 z._Val[0] = x._Val[0] - y; z._Val[1] = x._Val[1];
202 inline double_complex ccmul(double_complex x, double_complex y) {
203 return _Cmulcc(x, y);
206 inline double_complex cccmul(double_complex x, double_complex y, double_complex z) {
207 return _Cmulcc(_Cmulcc(x, y), z);
210 inline double_complex crmul(double_complex x,
double y) {
211 return _Cmulcr(x, y);
214 inline double_complex ccdiv(double_complex x, double_complex y) {
216 z._Val[0] = (x._Val[0] * y._Val[0] + x._Val[1] * y._Val[1]) / (y._Val[0] * y._Val[0] + y._Val[1] * y._Val[1]);
217 z._Val[1] = (x._Val[1] * y._Val[0] - x._Val[0] * y._Val[1]) / (y._Val[0] * y._Val[0] + y._Val[1] * y._Val[1]);
221 inline double_complex crdiv(double_complex x,
double y) {
223 z._Val[0] = x._Val[0] / y;
224 z._Val[1] = x._Val[1] / y;
229# error "SAF requires a compiler that supports the C99 standard, or MSVC version 1900 or newer"