]>
git.ipfire.org Git - thirdparty/glibc.git/blob - math/test-tgmath.c
c1cd3fc4576509213f0a16bb40f79f91df15a1ab
1 /* Test compilation of tgmath macros.
2 Copyright (C) 2001-2025 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)
235 a
= cospi (cospi (x
));
236 b
= acospi (acospi (a
));
239 b
= sinpi (sinpi (x
));
240 b
= asinpi (asinpi (a
));
243 b
= tanpi (tanpi (x
));
244 b
= atanpi (atanpi (a
));
246 c
= atan2 (atan2 (a
, c
), atan2 (b
, x
));
247 b
= atan2pi (atan2pi (a
, c
), atan2pi (b
, x
));
249 b
= acosh (acosh (a
));
251 b
= asinh (asinh (a
));
253 b
= atanh (atanh (a
));
256 a
= log10 (log10 (x
));
257 b
= ldexp (ldexp (a
, 1), 5);
258 a
= frexp (frexp (x
, &i
), &i
);
259 b
= expm1 (expm1 (a
));
260 a
= exp2m1 (exp2m1 (b
));
261 b
= exp10m1 (exp10m1 (a
));
262 a
= log1p (log1p (x
));
265 a
= exp10 (exp10 (x
));
267 a
= log2p1 (log2p1 (x
));
268 a
= log10p1 (log10p1 (x
));
269 a
= logp1 (logp1 (x
));
270 a
= pow (pow (x
, a
), pow (c
, b
));
271 b
= pown (pown (x
, k
), k
);
272 b
= compoundn (compoundn (x
, k
), k
);
273 b
= rootn (rootn (x
, k
), k
);
274 a
= powr (powr (x
, a
), powr (c
, b
));
276 a
= rsqrt (rsqrt (b
));
277 a
= hypot (hypot (x
, b
), hypot (c
, a
));
281 a
= floor (floor (x
));
282 b
= fmod (fmod (a
, b
), fmod (c
, x
));
283 a
= nearbyint (nearbyint (x
));
284 b
= round (round (a
));
285 c
= roundeven (roundeven (a
));
286 a
= trunc (trunc (x
));
287 b
= remquo (remquo (a
, b
, &i
), remquo (c
, x
, &i
), &i
);
288 j
= lrint (x
) + lround (a
);
289 k
= llrint (b
) + llround (c
);
290 m
= fromfp (a
, FP_INT_UPWARD
, 2) + fromfpx (b
, FP_INT_DOWNWARD
, 3);
291 um
= ufromfp (c
, FP_INT_TONEAREST
, 4) + ufromfpx (a
, FP_INT_TOWARDZERO
, 5);
294 a
= tgamma (tgamma (x
));
295 b
= lgamma (lgamma (a
));
297 b
= nextafter (nextafter (a
, b
), nextafter (c
, x
));
298 a
= nextdown (nextdown (a
));
299 b
= nexttoward (nexttoward (x
, a
), c
);
300 a
= nextup (nextup (a
));
301 b
= remainder (remainder (a
, b
), remainder (c
, x
));
302 a
= scalb (scalb (x
, a
), (TYPE
) (6));
303 k
= scalbn (a
, 7) + scalbln (c
, 10l);
306 a
= fdim (fdim (x
, a
), fdim (c
, b
));
307 b
= fmax (fmax (a
, x
), fmax (c
, b
));
308 a
= fmin (fmin (x
, a
), fmin (c
, b
));
309 b
= fmaxmag (fmaxmag (a
, x
), fmaxmag (c
, b
));
310 a
= fminmag (fminmag (x
, a
), fminmag (c
, b
));
311 b
= fmaximum (fmaximum (a
, x
), fmaximum (c
, b
));
312 a
= fminimum (fminimum (x
, a
), fminimum (c
, b
));
313 b
= fmaximum_num (fmaximum_num (a
, x
), fmaximum_num (c
, b
));
314 a
= fminimum_num (fminimum_num (x
, a
), fminimum_num (c
, b
));
315 b
= fmaximum_mag (fmaximum_mag (a
, x
), fmaximum_mag (c
, b
));
316 a
= fminimum_mag (fminimum_mag (x
, a
), fminimum_mag (c
, b
));
317 b
= fmaximum_mag_num (fmaximum_mag_num (a
, x
), fmaximum_mag_num (c
, b
));
318 a
= fminimum_mag_num (fminimum_mag_num (x
, a
), fminimum_mag_num (c
, b
));
319 b
= fma (sin (a
), sin (x
), sin (c
));
323 b
= remquo (i
, a
, &i
);
327 x
= a
+ b
+ c
+ i
+ j
+ k
+ m
+ um
;
340 z
= acosh (acosh (d
));
342 z
= asinh (asinh (d
));
344 z
= atanh (atanh (d
));
350 z
= pow (pow (a
, d
), pow (b
, z
));
351 d
= cproj (cproj (z
));
352 z
+= fabs (cproj (a
));
354 b
= creal (creal (d
));
355 c
= cimag (cimag (z
));
356 x
+= a
+ b
+ c
+ i
+ j
+ k
;
359 if (saved_count
!= count
)
402 a
= compoundn (y
, 12345);
403 a
= rootn (y
, 12345);
417 a
= remquo (y
, y
, &i
);
418 j
= lrint (y
) + lround (y
);
419 k
= llrint (y
) + llround (y
);
420 m
= fromfp (y
, FP_INT_UPWARD
, 6) + fromfpx (y
, FP_INT_DOWNWARD
, 7);
421 um
= (ufromfp (y
, FP_INT_TONEAREST
, 8)
422 + ufromfpx (y
, FP_INT_TOWARDZERO
, 9));
428 a
= nextafter (y
, y
);
429 a
= nexttoward (y
, y
);
430 a
= remainder (y
, y
);
431 a
= scalb (y
, (const TYPE
) (6));
432 k
= scalbn (y
, 7) + scalbln (y
, 10l);
442 a
= fmaximum_num (y
, y
);
443 a
= fminimum_num (y
, y
);
444 a
= fmaximum_mag (y
, y
);
445 a
= fminimum_mag (y
, y
);
446 a
= fmaximum_mag_num (y
, y
);
447 a
= fminimum_mag_num (y
, y
);
452 a
= remquo (i
, y
, &i
);
457 d
= cos ((const complex TYPE
) z
);
458 d
= acos ((const complex TYPE
) z
);
459 d
= sin ((const complex TYPE
) z
);
460 d
= asin ((const complex TYPE
) z
);
461 d
= tan ((const complex TYPE
) z
);
462 d
= atan ((const complex TYPE
) z
);
463 d
= cosh ((const complex TYPE
) z
);
464 d
= acosh ((const complex TYPE
) z
);
465 d
= sinh ((const complex TYPE
) z
);
466 d
= asinh ((const complex TYPE
) z
);
467 d
= tanh ((const complex TYPE
) z
);
468 d
= atanh ((const complex TYPE
) z
);
469 d
= exp ((const complex TYPE
) z
);
470 d
= log ((const complex TYPE
) z
);
471 d
= sqrt ((const complex TYPE
) z
);
472 d
= pow ((const complex TYPE
) z
, (const complex TYPE
) z
);
473 d
= fabs ((const complex TYPE
) z
);
474 d
= carg ((const complex TYPE
) z
);
475 d
= creal ((const complex TYPE
) z
);
476 d
= cimag ((const complex TYPE
) z
);
477 d
= conj ((const complex TYPE
) z
);
478 d
= cproj ((const complex TYPE
) z
);
575 (F(atan2
)) (TYPE x
, TYPE y
)
591 (F(atan2pi
)) (TYPE x
, TYPE y
)
671 (F(ldexp
)) (TYPE x
, int y
)
679 (F(frexp
)) (TYPE x
, int *y
)
703 (F(exp10m1
)) (TYPE x
)
759 (F(log10p1
)) (TYPE x
)
775 (F(pow
)) (TYPE x
, TYPE y
)
783 (F(pown
)) (TYPE x
, long long int y
)
791 (F(powr
)) (TYPE x
, TYPE y
)
799 (F(compoundn
)) (TYPE x
, long long int y
)
807 (F(rootn
)) (TYPE x
, long long int y
)
831 (F(hypot
)) (TYPE x
, TYPE y
)
871 (F(fmod
)) (TYPE x
, TYPE y
)
879 (F(nearbyint
)) (TYPE x
)
895 (F(roundeven
)) (TYPE x
)
911 (F(remquo
)) (TYPE x
, TYPE y
, int *i
)
943 (F(llround
)) (TYPE x
)
951 (F(fromfp
)) (TYPE x
, int round
, unsigned int width
)
959 (F(fromfpx
)) (TYPE x
, int round
, unsigned int width
)
967 (F(ufromfp
)) (TYPE x
, int round
, unsigned int width
)
975 (F(ufromfpx
)) (TYPE x
, int round
, unsigned int width
)
1007 (F(lgamma
)) (TYPE x
)
1023 (F(nextafter
)) (TYPE x
, TYPE y
)
1031 (F(nextdown
)) (TYPE x
)
1039 (F(nexttoward
)) (TYPE x
, long double y
)
1047 (F(nextup
)) (TYPE x
)
1055 (F(remainder
)) (TYPE x
, TYPE y
)
1063 (F(scalb
)) (TYPE x
, TYPE y
)
1071 (F(scalbn
)) (TYPE x
, int y
)
1079 (F(scalbln
)) (TYPE x
, long int y
)
1103 (F(fdim
)) (TYPE x
, TYPE y
)
1111 (F(fmin
)) (TYPE x
, TYPE y
)
1119 (F(fmax
)) (TYPE x
, TYPE y
)
1127 (F(fminmag
)) (TYPE x
, TYPE y
)
1135 (F(fmaxmag
)) (TYPE x
, TYPE y
)
1143 (F(fminimum
)) (TYPE x
, TYPE y
)
1151 (F(fmaximum
)) (TYPE x
, TYPE y
)
1159 (F(fminimum_num
)) (TYPE x
, TYPE y
)
1167 (F(fmaximum_num
)) (TYPE x
, TYPE y
)
1175 (F(fminimum_mag
)) (TYPE x
, TYPE y
)
1183 (F(fmaximum_mag
)) (TYPE x
, TYPE y
)
1191 (F(fminimum_mag_num
)) (TYPE x
, TYPE y
)
1199 (F(fmaximum_mag_num
)) (TYPE x
, TYPE y
)
1207 (F(fma
)) (TYPE x
, TYPE y
, TYPE z
)
1215 (F(cacos
)) (complex TYPE x
)
1223 (F(casin
)) (complex TYPE x
)
1231 (F(catan
)) (complex TYPE x
)
1239 (F(ccos
)) (complex TYPE x
)
1247 (F(csin
)) (complex TYPE x
)
1255 (F(ctan
)) (complex TYPE x
)
1263 (F(cacosh
)) (complex TYPE x
)
1271 (F(casinh
)) (complex TYPE x
)
1279 (F(catanh
)) (complex TYPE x
)
1287 (F(ccosh
)) (complex TYPE x
)
1295 (F(csinh
)) (complex TYPE x
)
1303 (F(ctanh
)) (complex TYPE x
)
1311 (F(cexp
)) (complex TYPE x
)
1319 (F(clog
)) (complex TYPE x
)
1327 (F(csqrt
)) (complex TYPE x
)
1335 (F(cpow
)) (complex TYPE x
, complex TYPE y
)
1343 (F(cabs
)) (complex TYPE x
)
1351 (F(carg
)) (complex TYPE x
)
1359 (F(creal
)) (complex TYPE x
)
1367 (F(cimag
)) (complex TYPE x
)
1375 (F(conj
)) (complex TYPE x
)
1383 (F(cproj
)) (complex TYPE x
)