1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright © 2021 Keith Packard
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above
14  *    copyright notice, this list of conditions and the following
15  *    disclaimer in the documentation and/or other materials provided
16  *    with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  *    contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #define _GNU_SOURCE
37 #include <stdio.h>
38 #include <math.h>
39 #include <stdlib.h>
40 #ifdef _HAVE_COMPLEX
41 #include <complex.h>
42 #endif
43 
44 double d1, d2, d3;
45 float f1, f2, f3;
46 int i1;
47 long int li1;
48 long long int lli1;
49 
50 #ifdef _HAVE_LONG_DOUBLE
51 long double l1, l2, l3;
52 #endif
53 
54 #ifdef _HAVE_COMPLEX
55 double complex cd1, cd2, cd3;
56 float complex cf1, cf2, cf3;
57 
58 #ifdef _HAVE_LONG_DOUBLE
59 long double complex cl1, cl2, cl3;
60 #endif
61 
62 #endif
63 
64 /*
65  * Touch test to make sure all of the expected math functions exist
66  */
67 
68 int
main(void)69 main(void)
70 {
71     printf("sizeof float %ld double %ld long double %ld\n",
72 	   (long) sizeof(float), (long) sizeof(double), (long) sizeof(long double));
73     d1 = atan (d1);
74     d1 = cos (d1);
75     d1 = sin (d1);
76     d1 = tan (d1);
77     d1 = tanh (d1);
78     d1 = frexp (d1, &i1);
79     d1 = modf (d1, &d2);
80     d1 = ceil (d1);
81     d1 = fabs (d1);
82     d1 = floor (d1);
83     d1 = acos (d1);
84     d1 = asin (d1);
85     d1 = atan2 (d1, d2);
86     d1 = cosh (d1);
87     d1 = sinh (d1);
88     d1 = exp (d1);
89     d1 = ldexp (d1, i1);
90     d1 = log (d1);
91     d1 = log10 (d1);
92     d1 = pow (d1, d2);
93     d1 = sqrt (d1);
94     d1 = fmod (d1, d2);
95 
96     i1 = finite (d1);
97     i1 = finitef (f1);
98 #if defined(_HAVE_BUILTIN_FINITEL) || defined(_HAVE_BUILTIN_ISFINITE)
99     i1 = finitel (l1);
100 #endif
101     i1 = isinff (f1);
102     i1 = isnanf (f1);
103 #ifdef _HAVE_BUILTIN_ISINFL
104     i1 = isinfl (l1);
105 #endif
106 #ifdef _HAVE_BUILTIN_ISNANL
107     i1 = isnanl (l1);
108 #endif
109     i1 = isinf (d1);
110     i1 = isnan (d1);
111 
112     i1 = __isinff (f1);
113     i1 = __isinfd (d1);
114     i1 = __isnanf (f1);
115     i1 = __isnand (d1);
116     i1 = __fpclassifyf (f1);
117     i1 = __fpclassifyd (d1);
118     i1 = __signbitf (f1);
119     i1 = __signbitd (d1);
120 
121 /* Non ANSI double precision functions.  */
122 
123     d1 = infinity ();
124     d1 = nan ("");
125     d1 = copysign (d1, d2);
126     d1 = logb (d1);
127     i1 = ilogb (d1);
128 
129     d1 = asinh (d1);
130     d1 = cbrt (d1);
131     d1 = nextafter (d1, d2);
132     d1 = rint (d1);
133     d1 = scalbn (d1, i1);
134 
135     d1 = exp2 (d1);
136     d1 = scalbln (d1, li1);
137     d1 = tgamma (d1);
138     d1 = nearbyint (d1);
139     li1 = lrint (d1);
140     lli1 = llrint (d1);
141     d1 = round (d1);
142     li1 = lround (d1);
143     lli1 = llround (d1);
144     d1 = trunc (d1);
145     d1 = remquo (d1, d2, &i1);
146     d1 = fdim (d1, d2);
147     d1 = fmax (d1, d2);
148     d1 = fmin (d1, d2);
149     d1 = fma (d1, d2, d3);
150 
151     d1 = log1p (d1);
152     d1 = expm1 (d1);
153 
154     d1 = acosh (d1);
155     d1 = atanh (d1);
156     d1 = remainder (d1, d2);
157     d1 = gamma (d1);
158     d1 = lgamma (d1);
159     d1 = erf (d1);
160     d1 = erfc (d1);
161     d1 = log2 (d1);
162 
163     d1 = hypot (d1, d2);
164 
165 /* Single precision versions of ANSI functions.  */
166 
167     f1 = atanf (f1);
168     f1 = cosf (f1);
169     f1 = sinf (f1);
170     f1 = tanf (f1);
171     f1 = tanhf (f1);
172     f1 = frexpf (f1, &i1);
173     f1 = modff (f1, &f2);
174     f1 = ceilf (f1);
175     f1 = fabsf (f1);
176     f1 = floorf (f1);
177 
178     f1 = acosf (f1);
179     f1 = asinf (f1);
180     f1 = atan2f (f1, f2);
181     f1 = coshf (f1);
182     f1 = sinhf (f1);
183     f1 = expf (f1);
184     f1 = ldexpf (f1, i1);
185     f1 = logf (f1);
186     f1 = log10f (f1);
187     f1 = powf (f1, f2);
188     f1 = sqrtf (f1);
189     f1 = fmodf (f1, f2);
190 
191 /* Other single precision functions.  */
192 
193     f1 = exp2f (f1);
194     f1 = scalblnf (f1, li1);
195     f1 = tgammaf (f1);
196     f1 = nearbyintf (f1);
197     li1 = lrintf (f1);
198     lli1 = llrintf (f1);
199     f1 = roundf (f1);
200     li1 = lroundf (f1);
201     lli1 = llroundf (f1);
202     f1 = truncf (f1);
203     f1 = remquof (f1, f2, &i1);
204     f1 = fdimf (f1, f2);
205     f1 = fmaxf (f1, f2);
206     f1 = fminf (f1, f2);
207     f1 = fmaf (f1, f2, f3);
208 
209     f1 = infinityf ();
210     f1 = nanf ("");
211     f1 = copysignf (f1, f2);
212     f1 = logbf (f1);
213     i1 = ilogbf (f1);
214 
215     f1 = asinhf (f1);
216     f1 = cbrtf (f1);
217     f1 = nextafterf (f1, f2);
218     f1 = rintf (f1);
219     f1 = scalbnf (f1, i1);
220     f1 = log1pf (f1);
221     f1 = expm1f (f1);
222 
223     f1 = acoshf (f1);
224     f1 = atanhf (f1);
225     f1 = remainderf (f1, f2);
226     f1 = gammaf (f1);
227     f1 = lgammaf (f1);
228     f1 = erff (f1);
229     f1 = erfcf (f1);
230     f1 = log2f (f1);
231     f1 = hypotf (f1, f2);
232 
233 #ifdef _HAVE_LONG_DOUBLE
234     l1 = frexpl (l1, &i1);
235     l1 = ldexpl (l1, i1);
236     l1 = sqrtl (l1);
237     l1 = hypotl (l1, l2);
238     l1 = nanl ("");
239     i1 = ilogbl (l1);
240     l1 = logbl (l1);
241     l1 = scalbnl (l1, i1);
242     l1 = scalblnl (l1, li1);
243     l1 = nearbyintl (l1);
244     l1 = rintl (l1);
245     li1 = lrintl (l1);
246     lli1 = llrintl (l1);
247     l1 = roundl (l1);
248     l1 = lroundl (l1);
249     lli1 = llroundl (l1);
250     l1 = truncl (l1);
251     l1 = fmaxl (l1, l2);
252     l1 = fminl (l1, l2);
253     l1 = hypotl (l1, l2);
254     l1 = sqrtl (l1);
255     l1 = fabsl (l1);
256     l1 = copysignl (l1, l2);
257 
258     l1 = ceill (l1);
259     l1 = floorl (l1);
260 
261 #ifdef _HAVE_LONG_DOUBLE_MATH
262     l1 = atanl (l1);
263     l1 = cosl (l1);
264     l1 = sinl (l1);
265     l1 = tanl (l1);
266     l1 = tanhl (l1);
267     l1 = modfl (l1, &l2);
268     l1 = log1pl (l1);
269     l1 = expm1l (l1);
270 
271     l1 = acosl (l1);
272     l1 = asinl (l1);
273     l1 = atan2l (l1, l2);
274     l1 = coshl (l1);
275     l1 = sinhl (l1);
276     l1 = expl (l1);
277     l1 = logl (l1);
278     l1 = log10l (l1);
279     l1 = powl (l1, l2);
280     l1 = fmodl (l1, l2);
281 
282     l1 = asinhl (l1);
283     l1 = cbrtl (l1);
284     l1 = log2l (l1);
285     l1 = exp2l (l1);
286     l1 = tgammal (l1);
287     l1 = remquol (l1, l2, &i1);
288     l1 = fdiml (l1, l2);
289     l1 = fmal (l1, l2, l3);
290     l1 = acoshl (l1);
291     l1 = atanhl (l1);
292     l1 = remainderl (l1, l2);
293     l1 = lgammal (l1);
294     l1 = erfl (l1);
295     l1 = erfcl (l1);
296     f1 = dreml (l1, l2);
297     sincosl (l1, &l2, &l3);
298     l1 = exp10l (l1);
299     l1 = pow10l (l1);
300     f1 = nexttowardf (f1, l1);
301     d1 = nexttoward (d1, l1);
302     l1 = nextafterl (l1, l2);
303     l1 = nexttowardl (l1, l2);
304 #endif /* _HAVE_LONG_DOUBLE_MATH */
305 #endif /* _HAVE_LONG_DOUBLE */
306 
307     d1 = drem (d1, d2);
308     f1 = dremf (f1, f2);
309     d1 = lgamma_r (d1, &i1);
310     f1 = lgammaf_r (f1, &i1);
311 
312     d1 = y0 (d1);
313     d1 = y1 (d1);
314     d1 = yn (i1, d1);
315     d1 = j0 (d1);
316     d1 = j1 (d1);
317     d1 = jn (i1, d1);
318 
319     f1 = y0f (f1);
320     f1 = y1f (f1);
321     f1 = ynf (i1, f2);
322     f1 = j0f (f1);
323     f1 = j1f (f1);
324     f1 = jnf (i1, f2);
325 
326     sincos (d1, &d2, &d3);
327     sincosf (f1, &f2, &f3);
328     d1 = exp10 (d1);
329     d1 = pow10 (d1);
330     f1 = exp10f (f1);
331     f1 = pow10f (f1);
332 
333 #ifdef _HAVE_COMPLEX
334     cd1 = cacos(cd1);
335     cf1 = cacosf(cf1);
336 
337 /* 7.3.5.2 The casin functions */
338     cd1 = casin(cd1);
339     cf1 = casinf(cf1);
340 
341 /* 7.3.5.1 The catan functions */
342     cd1 = catan(cd1);
343     cf1 = catanf(cf1);
344 
345 /* 7.3.5.1 The ccos functions */
346     cd1 = ccos(cd1);
347     cf1 = ccosf(cf1);
348 
349 /* 7.3.5.1 The csin functions */
350     cd1 = csin(cd1);
351     cf1 = csinf(cf1);
352 
353 /* 7.3.5.1 The ctan functions */
354     cd1 = ctan(cd1);
355     cf1 = ctanf(cf1);
356 
357 /* 7.3.6 Hyperbolic functions */
358 /* 7.3.6.1 The cacosh functions */
359     cd1 = cacosh(cd1);
360     cf1 = cacoshf(cf1);
361 
362 /* 7.3.6.2 The casinh functions */
363     cd1 = casinh(cd1);
364     cf1 = casinhf(cf1);
365 
366 /* 7.3.6.3 The catanh functions */
367     cd1 = catanh(cd1);
368     cf1 = catanhf(cf1);
369 
370 /* 7.3.6.4 The ccosh functions */
371     cd1 = ccosh(cd1);
372     cf1 = ccoshf(cf1);
373 
374 /* 7.3.6.5 The csinh functions */
375     cd1 = csinh(cd1);
376     cf1 = csinhf(cf1);
377 
378 /* 7.3.6.6 The ctanh functions */
379     cd1 = ctanh(cd1);
380     cf1 = ctanhf(cf1);
381 
382 /* 7.3.7 Exponential and logarithmic functions */
383 /* 7.3.7.1 The cexp functions */
384     cd1 = cexp(cd1);
385     cf1 = cexpf(cf1);
386 
387 /* 7.3.7.2 The clog functions */
388     cd1 = clog(cd1);
389     cf1 = clogf(cf1);
390 
391 /* 7.3.8 Power and absolute-value functions */
392 /* 7.3.8.1 The cabs functions */
393     d1 = cabs(cd1) ;
394     f1 = cabsf(cf1) ;
395 
396 /* 7.3.8.2 The cpow functions */
397     cd1 = cpow(cd1, cd2);
398     cf1 = cpowf(cf1, cf2);
399 
400 /* 7.3.8.3 The csqrt functions */
401     cd1 = csqrt(cd1);
402     cf1 = csqrtf(cf1);
403 
404 /* 7.3.9 Manipulation functions */
405 /* 7.3.9.1 The carg functions */
406     d1 = carg(cd1);
407     f1 = cargf(cf1);
408 
409 /* 7.3.9.2 The cimag functions */
410     d1 = cimag(cd1);
411     f1 = cimagf(cf1);
412 
413 /* 7.3.9.3 The conj functions */
414     cd1 = conj(cd1);
415     cf1 = conjf(cf1);
416 
417 /* 7.3.9.4 The cproj functions */
418     cd1 = cproj(cd1);
419     cf1 = cprojf(cf1);
420 
421 /* 7.3.9.5 The creal functions */
422     d1 = creal(cd1);
423     f1 = crealf(cf1);
424 
425 #if __GNU_VISIBLE
426     cd1 = clog10(cd1);
427     cf1 = clog10f(cf1);
428 #endif
429 
430 #ifdef _HAVE_LONG_DOUBLE
431     cl1 =  csqrtl(cl1);
432     l1 = cabsl(cl1) ;
433     cl1 = cprojl(cl1);
434     l1 = creall(cl1);
435     cl1 = conjl(cl1);
436     l1 = cimagl(cl1);
437 
438 #ifdef _HAVE_LONG_DOUBLE_MATH
439     l1 = cargl(cl1);
440     cl1 = casinl(cl1);
441     cl1 = cacosl(cl1);
442     cl1 = catanl(cl1);
443     cl1 = ccosl(cl1);
444     cl1 = csinl(cl1);
445     cl1 = ctanl(cl1);
446     cl1 = cacoshl(cl1);
447     cl1 = casinhl(cl1);
448     cl1 = catanhl(cl1);
449     cl1 = ccoshl(cl1);
450     cl1 = csinhl(cl1);
451     cl1 = ctanhl(cl1);
452     cl1 = cexpl(cl1);
453     cl1 = clogl(cl1);
454     cl1 = cpowl(cl1, cl2);
455 #if __GNU_VISIBLE
456     cl1 = clog10l(cl1);
457 #endif
458 #endif /* _HAVE_LONG_DOUBLE_MATH */
459 
460 #endif /* _HAVE_LONG_DOUBLE */
461 
462 #endif /* _HAVE_COMPLEX */
463 
464     return 0;
465 }
466