1 /* $OpenBSD: testvectll.c,v 1.5 2022/04/23 16:04:05 mbuhl Exp $ */
2
3 /*
4 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /* Test vectors for math functions.
20 See C9X section F.9.
21
22 On some systems it may be necessary to modify the default exception
23 settings of the floating point arithmetic unit. */
24
25 #include <float.h>
26
27 #if LDBL_MANT_DIG == 113
28 #include <stdio.h>
29 #include <string.h>
30 int __isfinitel (long double);
31
32 /* Some compilers will not accept these expressions. */
33
34 #define ZINF 1
35 #define ZMINF 2
36 #define ZNANL 3
37 #define ZPIL 4
38 #define ZPIO2L 4
39
40 /*
41 extern long double INFINITYL, NANL, NEGZEROL;
42 */
43 extern long double INFINITYL;
44 long double NANL, NEGZEROL;
45 long double MINFL;
46 extern long double PIL, PIO2L, PIO4L, MACHEPL;
47 long double MPIL;
48 long double MPIO2L;
49 long double MPIO4L;
50 long double THPIO4L = 2.35619449019234492884698L;
51 long double MTHPIO4L = -2.35619449019234492884698L;
52 long double SQRT2L = 1.414213562373095048802E0L;
53 long double SQRTHL = 7.071067811865475244008E-1L;
54 long double ZEROL = 0.0L;
55 long double HALFL = 0.5L;
56 long double MHALFL = -0.5L;
57 long double ONEL = 1.0L;
58 long double MONEL = -1.0L;
59 long double TWOL = 2.0L;
60 long double MTWOL = -2.0L;
61 long double THREEL = 3.0L;
62 long double MTHREEL = -3.0L;
63
64 /* Functions of one variable. */
65 long double logl (long double);
66 long double expl (long double);
67 long double atanl (long double);
68 long double sinl (long double);
69 long double cosl (long double);
70 long double tanl (long double);
71 long double acosl (long double);
72 long double asinl (long double);
73 long double acoshl (long double);
74 long double asinhl (long double);
75 long double atanhl (long double);
76 long double sinhl (long double);
77 long double coshl (long double);
78 long double tanhl (long double);
79 long double exp2l (long double);
80 long double expm1l (long double);
81 long double log10l (long double);
82 long double log1pl (long double);
83 long double log2l (long double);
84 long double fabsl (long double);
85 long double erfl (long double);
86 long double erfcl (long double);
87 long double tgammal (long double);
88 long double floorl (long double);
89 long double ceill (long double);
90 long double cbrtl (long double);
91 long double lgammal (long double);
92
93 struct oneargument
94 {
95 char *name; /* Name of the function. */
96 long double (*func) (long double);
97 long double *arg1;
98 long double *answer;
99 int thresh; /* Error report threshold. */
100 };
101
102 #if 0
103 {"sinl", sinl, 32767.L, 1.8750655394138942394239E-1L, 0},
104 {"cosl", cosl, 32767.L, 9.8226335176928229845654E-1L, 0},
105 {"tanl", tanl, 32767.L, 1.9089234430221485740826E-1L, 0},
106 {"sinl", sinl, 8388607.L, 9.9234509376961249835628E-1L, 0},
107 {"cosl", cosl, 8388607.L, -1.2349580912475928183718E-1L, 0},
108 {"tanl", tanl, 8388607.L, -8.0354556223613614748329E0L, 0},
109 {"sinl", sinl, 2147483647.L, -7.2491655514455639054829E-1L, 0},
110 {"cosl", cosl, 2147483647.L, -6.8883669187794383467976E-1L, 0},
111 {"tanl", tanl, 2147483647.L, 1.0523779637351339136698E0L, 0},
112 {"sinl", sinl, PIO4L, 7.0710678118654752440084E-1L, 0},
113 {"cosl", cosl, PIO2L, -2.50827880633416613471e-20L, 0},
114 #endif
115
116 static struct oneargument test1[] =
117 {
118 {"atanl", atanl, &ONEL, &PIO4L, 0},
119 {"sinl", sinl, &PIO2L, &ONEL, 0},
120 {"cosl", cosl, &PIO4L, &SQRTHL, 0},
121 {"acosl", acosl, &NANL, &NANL, 0},
122 {"acosl", acosl, &ONEL, &ZEROL, 0},
123 {"acosl", acosl, &TWOL, &NANL, 0},
124 {"acosl", acosl, &MTWOL, &NANL, 0},
125 {"asinl", asinl, &NANL, &NANL, 0},
126 {"asinl", asinl, &ZEROL, &ZEROL, 0},
127 {"asinl", asinl, &NEGZEROL, &NEGZEROL, 0},
128 {"asinl", asinl, &TWOL, &NANL, 0},
129 {"asinl", asinl, &MTWOL, &NANL, 0},
130 {"atanl", atanl, &NANL, &NANL, 0},
131 {"atanl", atanl, &ZEROL, &ZEROL, 0},
132 {"atanl", atanl, &NEGZEROL, &NEGZEROL, 0},
133 {"atanl", atanl, &INFINITYL, &PIO2L, 0},
134 {"atanl", atanl, &MINFL, &MPIO2L, 0},
135 {"cosl", cosl, &NANL, &NANL, 0},
136 {"cosl", cosl, &ZEROL, &ONEL, 0},
137 {"cosl", cosl, &NEGZEROL, &ONEL, 0},
138 {"cosl", cosl, &INFINITYL, &NANL, 0},
139 {"cosl", cosl, &MINFL, &NANL, 0},
140 {"sinl", sinl, &NANL, &NANL, 0},
141 {"sinl", sinl, &NEGZEROL, &NEGZEROL, 0},
142 {"sinl", sinl, &ZEROL, &ZEROL, 0},
143 {"sinl", sinl, &INFINITYL, &NANL, 0},
144 {"sinl", sinl, &MINFL, &NANL, 0},
145 {"tanl", tanl, &NANL, &NANL, 0},
146 {"tanl", tanl, &ZEROL, &ZEROL, 0},
147 {"tanl", tanl, &NEGZEROL, &NEGZEROL, 0},
148 {"tanl", tanl, &INFINITYL, &NANL, 0},
149 {"tanl", tanl, &MINFL, &NANL, 0},
150 {"acoshl", acoshl, &NANL, &NANL, 0},
151 {"acoshl", acoshl, &ONEL, &ZEROL, 0},
152 {"acoshl", acoshl, &INFINITYL, &INFINITYL, 0},
153 {"acoshl", acoshl, &HALFL, &NANL, 0},
154 {"acoshl", acoshl, &MONEL, &NANL, 0},
155 {"asinhl", asinhl, &NANL, &NANL, 0},
156 {"asinhl", asinhl, &ZEROL, &ZEROL, 0},
157 {"asinhl", asinhl, &NEGZEROL, &NEGZEROL, 0},
158 {"asinhl", asinhl, &INFINITYL, &INFINITYL, 0},
159 {"asinhl", asinhl, &MINFL, &MINFL, 0},
160 {"atanhl", atanhl, &NANL, &NANL, 0},
161 {"atanhl", atanhl, &ZEROL, &ZEROL, 0},
162 {"atanhl", atanhl, &NEGZEROL, &NEGZEROL, 0},
163 {"atanhl", atanhl, &ONEL, &INFINITYL, 0},
164 {"atanhl", atanhl, &MONEL, &MINFL, 0},
165 {"atanhl", atanhl, &TWOL, &NANL, 0},
166 {"atanhl", atanhl, &MTWOL, &NANL, 0},
167 {"coshl", coshl, &NANL, &NANL, 0},
168 {"coshl", coshl, &ZEROL, &ONEL, 0},
169 {"coshl", coshl, &NEGZEROL, &ONEL, 0},
170 {"coshl", coshl, &INFINITYL, &INFINITYL, 0},
171 {"coshl", coshl, &MINFL, &INFINITYL, 0},
172 {"sinhl", sinhl, &NANL, &NANL, 0},
173 {"sinhl", sinhl, &ZEROL, &ZEROL, 0},
174 {"sinhl", sinhl, &NEGZEROL, &NEGZEROL, 0},
175 {"sinhl", sinhl, &INFINITYL, &INFINITYL, 0},
176 {"sinhl", sinhl, &MINFL, &MINFL, 0},
177 {"tanhl", tanhl, &NANL, &NANL, 0},
178 {"tanhl", tanhl, &ZEROL, &ZEROL, 0},
179 {"tanhl", tanhl, &NEGZEROL, &NEGZEROL, 0},
180 {"tanhl", tanhl, &INFINITYL, &ONEL, 0},
181 {"tanhl", tanhl, &MINFL, &MONEL, 0},
182 {"expl", expl, &NANL, &NANL, 0},
183 {"expl", expl, &ZEROL, &ONEL, 0},
184 {"expl", expl, &NEGZEROL, &ONEL, 0},
185 {"expl", expl, &INFINITYL, &INFINITYL, 0},
186 {"expl", expl, &MINFL, &ZEROL, 0},
187 {"exp2l", exp2l, &NANL, &NANL, 0},
188 {"exp2l", exp2l, &ZEROL, &ONEL, 0},
189 {"exp2l", exp2l, &NEGZEROL, &ONEL, 0},
190 {"exp2l", exp2l, &INFINITYL, &INFINITYL, 0},
191 {"exp2l", exp2l, &MINFL, &ZEROL, 0},
192 {"expm1l", expm1l, &NANL, &NANL, 0},
193 {"expm1l", expm1l, &ZEROL, &ZEROL, 0},
194 {"expm1l", expm1l, &NEGZEROL, &NEGZEROL, 0},
195 {"expm1l", expm1l, &INFINITYL, &INFINITYL, 0},
196 {"expm1l", expm1l, &MINFL, &MONEL, 0},
197 {"logl", logl, &NANL, &NANL, 0},
198 {"logl", logl, &ZEROL, &MINFL, 0},
199 {"logl", logl, &NEGZEROL, &MINFL, 0},
200 {"logl", logl, &ONEL, &ZEROL, 0},
201 {"logl", logl, &MONEL, &NANL, 0},
202 {"logl", logl, &INFINITYL, &INFINITYL, 0},
203 {"log10l", log10l, &NANL, &NANL, 0},
204 {"log10l", log10l, &ZEROL, &MINFL, 0},
205 {"log10l", log10l, &NEGZEROL, &MINFL, 0},
206 {"log10l", log10l, &ONEL, &ZEROL, 0},
207 {"log10l", log10l, &MONEL, &NANL, 0},
208 {"log10l", log10l, &INFINITYL, &INFINITYL, 0},
209 {"log1pl", log1pl, &NANL, &NANL, 0},
210 {"log1pl", log1pl, &ZEROL, &ZEROL, 0},
211 {"log1pl", log1pl, &NEGZEROL, &NEGZEROL, 0},
212 {"log1pl", log1pl, &MONEL, &MINFL, 0},
213 {"log1pl", log1pl, &MTWOL, &NANL, 0},
214 {"log1pl", log1pl, &INFINITYL, &INFINITYL, 0},
215 {"log2l", log2l, &NANL, &NANL, 0},
216 {"log2l", log2l, &ZEROL, &MINFL, 0},
217 {"log2l", log2l, &NEGZEROL, &MINFL, 0},
218 {"log2l", log2l, &MONEL, &NANL, 0},
219 {"log2l", log2l, &INFINITYL, &INFINITYL, 0},
220 /* {"fabsl", fabsl, &NANL, &NANL, 0}, */
221 {"fabsl", fabsl, &ONEL, &ONEL, 0},
222 {"fabsl", fabsl, &MONEL, &ONEL, 0},
223 {"fabsl", fabsl, &ZEROL, &ZEROL, 0},
224 {"fabsl", fabsl, &NEGZEROL, &ZEROL, 0},
225 {"fabsl", fabsl, &INFINITYL, &INFINITYL, 0},
226 {"fabsl", fabsl, &MINFL, &INFINITYL, 0},
227 {"cbrtl", cbrtl, &NANL, &NANL, 0},
228 {"cbrtl", cbrtl, &ZEROL, &ZEROL, 0},
229 {"cbrtl", cbrtl, &NEGZEROL, &NEGZEROL, 0},
230 {"cbrtl", cbrtl, &INFINITYL, &INFINITYL, 0},
231 {"cbrtl", cbrtl, &MINFL, &MINFL, 0},
232 {"erfl", erfl, &NANL, &NANL, 0},
233 {"erfl", erfl, &ZEROL, &ZEROL, 0},
234 {"erfl", erfl, &NEGZEROL, &NEGZEROL, 0},
235 {"erfl", erfl, &INFINITYL, &ONEL, 0},
236 {"erfl", erfl, &MINFL, &MONEL, 0},
237 {"erfcl", erfcl, &NANL, &NANL, 0},
238 {"erfcl", erfcl, &INFINITYL, &ZEROL, 0},
239 {"erfcl", erfcl, &MINFL, &TWOL, 0},
240 {"tgammal", tgammal, &NANL, &NANL, 0},
241 {"tgammal", tgammal, &INFINITYL, &INFINITYL, 0},
242 {"tgammal", tgammal, &MONEL, &NANL, 0},
243 {"tgammal", tgammal, &ZEROL, &INFINITYL, 0},
244 {"tgammal", tgammal, &MINFL, &NANL, 0},
245 {"lgammal", lgammal, &NANL, &NANL, 0},
246 {"lgammal", lgammal, &INFINITYL, &INFINITYL, 0},
247 {"lgammal", lgammal, &MONEL, &INFINITYL, 0},
248 {"lgammal", lgammal, &ZEROL, &INFINITYL, 0},
249 {"lgammal", lgammal, &MINFL, &INFINITYL, 0},
250 {"ceill", ceill, &NANL, &NANL, 0},
251 {"ceill", ceill, &ZEROL, &ZEROL, 0},
252 {"ceill", ceill, &NEGZEROL, &NEGZEROL, 0},
253 {"ceill", ceill, &INFINITYL, &INFINITYL, 0},
254 {"ceill", ceill, &MINFL, &MINFL, 0},
255 {"floorl", floorl, &NANL, &NANL, 0},
256 {"floorl", floorl, &ZEROL, &ZEROL, 0},
257 {"floorl", floorl, &NEGZEROL, &NEGZEROL, 0},
258 {"floorl", floorl, &INFINITYL, &INFINITYL, 0},
259 {"floorl", floorl, &MINFL, &MINFL, 0},
260 {"null", NULL, &ZEROL, &ZEROL, 0},
261 };
262
263 /* Functions of two variables. */
264 long double atan2l (long double, long double);
265 long double powl (long double, long double);
266
267 struct twoarguments
268 {
269 char *name; /* Name of the function. */
270 long double (*func) (long double, long double);
271 long double *arg1;
272 long double *arg2;
273 long double *answer;
274 int thresh;
275 };
276
277 static struct twoarguments test2[] =
278 {
279 {"atan2l", atan2l, &ZEROL, &ONEL, &ZEROL, 0},
280 {"atan2l", atan2l, &NEGZEROL, &ONEL,&NEGZEROL, 0},
281 {"atan2l", atan2l, &ZEROL, &ZEROL, &ZEROL, 0},
282 {"atan2l", atan2l, &NEGZEROL, &ZEROL, &NEGZEROL, 0},
283 {"atan2l", atan2l, &ZEROL, &MONEL, &PIL, 0},
284 {"atan2l", atan2l, &NEGZEROL, &MONEL, &MPIL, 0},
285 {"atan2l", atan2l, &ZEROL, &NEGZEROL, &PIL, 0},
286 {"atan2l", atan2l, &NEGZEROL, &NEGZEROL, &MPIL, 0},
287 {"atan2l", atan2l, &ONEL, &ZEROL, &PIO2L, 0},
288 {"atan2l", atan2l, &ONEL, &NEGZEROL, &PIO2L, 0},
289 {"atan2l", atan2l, &MONEL, &ZEROL, &MPIO2L, 0},
290 {"atan2l", atan2l, &MONEL, &NEGZEROL, &MPIO2L, 0},
291 {"atan2l", atan2l, &ONEL, &INFINITYL, &ZEROL, 0},
292 {"atan2l", atan2l, &MONEL, &INFINITYL, &NEGZEROL, 0},
293 {"atan2l", atan2l, &INFINITYL, &ONEL, &PIO2L, 0},
294 {"atan2l", atan2l, &INFINITYL, &MONEL, &PIO2L, 0},
295 {"atan2l", atan2l, &MINFL, &ONEL, &MPIO2L, 0},
296 {"atan2l", atan2l, &MINFL, &MONEL, &MPIO2L, 0},
297 {"atan2l", atan2l, &ONEL, &MINFL, &PIL, 0},
298 {"atan2l", atan2l, &MONEL, &MINFL, &MPIL, 0},
299 {"atan2l", atan2l, &INFINITYL, &INFINITYL, &PIO4L, 0},
300 {"atan2l", atan2l, &MINFL, &INFINITYL, &MPIO4L, 0},
301 {"atan2l", atan2l, &INFINITYL, &MINFL, &THPIO4L, 0},
302 {"atan2l", atan2l, &MINFL, &MINFL, &MTHPIO4L, 0},
303 {"atan2l", atan2l, &ONEL, &ONEL, &PIO4L, 0},
304 {"atan2l", atan2l, &NANL, &ONEL, &NANL, 0},
305 {"atan2l", atan2l, &ONEL, &NANL, &NANL, 0},
306 {"atan2l", atan2l, &NANL, &NANL, &NANL, 0},
307 {"powl", powl, &ONEL, &ZEROL, &ONEL, 0},
308 {"powl", powl, &ONEL, &NEGZEROL, &ONEL, 0},
309 {"powl", powl, &MONEL, &ZEROL, &ONEL, 0},
310 {"powl", powl, &MONEL, &NEGZEROL, &ONEL, 0},
311 {"powl", powl, &INFINITYL, &ZEROL, &ONEL, 0},
312 {"powl", powl, &INFINITYL, &NEGZEROL, &ONEL, 0},
313 {"powl", powl, &NANL, &ZEROL, &ONEL, 0},
314 {"powl", powl, &NANL, &NEGZEROL, &ONEL, 0},
315 {"powl", powl, &TWOL, &INFINITYL, &INFINITYL, 0},
316 {"powl", powl, &MTWOL, &INFINITYL, &INFINITYL, 0},
317 {"powl", powl, &HALFL, &INFINITYL, &ZEROL, 0},
318 {"powl", powl, &MHALFL, &INFINITYL, &ZEROL, 0},
319 {"powl", powl, &TWOL, &MINFL, &ZEROL, 0},
320 {"powl", powl, &MTWOL, &MINFL, &ZEROL, 0},
321 {"powl", powl, &HALFL, &MINFL, &INFINITYL, 0},
322 {"powl", powl, &MHALFL, &MINFL, &INFINITYL, 0},
323 {"powl", powl, &INFINITYL, &HALFL, &INFINITYL, 0},
324 {"powl", powl, &INFINITYL, &TWOL, &INFINITYL, 0},
325 {"powl", powl, &INFINITYL, &MHALFL, &ZEROL, 0},
326 {"powl", powl, &INFINITYL, &MTWOL, &ZEROL, 0},
327 {"powl", powl, &MINFL, &THREEL, &MINFL, 0},
328 {"powl", powl, &MINFL, &TWOL, &INFINITYL, 0},
329 {"powl", powl, &MINFL, &MTHREEL, &NEGZEROL, 0},
330 {"powl", powl, &MINFL, &MTWOL, &ZEROL, 0},
331 {"powl", powl, &NANL, &ONEL, &NANL, 0},
332 {"powl", powl, &ONEL, &NANL, &ONEL, 0},
333 {"powl", powl, &NANL, &NANL, &NANL, 0},
334 {"powl", powl, &ONEL, &INFINITYL, &ONEL, 0},
335 {"powl", powl, &MONEL, &INFINITYL, &ONEL, 0},
336 {"powl", powl, &ONEL, &MINFL, &ONEL, 0},
337 {"powl", powl, &MONEL, &MINFL, &ONEL, 0},
338 {"powl", powl, &MTWOL, &HALFL, &NANL, 0},
339 {"powl", powl, &ZEROL, &MTHREEL, &INFINITYL, 0},
340 {"powl", powl, &NEGZEROL, &MTHREEL, &MINFL, 0},
341 {"powl", powl, &ZEROL, &MHALFL, &INFINITYL, 0},
342 {"powl", powl, &NEGZEROL, &MHALFL, &INFINITYL, 0},
343 {"powl", powl, &ZEROL, &THREEL, &ZEROL, 0},
344 {"powl", powl, &NEGZEROL, &THREEL, &NEGZEROL, 0},
345 {"powl", powl, &ZEROL, &HALFL, &ZEROL, 0},
346 {"powl", powl, &NEGZEROL, &HALFL, &ZEROL, 0},
347 {"null", NULL, &ZEROL, &ZEROL, &ZEROL, 0},
348 };
349
350 /* Integer functions of one variable. */
351
352 int __isnanl (long double);
353 int __signbitl (long double);
354
355 struct intans
356 {
357 char *name; /* Name of the function. */
358 int (*func) (long double);
359 long double *arg1;
360 int ianswer;
361 };
362
363 static struct intans test3[] =
364 {
365 {"isfinitel", __isfinitel, &ZEROL, 1},
366 {"isfinitel", __isfinitel, &INFINITYL, 0},
367 {"isfinitel", __isfinitel, &MINFL, 0},
368 {"isnanl", __isnanl, &NANL, 1},
369 {"isnanl", __isnanl, &INFINITYL, 0},
370 {"isnanl", __isnanl, &ZEROL, 0},
371 {"isnanl", __isnanl, &NEGZEROL, 0},
372 {"signbitl", __signbitl, &NEGZEROL, 1},
373 {"signbitl", __signbitl, &MONEL, 1},
374 {"signbitl", __signbitl, &ZEROL, 0},
375 {"signbitl", __signbitl, &ONEL, 0},
376 {"signbitl", __signbitl, &MINFL, 1},
377 {"signbitl", __signbitl, &INFINITYL, 0},
378 {"null", NULL, &ZEROL, 0},
379 };
380
381 static volatile long double x1;
382 static volatile long double x2;
383 static volatile long double y;
384 static volatile long double answer;
385
386 /* Print bits of a long double. */
pvec(char * str,long double x)387 static void pvec (char *str, long double x)
388 {
389 union
390 {
391 long double d;
392 unsigned int i[4];
393 } u;
394 int i;
395
396 u.d = x;
397 printf ("%s ", str);
398 for (i = 0; i < 4; i++)
399 printf ("%08x ", u.i[i]);
400 printf ("\n");
401 }
402
403 int
testvectll()404 testvectll ()
405 {
406 int i, nerrors, k, ianswer, ntests;
407 long double (*fun1) (long double);
408 long double (*fun2) (long double, long double);
409 int (*fun3) (long double);
410 long double e;
411 union
412 {
413 long double d;
414 char c[16];
415 } u, v;
416
417 INFINITYL = ONEL/ZEROL;
418 pvec ("Infinity = ", INFINITYL);
419 NANL = INFINITYL - INFINITYL;
420 pvec ("Nan = ", NANL);
421 NEGZEROL = -ZEROL;
422 pvec ("-0.0 = ", NEGZEROL);
423 /* This masks off fpu exceptions on i386. */
424 /* setfpu(0x137f); */
425 nerrors = 0;
426 ntests = 0;
427 MINFL = -INFINITYL;
428 MPIL = -PIL;
429 MPIO2L = -PIO2L;
430 MPIO4L = -PIO4L;
431 i = 0;
432 for (;;)
433 {
434 fun1 = test1[i].func;
435 if (fun1 == NULL)
436 break;
437 x1 = *(test1[i].arg1);
438 y = (*(fun1)) (x1);
439 answer = *(test1[i].answer);
440 if (test1[i].thresh == 0)
441 {
442 v.d = answer;
443 u.d = y;
444 if (memcmp(u.c, v.c, 16) != 0)
445 {
446 /* O.K. if both are NaNs of some sort. */
447 if (__isnanl(v.d) && __isnanl(u.d))
448 goto nxttest1;
449 goto wrongone;
450 }
451 else
452 goto nxttest1;
453 }
454 if (y != answer)
455 {
456 e = y - answer;
457 if (answer != 0.0L)
458 e = e / answer;
459 if (e < 0)
460 e = -e;
461 if (e > test1[i].thresh * MACHEPL)
462 {
463 wrongone:
464 printf ("%s (%.20Le) = %.20Le\n should be %.20Le\n",
465 test1[i].name, x1, y, answer);
466 nerrors += 1;
467 }
468 }
469 nxttest1:
470 ntests += 1;
471 i += 1;
472 }
473
474 i = 0;
475 for (;;)
476 {
477 fun2 = test2[i].func;
478 if (fun2 == NULL)
479 break;
480 x1 = *(test2[i].arg1);
481 x2 = *(test2[i].arg2);
482 y = (*(fun2)) (x1, x2);
483 answer = *(test2[i].answer);
484 if (test2[i].thresh == 0)
485 {
486 v.d = answer;
487 u.d = y;
488 if (memcmp(u.c, v.c, 16) != 0)
489 {
490 /* O.K. if both are NaNs of some sort. */
491 if (__isnanl(v.d) && __isnanl(u.d))
492 goto nxttest2;
493 goto wrongtwo;
494 }
495 else
496 goto nxttest2;
497 }
498 if (y != answer)
499 {
500 e = y - answer;
501 if (answer != 0.0L)
502 e = e / answer;
503 if (e < 0)
504 e = -e;
505 if (e > test2[i].thresh * MACHEPL)
506 {
507 wrongtwo:
508 printf ("%s (%.20Le, %.20Le) = %.20Le\n should be %.20Le\n",
509 test2[i].name, x1, x2, y, answer);
510 nerrors += 1;
511 }
512 }
513 nxttest2:
514 ntests += 1;
515 i += 1;
516 }
517
518
519 i = 0;
520 for (;;)
521 {
522 fun3 = test3[i].func;
523 if (fun3 == NULL)
524 break;
525 x1 = *(test3[i].arg1);
526 k = (*(fun3)) (x1);
527 ianswer = test3[i].ianswer;
528 if (k != ianswer)
529 {
530 printf ("%s (%.20Le) = %d\n should be. %d\n",
531 test3[i].name, x1, k, ianswer);
532 nerrors += 1;
533 }
534 ntests += 1;
535 i += 1;
536 }
537
538 printf ("%d errors in %d tests\n", nerrors, ntests);
539 return (nerrors);
540 }
541 #endif /* LDBL_MANT_DIG == 113 */
542