Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/ieee/cdivchkld.c

raw
1 /*
2 Program to test complex divide for correct results on selected values.
3 Checking known failure points.
4 */
5
6 #include <float.h>
7
8 extern void abort (void);
9 extern void exit (int);
10
11 extern int ilogbl (long double);
12 int match (long double _Complex,long double _Complex);
13
14 #define SMALL LDBL_MIN
15 #define MAXBIT LDBL_MANT_DIG
16 #define ERRLIM 6
17
18 /*
19 Compare c (computed value) with z (expected value).
20 Return 0 if within allowed range. Return 1 if not.
21 */
22 int match (long double _Complex c,long double _Complex z)
23 {
24 long double rz, iz, rc, ic;
25 long double rerr, ierr, rmax;
26 int biterr;
27 rz = __real__ z;
28 iz = __imag__ z;
29 rc = __real__ c;
30 ic = __imag__ c;
31
32 if (__builtin_fabsl (rz) > SMALL)
33 {
34 rerr = __builtin_fabsl (rz - rc) / __builtin_fabsl(rz);
35 }
36 else if (__builtin_fabsl (rz) == 0.0)
37 {
38 rerr = __builtin_fabsl (rc);
39 }
40 else
41 {
42 rerr = __builtin_fabsl (rz - rc) / SMALL;
43 }
44
45 if (__builtin_fabsl (iz) > SMALL)
46 {
47 ierr = __builtin_fabsl (iz - ic) / __builtin_fabsl(iz);
48 }
49 else if (__builtin_fabsl (iz) == 0.0)
50 {
51 ierr = __builtin_fabsl (ic);
52 }
53 else
54 {
55 ierr = __builtin_fabsl (iz - ic) / SMALL;
56 }
57 rmax = __builtin_fmaxl (rerr, ierr);
58 biterr = 0;
59 if ( rmax != 0.0)
60 {
61 biterr = ilogbl (rmax) + MAXBIT + 1;
62 }
63
64 if (biterr >= ERRLIM)
65 return 0;
66 else
67 return 1;
68 }
69
70
71 int main (int argc, char** argv)
72 {
73 long double _Complex a,b,c,z;
74 long double xr[4], xi[4], yr[4], yi[4], zr[4], zi[4];
75 long double cr, ci;
76 int i;
77 int ok = 1;
78
79 #if (LDBL_MAX_EXP < 2048)
80 /*
81 Test values when mantissa is 11 or fewer bits. Either LDBL is
82 using DBL on this platform or we are using IBM extended double
83 precision. Test values will be automatically truncated when
84 the available precision is smaller than the explicit precision.
85 */
86 xr[0] = -0x1.16e7fad79e45ep+651;
87 xi[0] = -0x1.f7f75b94c6c6ap-860;
88 yr[0] = -0x1.2f40d8ff7e55ep+245;
89 yi[0] = -0x0.0000000004ebcp-968;
90 zr[0] = 0x1.d6e4b0e2828694570ba839070beep+405L;
91 zi[0] = -0x1.e9095e311e70498db810196259b7p-846L;
92
93 xr[1] = -0x1.21ff587f953d3p-310;
94 xi[1] = -0x1.5a526dcc59960p+837;
95 yr[1] = 0x1.b88b8b552eaadp+735;
96 yi[1] = -0x1.873e2d6544d92p-327;
97 zr[1] = 0x1.65734a88b2ddff699c482ee8eef6p-961L;
98 zi[1] = -0x1.927e85b8b576f94a797a1bcb733dp+101L;
99
100 xr[2] = 0x1.4612e41aa8080p-846;
101 xi[2] = -0x0.0000000613e07p-968;
102 yr[2] = 0x1.df9cd0d58caafp-820;
103 yi[2] = -0x1.e47051a9036dbp-584;
104 zr[2] = 0x1.9b194f3aaadea545174c5372d8p-415L;
105 zi[2] = 0x1.58a00ab740a6ad3249002f2b79p-263L;
106
107 xr[3] = 0x1.cb27eece7c585p-355;
108 xi[3] = 0x0.000000223b8a8p-968;
109 yr[3] = -0x1.74e7ed2b9189fp-22;
110 yi[3] = 0x1.3d80439e9a119p-731;
111 zr[3] = -0x1.3b35ed806ae5a2a8cc1c9a96931dp-333L;
112 zi[3] = -0x1.7802c17c774895bd541adeb200p-974L;
113 #else
114 /*
115 Test values intended for either IEEE128 or Intel80 formats. In
116 either case, 15 bits of exponent are available. Test values will
117 be automatically truncated when the available precision is smaller
118 than the explicit precision.
119 */
120 xr[0] = -0x9.c793985b7d029d90p-8480L;
121 xi[0] = 0x8.018745ffa61a8fe0p+16329L;
122 yr[0] = -0xe.d5bee9c523a35ad0p-15599L;
123 yi[0] = -0xa.8c93c5a4f94128f0p+869L;
124 zr[0] = -0x1.849178451c035b95d16311d0efdap+15459L;
125 zi[0] = -0x1.11375ed2c1f58b9d047ab64aed97p-1008L;
126
127 xr[1] = 0xb.68e44bc6d0b91a30p+16026L;
128 xi[1] = 0xb.ab10f5453e972f30p-14239L;
129 yr[1] = 0x8.8cbd470705428ff0p-16350L;
130 yi[1] = -0xa.0c1cbeae4e4b69f0p+347L;
131 zr[1] = 0x1.eec40848785e500d9f0945ab58d3p-1019L;
132 zi[1] = 0x1.22b6b579927a3f238b772bb6dc95p+15679L;
133
134 xr[2] = -0x9.e8c093a43b546a90p+15983L;
135 xi[2] = 0xc.95b18274208311e0p-2840L;
136 yr[2] = -0x8.dedb729b5c1b2ec0p+8L;
137 yi[2] = 0xa.a49fb81b24738370p-16385L;
138 zr[2] = 0x1.1df99ee89bb118f3201369e06576p+15975L;
139 zi[2] = 0x1.571e7ef904d6b6eee7acb0dcf098p-418L;
140
141 xr[3] = 0xc.4687f251c0f48bd0p-3940L;
142 xi[3] = -0xe.a3f2138992d85fa0p+15598L;
143 yr[3] = 0xe.4b0c25c3d5ebb830p-16344L;
144 yi[3] = -0xa.6cbf1ba80f7b97a0p+78L;
145 zr[3] = 0x1.6785ba23bfb744cee97b4142348bp+15520L;
146 zi[3] = -0x1.ecee7b8c7bdd36237eb538324289p-902L;
147 #endif
148
149 for (i = 0; i < 4; i++)
150 {
151 __real__ a = xr[i];
152 __imag__ a = xi[i];
153 __real__ b = yr[i];
154 __imag__ b = yi[i];
155 __real__ z = zr[i];
156 __imag__ z = zi[i];
157 c = a / b;
158 cr = __real__ c;
159 ci = __imag__ c;
160
161 if (!match (c,z)){
162 ok = 0;
163 }
164 }
165 if (!ok)
166 abort ();
167 exit (0);
168 }