File: builtin-complex-1.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (124 lines) | stat: -rw-r--r-- 2,785 bytes parent folder | download | duplicates (8)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Test __builtin_complex semantics.  */
/* { dg-do run } */
/* { dg-options "-std=c11 -pedantic-errors" } */
/* { dg-add-options ieee } */

extern void exit (int);
extern void abort (void);

#define COMPARE_BODY(A, B, TYPE, COPYSIGN)				\
  do {									\
    TYPE s1 = COPYSIGN ((TYPE) 1.0, A);					\
    TYPE s2 = COPYSIGN ((TYPE) 1.0, B);					\
    if (s1 != s2)							\
      abort ();								\
    if ((__builtin_isnan (A) != 0) != (__builtin_isnan (B) != 0))	\
      abort ();								\
    if ((A != B) != (__builtin_isnan (A) != 0))				\
      abort ();								\
  } while (0)

#ifndef __SPU__
void
comparef (float a, float b)
{
  COMPARE_BODY (a, b, float, __builtin_copysignf);
}
#endif

void
compare (double a, double b)
{
  COMPARE_BODY (a, b, double, __builtin_copysign);
}

void
comparel (long double a, long double b)
{
  COMPARE_BODY (a, b, long double, __builtin_copysignl);
}

#ifndef __SPU__
void
comparecf (_Complex float a, float r, float i)
{
  comparef (__real__ a, r);
  comparef (__imag__ a, i);
}
#endif

void
comparec (_Complex double a, double r, double i)
{
  compare (__real__ a, r);
  compare (__imag__ a, i);
}

void
comparecl (_Complex long double a, long double r, long double i)
{
  comparel (__real__ a, r);
  comparel (__imag__ a, i);
}

#define VERIFY(A, B, TYPE, COMPARE)			\
  do {							\
    TYPE a = A;						\
    TYPE b = B;						\
    _Complex TYPE cr = __builtin_complex (a, b);	\
    static _Complex TYPE cs = __builtin_complex (A, B);	\
    COMPARE (cr, A, B);					\
    COMPARE (cs, A, B);					\
  } while (0)

#define ALL_CHECKS(PZ, NZ, NAN, INF, TYPE, COMPARE)	\
  do {							\
    VERIFY (PZ, PZ, TYPE, COMPARE);			\
    VERIFY (PZ, NZ, TYPE, COMPARE);			\
    VERIFY (PZ, NAN, TYPE, COMPARE);			\
    VERIFY (PZ, INF, TYPE, COMPARE);			\
    VERIFY (NZ, PZ, TYPE, COMPARE);			\
    VERIFY (NZ, NZ, TYPE, COMPARE);			\
    VERIFY (NZ, NAN, TYPE, COMPARE);			\
    VERIFY (NZ, INF, TYPE, COMPARE);			\
    VERIFY (NAN, PZ, TYPE, COMPARE);			\
    VERIFY (NAN, NZ, TYPE, COMPARE);			\
    VERIFY (NAN, NAN, TYPE, COMPARE);			\
    VERIFY (NAN, INF, TYPE, COMPARE);			\
    VERIFY (INF, PZ, TYPE, COMPARE);			\
    VERIFY (INF, NZ, TYPE, COMPARE);			\
    VERIFY (INF, NAN, TYPE, COMPARE);			\
    VERIFY (INF, INF, TYPE, COMPARE);			\
  } while (0)

void
check_float (void)
{
#ifndef __SPU__
  ALL_CHECKS (0.0f, -0.0f, __builtin_nanf(""), __builtin_inff(),
	      float, comparecf);
#endif
}

void
check_double (void)
{
  ALL_CHECKS (0.0, -0.0, __builtin_nan(""), __builtin_inf(),
	      double, comparec);
}

void
check_long_double (void)
{
  ALL_CHECKS (0.0l, -0.0l, __builtin_nanl(""), __builtin_infl(),
	      long double, comparecl);
}

int
main (void)
{
  check_float ();
  check_double ();
  check_long_double ();
  exit (0);
}