2018-06-09 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / libgomp / testsuite / libgomp.hsa.c / complex-1.c
blob438c64a1593cd2f4c47b70d18ebe837a25bf056c
1 #include <assert.h>
2 #include <complex.h>
3 #include <math.h>
5 #define uchar unsigned char
6 #define C 123
8 #define TEST(type) \
9 type foo_##type (void) \
10 { \
11 _Complex type a = C + 45I; \
12 return __real__ a; \
15 #pragma omp declare target
16 TEST (char)
17 TEST (uchar)
18 TEST (short)
19 TEST (int)
21 float
22 bar (float a, float b)
24 _Complex float c = a + b * I;
26 c += 11.f + 12.f * I;
28 _Complex float d = 2.f + 4.44f * I;
30 return __real__(crealf (c + d) + cimag (d) * I);
33 #pragma omp end declare target
35 int
36 main (void)
38 int v = 0;
39 float v2 = 0.0f;
41 #pragma omp target map(to: v)
42 v = foo_char ();
44 assert (v == C);
46 #pragma omp target map(to: v)
47 v = foo_uchar ();
49 assert (v == C);
51 #pragma omp target map(to: v)
52 v = foo_short ();
54 assert (v == C);
56 #pragma omp target map(to: v)
57 v = foo_int ();
59 assert (v == C);
61 #pragma omp target map(to: v2)
62 v2 = bar (1.12f, 4.44f);
64 assert (fabs (v2 - 14.12) < 0.0001f);