forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex.h
77 lines (59 loc) · 1.98 KB
/
complex.h
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
/*
* Copyright (c) 2022, Peter Elliott <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
/* complex arithmetic
*
* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/complex.h.html
*/
#pragma once
#ifdef __cplusplus
# error "C++ code must not include complex.h. Use AK/Complex.h instead."
#endif
#include <stddef.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
#define complex _Complex
#define _Complex_I (0.0f + 1.0fi)
#define I _Complex_I
#define CMPLX(x, y) ((double complex)__builtin_complex((double)x, (double)y))
#define CMPLXF(x, y) ((float complex)__builtin_complex((float)x, (float)y))
#define CMPLXL(x, y) ((long double complex)__builtin_complex((long double)x, (long double)y))
// These are macro implementations of the above functions, so that they will always be inlined.
#define creal(z) ((double)__real__((double complex)z))
#define crealf(z) ((float)__real__((float complex)z))
#define creall(z) ((long double)__real__((long double complex)z))
#define cimag(z) ((double)__imag__((double complex)z))
#define cimagf(z) ((float)__imag__((float complex)z))
#define cimagl(z) ((long double)__imag__((long double complex)z))
// Function definitions of this form "type (name)(args)" are intentional, to
// prevent macro versions of "name" from being incorrectly expanded. These
// functions are here to provide external linkage to their macro implementations.
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/creal.html
static inline float(crealf)(float complex z)
{
return crealf(z);
}
static inline double(creal)(double complex z)
{
return creal(z);
}
static inline long double(creall)(long double complex z)
{
return creall(z);
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/cimag.html
static inline double(cimag)(double complex z)
{
return cimag(z);
}
static inline float(cimagf)(float complex z)
{
return cimagf(z);
}
static inline long double(cimagl)(long double complex z)
{
return cimagl(z);
}
__END_DECLS