summaryrefslogtreecommitdiff
path: root/lib/Numerical/Complex.cpp
blob: af7179f4c1899e58425c4e0fe8d7ee1d6d256675 (plain)
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
#include <complex>
#include "Numerical/Complex.h"

using namespace std;

static inline Complex8 cmplx(complex<double> Value) {
  Complex8 Result = { Value.real(), Value.imag() };
  return Result;
}

static inline Complex4 cmplx(complex<float> Value) {
  Complex4 Result = { Value.real(), Value.imag() };
  return Result;
}

static inline complex<double> generic(double Re, double Im) {
  return complex<double>(Re, Im);
}

static inline complex<float> generic(float Re, float Im) {
  return complex<float>(Re, Im);
}

LIBFLANG_ABI void libflang_cpow(double LHSRe, double LHSIm,
                                double RHSRe, double RHSIm,
                                Complex8 *Result) {
  *Result = cmplx(pow(generic(LHSRe, LHSIm),
                    generic(RHSRe, RHSIm)));
}
LIBFLANG_ABI void libflang_cpowf(float LHSRe, float LHSIm,
                                 float RHSRe, float RHSIm,
                                 Complex4 *Result) {
  *Result = cmplx(pow(generic(LHSRe, LHSIm),
                    generic(RHSRe, RHSIm)));
}

LIBFLANG_ABI void libflang_cpowi(double Re, double Im,
                                 int32_t power,
                                 Complex8 *Result) {
  *Result = cmplx(pow(generic(Re, Im), power));
}
LIBFLANG_ABI void libflang_cpowif(float Re, float Im,
                                  int32_t power,
                                  Complex4 *Result) {
  *Result = cmplx(complex<float>(pow(generic(Re, Im), power)));
}

// intrinsics

LIBFLANG_ABI double libflang_cabs(double Re, double Im) {
  return abs(generic(Re, Im));
}
LIBFLANG_ABI float libflang_cabsf(float Re, float Im) {
  return abs(generic(Re, Im));
}

LIBFLANG_ABI void libflang_csqrt(double Re, double Im,
                                 Complex8 *Result) {
  *Result = cmplx(sqrt(generic(Re, Im)));
}
LIBFLANG_ABI void libflang_csqrtf(float Re, float Im,
                                  Complex4 *Result) {
  *Result = cmplx(sqrt(generic(Re, Im)));
}

LIBFLANG_ABI void libflang_cexp(double Re, double Im,
                                Complex8 *Result) {
  *Result = cmplx(exp(generic(Re, Im)));
}
LIBFLANG_ABI void libflang_cexpf(float Re, float Im,
                                 Complex4 *Result) {
  *Result = cmplx(exp(generic(Re, Im)));
}

LIBFLANG_ABI void libflang_clog(double Re, double Im,
                                Complex8 *Result) {
  *Result = cmplx(log(generic(Re, Im)));
}
LIBFLANG_ABI void libflang_clogf(float Re, float Im,
                                 Complex4 *Result) {
  *Result = cmplx(log(generic(Re, Im)));
}

LIBFLANG_ABI void libflang_csin(double Re, double Im,
                                Complex8 *Result) {
  *Result = cmplx(sin(generic(Re, Im)));
}
LIBFLANG_ABI void libflang_csinf(float Re, float Im,
                                 Complex4 *Result) {
  *Result = cmplx(sin(generic(Re, Im)));
}

LIBFLANG_ABI void libflang_ccos(double Re, double Im,
                                Complex8 *Result) {
  *Result = cmplx(cos(generic(Re, Im)));
}
LIBFLANG_ABI void libflang_ccosf(float Re, float Im,
                                 Complex4 *Result) {
  *Result = cmplx(cos(generic(Re, Im)));
}

LIBFLANG_ABI void libflang_ctan(double Re, double Im,
                                Complex8 *Result) {
  *Result = cmplx(tan(generic(Re, Im)));
}
LIBFLANG_ABI void libflang_ctanf(float Re, float Im,
                                 Complex4 *Result) {
  *Result = cmplx(tan(generic(Re, Im)));
}