Documentation of CSL
libcomplexop.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef LIBCOMPLEXOP_H_INCLUDED
24 #define LIBCOMPLEXOP_H_INCLUDED
25 
26 #include <complex>
27 #include <iostream>
28 
29 
30 #ifdef QUAD
31 
33 // quadruple - double / float operators
35 
36 #include <quadmath.h>
37 
38 inline std::complex<__float128> operator+(
39  std::complex<__float128> const&c,
40  double a
41  )
42 {
43  return c + std::complex<__float128>(a);
44 }
45 inline std::complex<__float128> operator+(
46  double a,
47  std::complex<__float128> const&c
48  )
49 {
50  return c + std::complex<__float128>(a);
51 }
52 
53 inline std::complex<__float128> operator*(
54  std::complex<__float128> const&c,
55  double a
56  )
57 {
58  return c * std::complex<__float128>(a);
59 }
60 inline std::complex<__float128> operator*(
61  double a,
62  std::complex<__float128> const&c
63  )
64 {
65  return c * std::complex<__float128>(a);
66 }
67 
68 inline std::complex<__float128> operator-(
69  std::complex<__float128> const&c,
70  double a
71  )
72 {
73  return c - std::complex<__float128>(a);
74 }
75 inline std::complex<__float128> operator-(
76  double a,
77  std::complex<__float128> const&c
78  )
79 {
80  return std::complex<__float128>(a) - c;
81 }
82 
83 inline std::complex<__float128> operator/(
84  std::complex<__float128> const&c,
85  double a
86  )
87 {
88  return c / std::complex<__float128>(a);
89 }
90 inline std::complex<__float128> operator/(
91  double a,
92  std::complex<__float128> const&c
93  )
94 {
95  return std::complex<__float128>(a) / c;
96 }
97 
98 // Complex - complex operators
99 
100 inline std::complex<__float128> operator+(
101  std::complex<__float128> const&c,
102  std::complex<double> const&a
103  )
104 {
105  return c + std::complex<__float128>(a);
106 }
107 inline std::complex<__float128> operator+(
108  std::complex<double> const&a,
109  std::complex<__float128> const&c
110  )
111 {
112  return c + std::complex<__float128>(a);
113 }
114 
115 inline std::complex<__float128> operator*(
116  std::complex<__float128> const&c,
117  std::complex<double> const&a
118  )
119 {
120  return c * std::complex<__float128>(a);
121 }
122 inline std::complex<__float128> operator*(
123  std::complex<double> const&a,
124  std::complex<__float128> const&c
125  )
126 {
127  return c * std::complex<__float128>(a);
128 }
129 
130 inline std::complex<__float128> operator-(
131  std::complex<__float128> const&c,
132  std::complex<double> const&a
133  )
134 {
135  return c - std::complex<__float128>(a);
136 }
137 inline std::complex<__float128> operator-(
138  std::complex<double> const&a,
139  std::complex<__float128> const&c
140  )
141 {
142  return std::complex<__float128>(a) - c;
143 }
144 
145 inline std::complex<__float128> operator/(
146  std::complex<__float128> const&c,
147  std::complex<double> const&a
148  )
149 {
150  return c / std::complex<__float128>(a);
151 }
152 inline std::complex<__float128> operator/(
153  std::complex<double> const&a,
154  std::complex<__float128> const&c
155  )
156 {
157  return std::complex<__float128>(a) / c;
158 }
159 
161 // quadruple / int operators
163 
164 inline std::complex<__float128> operator+(
165  std::complex<__float128> const&c,
166  int a
167  )
168 {
169  return c + std::complex<__float128>(a);
170 }
171 inline std::complex<__float128> operator+(
172  int a,
173  std::complex<__float128> const&c
174  )
175 {
176  return c + std::complex<__float128>(a);
177 }
178 
179 inline std::complex<__float128> operator*(
180  std::complex<__float128> const&c,
181  int a
182  )
183 {
184  return c * std::complex<__float128>(a);
185 }
186 inline std::complex<__float128> operator*(
187  int a,
188  std::complex<__float128> const&c
189  )
190 {
191  return c * std::complex<__float128>(a);
192 }
193 
194 inline std::complex<__float128> operator-(
195  std::complex<__float128> const&c,
196  int a
197  )
198 {
199  return c - std::complex<__float128>(a);
200 }
201 inline std::complex<__float128> operator-(
202  int a,
203  std::complex<__float128> const&c
204  )
205 {
206  return std::complex<__float128>(a) - c;
207 }
208 
209 inline std::complex<__float128> operator/(
210  std::complex<__float128> const&c,
211  int a
212  )
213 {
214  return c / std::complex<__float128>(a);
215 }
216 inline std::complex<__float128> operator/(
217  int a,
218  std::complex<__float128> const&c
219  )
220 {
221  return std::complex<__float128>(a) / c;
222 }
223 
224 // Complex - complex operators
225 
226 inline std::complex<__float128> operator+(
227  std::complex<__float128> const&c,
228  std::complex<int> const&a
229  )
230 {
231  return c + std::complex<__float128>(a);
232 }
233 inline std::complex<__float128> operator+(
234  std::complex<int> const&a,
235  std::complex<__float128> const&c
236  )
237 {
238  return c + std::complex<__float128>(a);
239 }
240 
241 inline std::complex<__float128> operator*(
242  std::complex<__float128> const&c,
243  std::complex<int> const&a
244  )
245 {
246  return c * std::complex<__float128>(a);
247 }
248 inline std::complex<__float128> operator*(
249  std::complex<int> const&a,
250  std::complex<__float128> const&c
251  )
252 {
253  return c * std::complex<__float128>(a);
254 }
255 
256 inline std::complex<__float128> operator-(
257  std::complex<__float128> const&c,
258  std::complex<int> const&a
259  )
260 {
261  return c - std::complex<__float128>(a);
262 }
263 inline std::complex<__float128> operator-(
264  std::complex<int> const&a,
265  std::complex<__float128> const&c
266  )
267 {
268  return std::complex<__float128>(a) - c;
269 }
270 
271 inline std::complex<__float128> operator/(
272  std::complex<__float128> const&c,
273  std::complex<int> const&a
274  )
275 {
276  return c / std::complex<__float128>(a);
277 }
278 inline std::complex<__float128> operator/(
279  std::complex<int> const&a,
280  std::complex<__float128> const&c
281  )
282 {
283  return std::complex<__float128>(a) / c;
284 }
285 
286 inline std::ostream &operator<<(
287  std::ostream &out,
288  __float128 x
289  )
290 {
291  out << (double)x;
292  return out;
293 }
294 
295 inline std::ostream &operator<<(
296  std::ostream &out,
297  __complex128 z
298  )
299 {
300  out << "(" << crealq(z) << " + i*" << cimagq(z) << ")";
301  return out;
302 }
303 
304 #endif
305 
307 // double / int operators
309 
310 inline std::complex<double> operator+(
311  std::complex<double> const&c,
312  int a
313  )
314 {
315  return c + std::complex<double>(a);
316 }
317 inline std::complex<double> operator+(
318  int a,
319  std::complex<double> const&c
320  )
321 {
322  return c + std::complex<double>(a);
323 }
324 
325 inline std::complex<double> operator*(
326  std::complex<double> const&c,
327  int a
328  )
329 {
330  return c * std::complex<double>(a);
331 }
332 inline std::complex<double> operator*(
333  int a,
334  std::complex<double> const&c
335  )
336 {
337  return c * std::complex<double>(a);
338 }
339 
340 inline std::complex<double> operator-(
341  std::complex<double> const&c,
342  int a
343  )
344 {
345  return c - std::complex<double>(a);
346 }
347 inline std::complex<double> operator-(
348  int a,
349  std::complex<double> const&c
350  )
351 {
352  return std::complex<double>(a) - c;
353 }
354 
355 inline std::complex<double> operator/(
356  std::complex<double> const&c,
357  int a
358  )
359 {
360  return c / std::complex<double>(a);
361 }
362 inline std::complex<double> operator/(
363  int a,
364  std::complex<double> const&c
365  )
366 {
367  return std::complex<double>(a) / c;
368 }
369 
370 // Complex - complex operators
371 
372 inline std::complex<double> operator+(
373  std::complex<double> const&c,
374  std::complex<int> const&a
375  )
376 {
377  return c + std::complex<double>(a.real(), a.imag());
378 }
379 inline std::complex<double> operator+(
380  std::complex<int> const&a,
381  std::complex<double> const&c
382  )
383 {
384  return c + std::complex<double>(a.real(), a.imag());
385 }
386 
387 inline std::complex<double> operator*(
388  std::complex<double> const&c,
389  std::complex<int> const&a
390  )
391 {
392  return c * std::complex<double>(a.real(), a.imag());
393 }
394 inline std::complex<double> operator*(
395  std::complex<int> const&a,
396  std::complex<double> const&c
397  )
398 {
399  return c * std::complex<double>(a.real(), a.imag());
400 }
401 
402 inline std::complex<double> operator-(
403  std::complex<double> const&c,
404  std::complex<int> const&a
405  )
406 {
407  return c - std::complex<double>(a.real(), a.imag());
408 }
409 inline std::complex<double> operator-(
410  std::complex<int> const&a,
411  std::complex<double> const&c
412  )
413 {
414  return std::complex<double>(a.real(), a.imag()) - c;
415 }
416 
417 inline std::complex<double> operator/(
418  std::complex<double> const&c,
419  std::complex<int> const&a
420  )
421 {
422  return c / std::complex<double>(a.real(), a.imag());
423 }
424 inline std::complex<double> operator/(
425  std::complex<int> const&a,
426  std::complex<double> const&c
427  )
428 {
429  return std::complex<double>(a.real(), a.imag()) / c;
430 }
431 
432 #endif
Expr operator+(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator + with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1298
Expr operator/(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator / with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1372
Expr operator*(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator * with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1351