aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.target/x86_64/abi/test_complex_returning.c
blob: 9e9678d7b024146323f21f8845aaea2260462ef9 (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
/* This is a small test case for returning a complex number. Written by
   Andreas Jaeger.  */

#include "defines.h"


#define BUILD_F_COMPLEX(real, imag) \
  ({ __complex__ float __retval; \
     __real__ __retval = (real); \
     __imag__ __retval = (imag); \
     __retval; })

#define BUILD_D_COMPLEX(real, imag) \
  ({ __complex__ double __retval; \
     __real__ __retval = (real); \
     __imag__ __retval = (imag); \
     __retval; })

#define BUILD_LD_COMPLEX(real, imag) \
  ({ __complex__ long double __retval; \
     __real__ __retval = (real); \
     __imag__ __retval = (imag); \
     __retval; })

__complex__ float
aj_f_times2 (__complex__ float x)
{
  __complex__ float res;

  __real__ res = (2.0 * __real__ x);
  __imag__ res = (2.0 * __imag__ x);

  return res;
}

__complex__ double
aj_d_times2 (__complex__ double x)
{
  __complex__ double res;

  __real__ res = (2.0 * __real__ x);
  __imag__ res = (2.0 * __imag__ x);

  return res;
}

__complex__ long double
aj_ld_times2 (__complex__ long double x)
{
  __complex__ long double res;

  __real__ res = (2.0 * __real__ x);
  __imag__ res = (2.0 * __imag__ x);

  return res;
}

int
main (void)
{
#ifdef CHECK_COMPLEX
  _Complex float fc, fd;
  _Complex double dc, dd;
  _Complex long double ldc, ldd;

  fc = BUILD_LD_COMPLEX (2.0f, 3.0f);
  fd = aj_f_times2 (fc);

  assert (__real__ fd == 4.0f && __imag__ fd == 6.0f);

  dc = BUILD_LD_COMPLEX (2.0, 3.0);
  dd = aj_ld_times2 (dc);

  assert (__real__ dd == 4.0 && __imag__ dd == 6.0);

  ldc = BUILD_LD_COMPLEX (2.0L, 3.0L);
  ldd = aj_ld_times2 (ldc);

  assert (__real__ ldd == 4.0L && __imag__ ldd == 6.0L);
#endif

  return 0;
}