1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
28 static void compile_test (void);
29 static void compile_testf (void);
30 #if LDBL_MANT_DIG > DBL_MANT_DIG
31 static void compile_testl (void);
37 const float fy
= 1.25;
38 const double dy
= 1.25;
39 const long double ly
= 1.25;
42 complex long double lz
;
44 volatile int count_double
;
45 volatile int count_float
;
46 volatile int count_ldouble
;
47 volatile int count_cdouble
;
48 volatile int count_cfloat
;
49 volatile int count_cldouble
;
60 count_float
= count_double
= count_ldouble
= 0;
61 count_cfloat
= count_cdouble
= count_cldouble
= 0;
63 if (count_float
!= 0 || count_cfloat
!= 0)
65 puts ("float function called for double test");
68 if (count_ldouble
!= 0 || count_cldouble
!= 0)
70 puts ("long double function called for double test");
73 if (count_double
< NCALLS
+ NCALLS_INT
)
75 printf ("double functions not called often enough (%d)\n",
79 else if (count_double
> NCALLS
+ NCALLS_INT
)
81 printf ("double functions called too often (%d)\n",
85 if (count_cdouble
< NCCALLS
)
87 printf ("double complex functions not called often enough (%d)\n",
91 else if (count_cdouble
> NCCALLS
)
93 printf ("double complex functions called too often (%d)\n",
98 count_float
= count_double
= count_ldouble
= 0;
99 count_cfloat
= count_cdouble
= count_cldouble
= 0;
101 if (count_double
!= 0 || count_cdouble
!= 0)
103 puts ("double function called for float test");
106 if (count_ldouble
!= 0 || count_cldouble
!= 0)
108 puts ("long double function called for float test");
111 if (count_float
< NCALLS
)
113 printf ("float functions not called often enough (%d)\n", count_float
);
116 else if (count_float
> NCALLS
)
118 printf ("float functions called too often (%d)\n",
122 if (count_cfloat
< NCCALLS
)
124 printf ("float complex functions not called often enough (%d)\n",
128 else if (count_cfloat
> NCCALLS
)
130 printf ("float complex functions called too often (%d)\n",
135 #if LDBL_MANT_DIG > DBL_MANT_DIG
136 count_float
= count_double
= count_ldouble
= 0;
137 count_cfloat
= count_cdouble
= count_cldouble
= 0;
139 if (count_float
!= 0 || count_cfloat
!= 0)
141 puts ("float function called for long double test");
144 if (count_double
!= 0 || count_cdouble
!= 0)
146 puts ("double function called for long double test");
149 if (count_ldouble
< NCALLS
)
151 printf ("long double functions not called often enough (%d)\n",
155 else if (count_ldouble
> NCALLS
)
157 printf ("long double functions called too often (%d)\n",
161 if (count_cldouble
< NCCALLS
)
163 printf ("long double complex functions not called often enough (%d)\n",
167 else if (count_cldouble
> NCCALLS
)
169 printf ("long double complex functions called too often (%d)\n",
178 /* Now generate the three functions. */
187 #define count count_double
188 #define ccount count_cdouble
189 #include "test-tgmath.c"
191 #define F(name) name##f
196 #define count count_float
197 #define ccount count_cfloat
198 #include "test-tgmath.c"
200 #if LDBL_MANT_DIG > DBL_MANT_DIG
201 #define F(name) name##l
202 #define TYPE long double
206 #define count count_ldouble
207 #define ccount count_cldouble
208 #include "test-tgmath.c"
211 #define TEST_FUNCTION do_test ()
212 #include "../test-skeleton.c"
217 #define P() puts (__FUNCTION__)
223 F(compile_test
) (void)
240 c
= atan2 (atan2 (a
, c
), atan2 (b
, x
));
242 b
= acosh (acosh (a
));
244 b
= asinh (asinh (a
));
246 b
= atanh (atanh (a
));
249 a
= log10 (log10 (x
));
250 b
= ldexp (ldexp (a
, 1), 5);
251 a
= frexp (frexp (x
, &i
), &i
);
252 b
= expm1 (expm1 (a
));
253 a
= exp2m1 (exp2m1 (b
));
254 b
= exp10m1 (exp10m1 (a
));
255 a
= log1p (log1p (x
));
258 a
= exp10 (exp10 (x
));
260 a
= log2p1 (log2p1 (x
));
261 a
= log10p1 (log10p1 (x
));
262 a
= logp1 (logp1 (x
));
263 a
= pow (pow (x
, a
), pow (c
, b
));
265 a
= hypot (hypot (x
, b
), hypot (c
, a
));
269 a
= floor (floor (x
));
270 b
= fmod (fmod (a
, b
), fmod (c
, x
));
271 a
= nearbyint (nearbyint (x
));
272 b
= round (round (a
));
273 c
= roundeven (roundeven (a
));
274 a
= trunc (trunc (x
));
275 b
= remquo (remquo (a
, b
, &i
), remquo (c
, x
, &i
), &i
);
276 j
= lrint (x
) + lround (a
);
277 k
= llrint (b
) + llround (c
);
278 m
= fromfp (a
, FP_INT_UPWARD
, 2) + fromfpx (b
, FP_INT_DOWNWARD
, 3);
279 um
= ufromfp (c
, FP_INT_TONEAREST
, 4) + ufromfpx (a
, FP_INT_TOWARDZERO
, 5);
282 a
= tgamma (tgamma (x
));
283 b
= lgamma (lgamma (a
));
285 b
= nextafter (nextafter (a
, b
), nextafter (c
, x
));
286 a
= nextdown (nextdown (a
));
287 b
= nexttoward (nexttoward (x
, a
), c
);
288 a
= nextup (nextup (a
));
289 b
= remainder (remainder (a
, b
), remainder (c
, x
));
290 a
= scalb (scalb (x
, a
), (TYPE
) (6));
291 k
= scalbn (a
, 7) + scalbln (c
, 10l);
294 a
= fdim (fdim (x
, a
), fdim (c
, b
));
295 b
= fmax (fmax (a
, x
), fmax (c
, b
));
296 a
= fmin (fmin (x
, a
), fmin (c
, b
));
297 b
= fmaxmag (fmaxmag (a
, x
), fmaxmag (c
, b
));
298 a
= fminmag (fminmag (x
, a
), fminmag (c
, b
));
299 b
= fmaximum (fmaximum (a
, x
), fmaximum (c
, b
));
300 a
= fminimum (fminimum (x
, a
), fminimum (c
, b
));
301 b
= fmaximum_num (fmaximum_num (a
, x
), fmaximum_num (c
, b
));
302 a
= fminimum_num (fminimum_num (x
, a
), fminimum_num (c
, b
));
303 b
= fmaximum_mag (fmaximum_mag (a
, x
), fmaximum_mag (c
, b
));
304 a
= fminimum_mag (fminimum_mag (x
, a
), fminimum_mag (c
, b
));
305 b
= fmaximum_mag_num (fmaximum_mag_num (a
, x
), fmaximum_mag_num (c
, b
));
306 a
= fminimum_mag_num (fminimum_mag_num (x
, a
), fminimum_mag_num (c
, b
));
307 b
= fma (sin (a
), sin (x
), sin (c
));
311 b
= remquo (i
, a
, &i
);
315 x
= a
+ b
+ c
+ i
+ j
+ k
+ m
+ um
;
328 z
= acosh (acosh (d
));
330 z
= asinh (asinh (d
));
332 z
= atanh (atanh (d
));
338 z
= pow (pow (a
, d
), pow (b
, z
));
339 d
= cproj (cproj (z
));
340 z
+= fabs (cproj (a
));
342 b
= creal (creal (d
));
343 c
= cimag (cimag (z
));
344 x
+= a
+ b
+ c
+ i
+ j
+ k
;
347 if (saved_count
!= count
)
393 a
= remquo (y
, y
, &i
);
394 j
= lrint (y
) + lround (y
);
395 k
= llrint (y
) + llround (y
);
396 m
= fromfp (y
, FP_INT_UPWARD
, 6) + fromfpx (y
, FP_INT_DOWNWARD
, 7);
397 um
= (ufromfp (y
, FP_INT_TONEAREST
, 8)
398 + ufromfpx (y
, FP_INT_TOWARDZERO
, 9));
404 a
= nextafter (y
, y
);
405 a
= nexttoward (y
, y
);
406 a
= remainder (y
, y
);
407 a
= scalb (y
, (const TYPE
) (6));
408 k
= scalbn (y
, 7) + scalbln (y
, 10l);
418 a
= fmaximum_num (y
, y
);
419 a
= fminimum_num (y
, y
);
420 a
= fmaximum_mag (y
, y
);
421 a
= fminimum_mag (y
, y
);
422 a
= fmaximum_mag_num (y
, y
);
423 a
= fminimum_mag_num (y
, y
);
428 a
= remquo (i
, y
, &i
);
433 d
= cos ((const complex TYPE
) z
);
434 d
= acos ((const complex TYPE
) z
);
435 d
= sin ((const complex TYPE
) z
);
436 d
= asin ((const complex TYPE
) z
);
437 d
= tan ((const complex TYPE
) z
);
438 d
= atan ((const complex TYPE
) z
);
439 d
= cosh ((const complex TYPE
) z
);
440 d
= acosh ((const complex TYPE
) z
);
441 d
= sinh ((const complex TYPE
) z
);
442 d
= asinh ((const complex TYPE
) z
);
443 d
= tanh ((const complex TYPE
) z
);
444 d
= atanh ((const complex TYPE
) z
);
445 d
= exp ((const complex TYPE
) z
);
446 d
= log ((const complex TYPE
) z
);
447 d
= sqrt ((const complex TYPE
) z
);
448 d
= pow ((const complex TYPE
) z
, (const complex TYPE
) z
);
449 d
= fabs ((const complex TYPE
) z
);
450 d
= carg ((const complex TYPE
) z
);
451 d
= creal ((const complex TYPE
) z
);
452 d
= cimag ((const complex TYPE
) z
);
453 d
= conj ((const complex TYPE
) z
);
454 d
= cproj ((const complex TYPE
) z
);
511 (F(atan2
)) (TYPE x
, TYPE y
)
591 (F(ldexp
)) (TYPE x
, int y
)
599 (F(frexp
)) (TYPE x
, int *y
)
623 (F(exp10m1
)) (TYPE x
)
679 (F(log10p1
)) (TYPE x
)
695 (F(pow
)) (TYPE x
, TYPE y
)
711 (F(hypot
)) (TYPE x
, TYPE y
)
751 (F(fmod
)) (TYPE x
, TYPE y
)
759 (F(nearbyint
)) (TYPE x
)
775 (F(roundeven
)) (TYPE x
)
791 (F(remquo
)) (TYPE x
, TYPE y
, int *i
)
823 (F(llround
)) (TYPE x
)
831 (F(fromfp
)) (TYPE x
, int round
, unsigned int width
)
839 (F(fromfpx
)) (TYPE x
, int round
, unsigned int width
)
847 (F(ufromfp
)) (TYPE x
, int round
, unsigned int width
)
855 (F(ufromfpx
)) (TYPE x
, int round
, unsigned int width
)
903 (F(nextafter
)) (TYPE x
, TYPE y
)
911 (F(nextdown
)) (TYPE x
)
919 (F(nexttoward
)) (TYPE x
, long double y
)
935 (F(remainder
)) (TYPE x
, TYPE y
)
943 (F(scalb
)) (TYPE x
, TYPE y
)
951 (F(scalbn
)) (TYPE x
, int y
)
959 (F(scalbln
)) (TYPE x
, long int y
)
983 (F(fdim
)) (TYPE x
, TYPE y
)
991 (F(fmin
)) (TYPE x
, TYPE y
)
999 (F(fmax
)) (TYPE x
, TYPE y
)
1007 (F(fminmag
)) (TYPE x
, TYPE y
)
1015 (F(fmaxmag
)) (TYPE x
, TYPE y
)
1023 (F(fminimum
)) (TYPE x
, TYPE y
)
1031 (F(fmaximum
)) (TYPE x
, TYPE y
)
1039 (F(fminimum_num
)) (TYPE x
, TYPE y
)
1047 (F(fmaximum_num
)) (TYPE x
, TYPE y
)
1055 (F(fminimum_mag
)) (TYPE x
, TYPE y
)
1063 (F(fmaximum_mag
)) (TYPE x
, TYPE y
)
1071 (F(fminimum_mag_num
)) (TYPE x
, TYPE y
)
1079 (F(fmaximum_mag_num
)) (TYPE x
, TYPE y
)
1087 (F(fma
)) (TYPE x
, TYPE y
, TYPE z
)
1095 (F(cacos
)) (complex TYPE x
)
1103 (F(casin
)) (complex TYPE x
)
1111 (F(catan
)) (complex TYPE x
)
1119 (F(ccos
)) (complex TYPE x
)
1127 (F(csin
)) (complex TYPE x
)
1135 (F(ctan
)) (complex TYPE x
)
1143 (F(cacosh
)) (complex TYPE x
)
1151 (F(casinh
)) (complex TYPE x
)
1159 (F(catanh
)) (complex TYPE x
)
1167 (F(ccosh
)) (complex TYPE x
)
1175 (F(csinh
)) (complex TYPE x
)
1183 (F(ctanh
)) (complex TYPE x
)
1191 (F(cexp
)) (complex TYPE x
)
1199 (F(clog
)) (complex TYPE x
)
1207 (F(csqrt
)) (complex TYPE x
)
1215 (F(cpow
)) (complex TYPE x
, complex TYPE y
)
1223 (F(cabs
)) (complex TYPE x
)
1231 (F(carg
)) (complex TYPE x
)
1239 (F(creal
)) (complex TYPE x
)
1247 (F(cimag
)) (complex TYPE x
)
1255 (F(conj
)) (complex TYPE x
)
1263 (F(cproj
)) (complex TYPE x
)