Imt.Base C++ API V4.1.1.0
Loading...
Searching...
No Matches
openlibm_complex.h
Go to the documentation of this file.
1/* $OpenBSD: complex.h,v 1.5 2014/03/16 18:38:30 guenther Exp $ */
2/*
3 * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifdef OPENLIBM_USE_HOST_COMPLEX_H
19#include <complex.h>
20#else /* !OPENLIBM_USE_HOST_COMPLEX_H */
21
22#ifndef OPENLIBM_COMPLEX_H
23#define OPENLIBM_COMPLEX_H
24
25#define complex _Complex
26
27#define _Complex_I 1.0fi
28#define I _Complex_I
29
30/*
31 * Macros that can be used to construct complex values.
32 *
33 * The C99 standard intends x+I*y to be used for this, but x+I*y is
34 * currently unusable in general since gcc introduces many overflow,
35 * underflow, sign and efficiency bugs by rewriting I*y as
36 * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
37 * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
38 * to -0.0+I*0.0.
39 *
40 * In C11, a CMPLX(x,y) macro was added to circumvent this limitation,
41 * and gcc 4.7 added a __builtin_complex feature to simplify implementation
42 * of CMPLX in libc, so we can take advantage of these features if they
43 * are available. Clang simply allows complex values to be constructed
44 * using a compound literal.
45 *
46 * If __builtin_complex is not available, resort to using inline
47 * functions instead. These can unfortunately not be used to construct
48 * compile-time constants.
49 *
50 * C99 specifies that complex numbers have the same representation as
51 * an array of two elements, where the first element is the real part
52 * and the second element is the imaginary part.
53 */
54
55#ifdef __clang__
56# define CMPLXF(x, y) ((float complex){x, y})
57# define CMPLX(x, y) ((double complex){x, y})
58# define CMPLXL(x, y) ((long double complex){x, y})
59#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__INTEL_COMPILER)
60# define CMPLXF(x,y) __builtin_complex ((float) (x), (float) (y))
61# define CMPLX(x,y) __builtin_complex ((double) (x), (double) (y))
62# define CMPLXL(x,y) __builtin_complex ((long double) (x), (long double) (y))
63#elif defined(_MSC_BUILD)
64 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 //
66 // Types
67 //
68 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69#ifndef _C_COMPLEX_T
70#define _C_COMPLEX_T
71typedef struct _C_double_complex {
72 double _Val[2];
73} _C_double_complex;
74
75typedef struct _C_float_complex {
76 float _Val[2];
77} _C_float_complex;
78
79typedef struct _C_ldouble_complex {
80 long double _Val[2];
81} _C_ldouble_complex;
82#endif
83
84typedef _C_double_complex _Dcomplex;
85typedef _C_float_complex _Fcomplex;
86typedef _C_ldouble_complex _Lcomplex;
87
88static inline _Fcomplex
89CMPLXF(float x, float y) {
90 union {
91 float a[2];
92 _Fcomplex f;
93 } z;
94 z.a[0] = x;
95 z.a[1] = y;
96
97 return (z.f);
98}
99
100static inline _Dcomplex
101CMPLX(double x, double y) {
102 union {
103 double a[2];
104 _Dcomplex f;
105 } z;
106 z.a[0] = x;
107 z.a[1] = y;
108
109 return (z.f);
110}
111
112static inline _Lcomplex
113CMPLXL(long double x, long double y) {
114 union {
115 long double a[2];
116 _Lcomplex f;
117 } z;
118 z.a[0] = x;
119 z.a[1] = y;
120
121 return (z.f);
122}
123#else
124static inline float complex CMPLXF(float x, float y)
125{
126 union {
127 float a[2];
128 float complex f;
129 } z = {{ x, y }};
130
131 return (z.f);
132}
133
134static inline double complex
135CMPLX(double x, double y)
136{
137 union {
138 double a[2];
139 double complex f;
140 } z = {{ x, y }};
141
142 return (z.f);
143}
144
145static inline long double complex
146CMPLXL(long double x, long double y)
147{
148 union {
149 long double a[2];
150 long double complex f;
151 } z = {{ x, y }};
152
153 return (z.f);
154}
155#endif
156
157#if !defined(_MSC_BUILD)
158/*
159 * Double versions of C99 functions
160 */
161double complex cacos(double complex);
162double complex casin(double complex);
163double complex catan(double complex);
164double complex ccos(double complex);
165double complex csin(double complex);
166double complex ctan(double complex);
167double complex cacosh(double complex);
168double complex casinh(double complex);
169double complex catanh(double complex);
170double complex ccosh(double complex);
171double complex csinh(double complex);
172double complex ctanh(double complex);
173double complex cexp(double complex);
174double complex clog(double complex);
175double cabs(double complex);
176double complex cpow(double complex, double complex);
177double complex csqrt(double complex);
178double carg(double complex);
179double cimag(double complex);
180double complex conj(double complex);
181double complex cproj(double complex);
182double creal(double complex);
183
184/*
185 * Float versions of C99 functions
186 */
187float complex cacosf(float complex);
188float complex casinf(float complex);
189float complex catanf(float complex);
190float complex ccosf(float complex);
191float complex csinf(float complex);
192float complex ctanf(float complex);
196float complex ccoshf(float complex);
197float complex csinhf(float complex);
198float complex ctanhf(float complex);
199float complex cexpf(float complex);
200float complex clogf(float complex);
201float cabsf(float complex);
202float complex cpowf(float complex, float complex);
203float complex csqrtf(float complex);
204float cargf(float complex);
205float cimagf(float complex);
206float complex conjf(float complex);
207float complex cprojf(float complex);
208float crealf(float complex);
209
210/*
211 * Long double versions of C99 functions
212 */
213long double complex cacosl(long double complex);
214long double complex casinl(long double complex);
215long double complex catanl(long double complex);
216long double complex ccosl(long double complex);
217long double complex csinl(long double complex);
218long double complex ctanl(long double complex);
219long double complex cacoshl(long double complex);
220long double complex casinhl(long double complex);
221long double complex catanhl(long double complex);
222long double complex ccoshl(long double complex);
223long double complex csinhl(long double complex);
224long double complex ctanhl(long double complex);
225long double complex cexpl(long double complex);
226long double complex clogl(long double complex);
227long double cabsl(long double complex);
228long double complex cpowl(long double complex,
229 long double complex);
230long double complex csqrtl(long double complex);
231long double cargl(long double complex);
232long double cimagl(long double complex);
233long double complex conjl(long double complex);
234long double complex cprojl(long double complex);
235long double creall(long double complex);
236#else
237/*
238* Double versions of C99 functions
239*/
240_Dcomplex cacos(_Dcomplex);
241_Dcomplex casin(_Dcomplex);
242_Dcomplex catan(_Dcomplex);
243_Dcomplex ccos(_Dcomplex);
244_Dcomplex csin(_Dcomplex);
245_Dcomplex ctan(_Dcomplex);
246_Dcomplex cacosh(_Dcomplex);
247_Dcomplex casinh(_Dcomplex);
248_Dcomplex catanh(_Dcomplex);
249_Dcomplex ccosh(_Dcomplex);
250_Dcomplex csinh(_Dcomplex);
251_Dcomplex ctanh(_Dcomplex);
252_Dcomplex cexp(_Dcomplex);
253_Dcomplex clog(_Dcomplex);
254double cabs(_Dcomplex);
255_Dcomplex cpow(_Dcomplex, _Dcomplex);
256_Dcomplex csqrt(_Dcomplex);
257double carg(_Dcomplex);
258double cimag(_Dcomplex);
259_Dcomplex conj(_Dcomplex);
260_Dcomplex cproj(_Dcomplex);
261double creal(_Dcomplex);
262
263/*
264* Float versions of C99 functions
265*/
266_Fcomplex cacosf(_Fcomplex);
267_Fcomplex casinf(_Fcomplex);
268_Fcomplex catanf(_Fcomplex);
269_Fcomplex ccosf(_Fcomplex);
270_Fcomplex csinf(_Fcomplex);
271_Fcomplex ctanf(_Fcomplex);
272_Fcomplex cacoshf(_Fcomplex);
273_Fcomplex casinhf(_Fcomplex);
274_Fcomplex catanhf(_Fcomplex);
275_Fcomplex ccoshf(_Fcomplex);
276_Fcomplex csinhf(_Fcomplex);
277_Fcomplex ctanhf(_Fcomplex);
278_Fcomplex cexpf(_Fcomplex);
279_Fcomplex clogf(_Fcomplex);
280float cabsf(_Fcomplex);
281_Fcomplex cpowf(_Fcomplex, _Fcomplex);
282_Fcomplex csqrtf(_Fcomplex);
283float cargf(_Fcomplex);
284float cimagf(_Fcomplex);
285_Fcomplex conjf(_Fcomplex);
286_Fcomplex cprojf(_Fcomplex);
287float crealf(_Fcomplex);
288
289/*
290* Long double versions of C99 functions
291*/
292_Lcomplex cacosl(_Lcomplex);
293_Lcomplex casinl(_Lcomplex);
294_Lcomplex catanl(_Lcomplex);
295_Lcomplex ccosl(_Lcomplex);
296_Lcomplex csinl(_Lcomplex);
297_Lcomplex ctanl(_Lcomplex);
298_Lcomplex cacoshl(_Lcomplex);
299_Lcomplex casinhl(_Lcomplex);
300_Lcomplex catanhl(_Lcomplex);
301_Lcomplex ccoshl(_Lcomplex);
302_Lcomplex csinhl(_Lcomplex);
303_Lcomplex ctanhl(_Lcomplex);
304_Lcomplex cexpl(_Lcomplex);
305_Lcomplex clogl(_Lcomplex);
306long double cabsl(_Lcomplex);
307_Lcomplex cpowl(_Lcomplex,
308 _Lcomplex);
309_Lcomplex csqrtl(_Lcomplex);
310long double cargl(_Lcomplex);
311long double cimagl(_Lcomplex);
312_Lcomplex conjl(_Lcomplex);
313_Lcomplex cprojl(_Lcomplex);
314long double creall(_Lcomplex);
315#endif /* !_MSC_BUILD */
316
317#endif /* !OPENLIBM_COMPLEX_H */
318
319#endif /* OPENLIBM_USE_HOST_COMPLEX_H */
double complex csqrt(double complex)
float cabsf(float complex)
double complex ccos(double complex)
#define complex
long double complex csinhl(long double complex)
long double complex ccosl(long double complex)
float cimagf(float complex)
float complex conjf(float complex)
float complex catanhf(float complex)
float complex ccosf(float complex)
double complex cacosh(double complex)
long double complex cexpl(long double complex)
long double cargl(long double complex)
float complex cacoshf(float complex)
long double complex cacosl(long double complex)
long double complex ctanhl(long double complex)
long double complex ccoshl(long double complex)
double complex catanh(double complex)
float cargf(float complex)
double complex catan(double complex)
long double complex cpowl(long double complex, long double complex)
float complex casinf(float complex)
double cimag(double complex)
float complex csqrtf(float complex)
float complex ccoshf(float complex)
double complex ctan(double complex)
float complex casinhf(float complex)
float complex cpowf(float complex, float complex)
double complex cexp(double complex)
double complex cproj(double complex)
double complex casinh(double complex)
double complex csinh(double complex)
float crealf(float complex)
double complex ctanh(double complex)
double complex cpow(double complex, double complex)
float complex catanf(float complex)
double cabs(double complex)
long double complex conjl(long double complex)
long double complex cprojl(long double complex)
long double cabsl(long double complex)
long double complex ctanl(long double complex)
long double complex csinl(long double complex)
double creal(double complex)
double complex ccosh(double complex)
float complex ctanhf(float complex)
float complex ctanf(float complex)
double complex clog(double complex)
double complex csin(double complex)
float complex clogf(float complex)
long double complex casinhl(long double complex)
float complex cprojf(float complex)
double complex cacos(double complex)
double complex conj(double complex)
float complex cacosf(float complex)
long double complex casinl(long double complex)
long double creall(long double complex)
long double complex csqrtl(long double complex)
long double complex catanhl(long double complex)
double carg(double complex)
float complex cexpf(float complex)
double complex casin(double complex)
long double complex catanl(long double complex)
long double complex cacoshl(long double complex)
float complex csinhf(float complex)
long double complex clogl(long double complex)
long double cimagl(long double complex)
float complex csinf(float complex)