1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <math.h>
11
12 #include <math.h>
13 #include <type_traits>
14 #include <cassert>
15
16 #include "hexfloat.h"
17
test_acos()18 void test_acos()
19 {
20 static_assert((std::is_same<decltype(acos((double)0)), double>::value), "");
21 static_assert((std::is_same<decltype(acosf(0)), float>::value), "");
22 static_assert((std::is_same<decltype(acosl(0)), long double>::value), "");
23 assert(acos(1) == 0);
24 }
25
test_asin()26 void test_asin()
27 {
28 static_assert((std::is_same<decltype(asin((double)0)), double>::value), "");
29 static_assert((std::is_same<decltype(asinf(0)), float>::value), "");
30 static_assert((std::is_same<decltype(asinl(0)), long double>::value), "");
31 assert(asin(0) == 0);
32 }
33
test_atan()34 void test_atan()
35 {
36 static_assert((std::is_same<decltype(atan((double)0)), double>::value), "");
37 static_assert((std::is_same<decltype(atanf(0)), float>::value), "");
38 static_assert((std::is_same<decltype(atanl(0)), long double>::value), "");
39 assert(atan(0) == 0);
40 }
41
test_atan2()42 void test_atan2()
43 {
44 static_assert((std::is_same<decltype(atan2((double)0, (double)0)), double>::value), "");
45 static_assert((std::is_same<decltype(atan2f(0,0)), float>::value), "");
46 static_assert((std::is_same<decltype(atan2l(0,0)), long double>::value), "");
47 assert(atan2(0,1) == 0);
48 }
49
test_ceil()50 void test_ceil()
51 {
52 static_assert((std::is_same<decltype(ceil((double)0)), double>::value), "");
53 static_assert((std::is_same<decltype(ceilf(0)), float>::value), "");
54 static_assert((std::is_same<decltype(ceill(0)), long double>::value), "");
55 assert(ceil(0) == 0);
56 }
57
test_cos()58 void test_cos()
59 {
60 static_assert((std::is_same<decltype(cos((double)0)), double>::value), "");
61 static_assert((std::is_same<decltype(cosf(0)), float>::value), "");
62 static_assert((std::is_same<decltype(cosl(0)), long double>::value), "");
63 assert(cos(0) == 1);
64 }
65
test_cosh()66 void test_cosh()
67 {
68 static_assert((std::is_same<decltype(cosh((double)0)), double>::value), "");
69 static_assert((std::is_same<decltype(coshf(0)), float>::value), "");
70 static_assert((std::is_same<decltype(coshl(0)), long double>::value), "");
71 assert(cosh(0) == 1);
72 }
73
test_exp()74 void test_exp()
75 {
76 static_assert((std::is_same<decltype(exp((double)0)), double>::value), "");
77 static_assert((std::is_same<decltype(expf(0)), float>::value), "");
78 static_assert((std::is_same<decltype(expl(0)), long double>::value), "");
79 assert(exp(0) == 1);
80 }
81
test_fabs()82 void test_fabs()
83 {
84 static_assert((std::is_same<decltype(fabs((double)0)), double>::value), "");
85 static_assert((std::is_same<decltype(fabsf(0.f)), float>::value), "");
86 static_assert((std::is_same<decltype(fabsl(0.L)), long double>::value), "");
87 assert(fabs(-1.f) == 1);
88 }
89
test_floor()90 void test_floor()
91 {
92 static_assert((std::is_same<decltype(floor((double)0)), double>::value), "");
93 static_assert((std::is_same<decltype(floorf(0)), float>::value), "");
94 static_assert((std::is_same<decltype(floorl(0)), long double>::value), "");
95 assert(floor(1) == 1);
96 }
97
test_fmod()98 void test_fmod()
99 {
100 static_assert((std::is_same<decltype(fmod((double)0, (double)0)), double>::value), "");
101 static_assert((std::is_same<decltype(fmodf(0,0)), float>::value), "");
102 static_assert((std::is_same<decltype(fmodl(0,0)), long double>::value), "");
103 assert(fmod(1.5,1) == .5);
104 }
105
test_frexp()106 void test_frexp()
107 {
108 int ip;
109 static_assert((std::is_same<decltype(frexp((double)0, &ip)), double>::value), "");
110 static_assert((std::is_same<decltype(frexpf(0, &ip)), float>::value), "");
111 static_assert((std::is_same<decltype(frexpl(0, &ip)), long double>::value), "");
112 assert(frexp(0, &ip) == 0);
113 }
114
test_ldexp()115 void test_ldexp()
116 {
117 int ip = 1;
118 static_assert((std::is_same<decltype(ldexp((double)0, ip)), double>::value), "");
119 static_assert((std::is_same<decltype(ldexpf(0, ip)), float>::value), "");
120 static_assert((std::is_same<decltype(ldexpl(0, ip)), long double>::value), "");
121 assert(ldexp(1, ip) == 2);
122 }
123
test_log()124 void test_log()
125 {
126 static_assert((std::is_same<decltype(log((double)0)), double>::value), "");
127 static_assert((std::is_same<decltype(logf(0)), float>::value), "");
128 static_assert((std::is_same<decltype(logl(0)), long double>::value), "");
129 assert(log(1) == 0);
130 }
131
test_log10()132 void test_log10()
133 {
134 static_assert((std::is_same<decltype(log10((double)0)), double>::value), "");
135 static_assert((std::is_same<decltype(log10f(0)), float>::value), "");
136 static_assert((std::is_same<decltype(log10l(0)), long double>::value), "");
137 assert(log10(1) == 0);
138 }
139
test_modf()140 void test_modf()
141 {
142 static_assert((std::is_same<decltype(modf((double)0, (double*)0)), double>::value), "");
143 static_assert((std::is_same<decltype(modff(0, (float*)0)), float>::value), "");
144 static_assert((std::is_same<decltype(modfl(0, (long double*)0)), long double>::value), "");
145 double i;
146 assert(modf(1., &i) == 0);
147 }
148
test_pow()149 void test_pow()
150 {
151 static_assert((std::is_same<decltype(pow((double)0, (double)0)), double>::value), "");
152 static_assert((std::is_same<decltype(powf(0,0)), float>::value), "");
153 static_assert((std::is_same<decltype(powl(0,0)), long double>::value), "");
154 assert(pow(1,1) == 1);
155 }
156
test_sin()157 void test_sin()
158 {
159 static_assert((std::is_same<decltype(sin((double)0)), double>::value), "");
160 static_assert((std::is_same<decltype(sinf(0)), float>::value), "");
161 static_assert((std::is_same<decltype(sinl(0)), long double>::value), "");
162 assert(sin(0) == 0);
163 }
164
test_sinh()165 void test_sinh()
166 {
167 static_assert((std::is_same<decltype(sinh((double)0)), double>::value), "");
168 static_assert((std::is_same<decltype(sinhf(0)), float>::value), "");
169 static_assert((std::is_same<decltype(sinhl(0)), long double>::value), "");
170 assert(sinh(0) == 0);
171 }
172
test_sqrt()173 void test_sqrt()
174 {
175 static_assert((std::is_same<decltype(sqrt((double)0)), double>::value), "");
176 static_assert((std::is_same<decltype(sqrtf(0)), float>::value), "");
177 static_assert((std::is_same<decltype(sqrtl(0)), long double>::value), "");
178 assert(sqrt(4) == 2);
179 }
180
test_tan()181 void test_tan()
182 {
183 static_assert((std::is_same<decltype(tan((double)0)), double>::value), "");
184 static_assert((std::is_same<decltype(tanf(0)), float>::value), "");
185 static_assert((std::is_same<decltype(tanl(0)), long double>::value), "");
186 assert(tan(0) == 0);
187 }
188
test_tanh()189 void test_tanh()
190 {
191 static_assert((std::is_same<decltype(tanh((double)0)), double>::value), "");
192 static_assert((std::is_same<decltype(tanhf(0)), float>::value), "");
193 static_assert((std::is_same<decltype(tanhl(0)), long double>::value), "");
194 assert(tanh(0) == 0);
195 }
196
test_signbit()197 void test_signbit()
198 {
199 static_assert((std::is_same<decltype(signbit((float)0)), bool>::value), "");
200 static_assert((std::is_same<decltype(signbit((double)0)), bool>::value), "");
201 static_assert((std::is_same<decltype(signbit((long double)0)), bool>::value), "");
202 assert(signbit(-1.0) == true);
203 }
204
test_fpclassify()205 void test_fpclassify()
206 {
207 static_assert((std::is_same<decltype(fpclassify((float)0)), int>::value), "");
208 static_assert((std::is_same<decltype(fpclassify((double)0)), int>::value), "");
209 static_assert((std::is_same<decltype(fpclassify((long double)0)), int>::value), "");
210 assert(fpclassify(-1.0) == FP_NORMAL);
211 }
212
test_isfinite()213 void test_isfinite()
214 {
215 static_assert((std::is_same<decltype(isfinite((float)0)), bool>::value), "");
216 static_assert((std::is_same<decltype(isfinite((double)0)), bool>::value), "");
217 static_assert((std::is_same<decltype(isfinite((long double)0)), bool>::value), "");
218 assert(isfinite(-1.0) == true);
219 }
220
test_isinf()221 void test_isinf()
222 {
223 static_assert((std::is_same<decltype(isinf((float)0)), bool>::value), "");
224 #if !(defined(__ANDROID__) && (__LP64__ || __ANDROID_API__ >= 21))
225 // 64-bit bionic isinf(double) returns int.
226 static_assert((std::is_same<decltype(isinf((double)0)), bool>::value), "");
227 #endif
228 static_assert((std::is_same<decltype(isinf((long double)0)), bool>::value), "");
229 assert(isinf(-1.0) == false);
230 }
231
test_isnan()232 void test_isnan()
233 {
234 static_assert((std::is_same<decltype(isnan((float)0)), bool>::value), "");
235 #if !defined(__ANDROID__)
236 // bionic isnan(double) returns int. Not sure how isnan(float) and isnan(long double) pass.
237 // Mask this check to reveal/fix more seirous one: eg. lack of log2 and nettoward, etc
238 static_assert((std::is_same<decltype(isnan((double)0)), bool>::value), "");
239 #endif
240 static_assert((std::is_same<decltype(isnan((long double)0)), bool>::value), "");
241 assert(isnan(-1.0) == false);
242 }
243
test_isnormal()244 void test_isnormal()
245 {
246 static_assert((std::is_same<decltype(isnormal((float)0)), bool>::value), "");
247 static_assert((std::is_same<decltype(isnormal((double)0)), bool>::value), "");
248 static_assert((std::is_same<decltype(isnormal((long double)0)), bool>::value), "");
249 assert(isnormal(-1.0) == true);
250 }
251
test_isgreater()252 void test_isgreater()
253 {
254 static_assert((std::is_same<decltype(isgreater((float)0, (float)0)), bool>::value), "");
255 static_assert((std::is_same<decltype(isgreater((float)0, (double)0)), bool>::value), "");
256 static_assert((std::is_same<decltype(isgreater((float)0, (long double)0)), bool>::value), "");
257 static_assert((std::is_same<decltype(isgreater((double)0, (float)0)), bool>::value), "");
258 static_assert((std::is_same<decltype(isgreater((double)0, (double)0)), bool>::value), "");
259 static_assert((std::is_same<decltype(isgreater((double)0, (long double)0)), bool>::value), "");
260 static_assert((std::is_same<decltype(isgreater((long double)0, (float)0)), bool>::value), "");
261 static_assert((std::is_same<decltype(isgreater((long double)0, (double)0)), bool>::value), "");
262 static_assert((std::is_same<decltype(isgreater((long double)0, (long double)0)), bool>::value), "");
263 assert(isgreater(-1.0, 0.F) == false);
264 }
265
test_isgreaterequal()266 void test_isgreaterequal()
267 {
268 static_assert((std::is_same<decltype(isgreaterequal((float)0, (float)0)), bool>::value), "");
269 static_assert((std::is_same<decltype(isgreaterequal((float)0, (double)0)), bool>::value), "");
270 static_assert((std::is_same<decltype(isgreaterequal((float)0, (long double)0)), bool>::value), "");
271 static_assert((std::is_same<decltype(isgreaterequal((double)0, (float)0)), bool>::value), "");
272 static_assert((std::is_same<decltype(isgreaterequal((double)0, (double)0)), bool>::value), "");
273 static_assert((std::is_same<decltype(isgreaterequal((double)0, (long double)0)), bool>::value), "");
274 static_assert((std::is_same<decltype(isgreaterequal((long double)0, (float)0)), bool>::value), "");
275 static_assert((std::is_same<decltype(isgreaterequal((long double)0, (double)0)), bool>::value), "");
276 static_assert((std::is_same<decltype(isgreaterequal((long double)0, (long double)0)), bool>::value), "");
277 assert(isgreaterequal(-1.0, 0.F) == false);
278 }
279
test_isless()280 void test_isless()
281 {
282 static_assert((std::is_same<decltype(isless((float)0, (float)0)), bool>::value), "");
283 static_assert((std::is_same<decltype(isless((float)0, (double)0)), bool>::value), "");
284 static_assert((std::is_same<decltype(isless((float)0, (long double)0)), bool>::value), "");
285 static_assert((std::is_same<decltype(isless((double)0, (float)0)), bool>::value), "");
286 static_assert((std::is_same<decltype(isless((double)0, (double)0)), bool>::value), "");
287 static_assert((std::is_same<decltype(isless((double)0, (long double)0)), bool>::value), "");
288 static_assert((std::is_same<decltype(isless((long double)0, (float)0)), bool>::value), "");
289 static_assert((std::is_same<decltype(isless((long double)0, (double)0)), bool>::value), "");
290 static_assert((std::is_same<decltype(isless((long double)0, (long double)0)), bool>::value), "");
291 assert(isless(-1.0, 0.F) == true);
292 }
293
test_islessequal()294 void test_islessequal()
295 {
296 static_assert((std::is_same<decltype(islessequal((float)0, (float)0)), bool>::value), "");
297 static_assert((std::is_same<decltype(islessequal((float)0, (double)0)), bool>::value), "");
298 static_assert((std::is_same<decltype(islessequal((float)0, (long double)0)), bool>::value), "");
299 static_assert((std::is_same<decltype(islessequal((double)0, (float)0)), bool>::value), "");
300 static_assert((std::is_same<decltype(islessequal((double)0, (double)0)), bool>::value), "");
301 static_assert((std::is_same<decltype(islessequal((double)0, (long double)0)), bool>::value), "");
302 static_assert((std::is_same<decltype(islessequal((long double)0, (float)0)), bool>::value), "");
303 static_assert((std::is_same<decltype(islessequal((long double)0, (double)0)), bool>::value), "");
304 static_assert((std::is_same<decltype(islessequal((long double)0, (long double)0)), bool>::value), "");
305 assert(islessequal(-1.0, 0.F) == true);
306 }
307
test_islessgreater()308 void test_islessgreater()
309 {
310 static_assert((std::is_same<decltype(islessgreater((float)0, (float)0)), bool>::value), "");
311 static_assert((std::is_same<decltype(islessgreater((float)0, (double)0)), bool>::value), "");
312 static_assert((std::is_same<decltype(islessgreater((float)0, (long double)0)), bool>::value), "");
313 static_assert((std::is_same<decltype(islessgreater((double)0, (float)0)), bool>::value), "");
314 static_assert((std::is_same<decltype(islessgreater((double)0, (double)0)), bool>::value), "");
315 static_assert((std::is_same<decltype(islessgreater((double)0, (long double)0)), bool>::value), "");
316 static_assert((std::is_same<decltype(islessgreater((long double)0, (float)0)), bool>::value), "");
317 static_assert((std::is_same<decltype(islessgreater((long double)0, (double)0)), bool>::value), "");
318 static_assert((std::is_same<decltype(islessgreater((long double)0, (long double)0)), bool>::value), "");
319 assert(islessgreater(-1.0, 0.F) == true);
320 }
321
test_isunordered()322 void test_isunordered()
323 {
324 static_assert((std::is_same<decltype(isunordered((float)0, (float)0)), bool>::value), "");
325 static_assert((std::is_same<decltype(isunordered((float)0, (double)0)), bool>::value), "");
326 static_assert((std::is_same<decltype(isunordered((float)0, (long double)0)), bool>::value), "");
327 static_assert((std::is_same<decltype(isunordered((double)0, (float)0)), bool>::value), "");
328 static_assert((std::is_same<decltype(isunordered((double)0, (double)0)), bool>::value), "");
329 static_assert((std::is_same<decltype(isunordered((double)0, (long double)0)), bool>::value), "");
330 static_assert((std::is_same<decltype(isunordered((long double)0, (float)0)), bool>::value), "");
331 static_assert((std::is_same<decltype(isunordered((long double)0, (double)0)), bool>::value), "");
332 static_assert((std::is_same<decltype(isunordered((long double)0, (long double)0)), bool>::value), "");
333 assert(isunordered(-1.0, 0.F) == false);
334 }
335
test_acosh()336 void test_acosh()
337 {
338 static_assert((std::is_same<decltype(acosh((double)0)), double>::value), "");
339 static_assert((std::is_same<decltype(acoshf(0)), float>::value), "");
340 static_assert((std::is_same<decltype(acoshl(0)), long double>::value), "");
341 assert(acosh(1) == 0);
342 }
343
test_asinh()344 void test_asinh()
345 {
346 static_assert((std::is_same<decltype(asinh((double)0)), double>::value), "");
347 static_assert((std::is_same<decltype(asinhf(0)), float>::value), "");
348 static_assert((std::is_same<decltype(asinhl(0)), long double>::value), "");
349 assert(asinh(0) == 0);
350 }
351
test_atanh()352 void test_atanh()
353 {
354 static_assert((std::is_same<decltype(atanh((double)0)), double>::value), "");
355 static_assert((std::is_same<decltype(atanhf(0)), float>::value), "");
356 static_assert((std::is_same<decltype(atanhl(0)), long double>::value), "");
357 assert(atanh(0) == 0);
358 }
359
test_cbrt()360 void test_cbrt()
361 {
362 static_assert((std::is_same<decltype(cbrt((double)0)), double>::value), "");
363 static_assert((std::is_same<decltype(cbrtf(0)), float>::value), "");
364 static_assert((std::is_same<decltype(cbrtl(0)), long double>::value), "");
365 assert(cbrt(1) == 1);
366 }
367
test_copysign()368 void test_copysign()
369 {
370 static_assert((std::is_same<decltype(copysign((double)0, (double)0)), double>::value), "");
371 static_assert((std::is_same<decltype(copysignf(0,0)), float>::value), "");
372 static_assert((std::is_same<decltype(copysignl(0,0)), long double>::value), "");
373 assert(copysign(1,1) == 1);
374 }
375
test_erf()376 void test_erf()
377 {
378 static_assert((std::is_same<decltype(erf((double)0)), double>::value), "");
379 static_assert((std::is_same<decltype(erff(0)), float>::value), "");
380 static_assert((std::is_same<decltype(erfl(0)), long double>::value), "");
381 assert(erf(0) == 0);
382 }
383
test_erfc()384 void test_erfc()
385 {
386 static_assert((std::is_same<decltype(erfc((double)0)), double>::value), "");
387 static_assert((std::is_same<decltype(erfcf(0)), float>::value), "");
388 static_assert((std::is_same<decltype(erfcl(0)), long double>::value), "");
389 assert(erfc(0) == 1);
390 }
391
test_exp2()392 void test_exp2()
393 {
394 static_assert((std::is_same<decltype(exp2((double)0)), double>::value), "");
395 static_assert((std::is_same<decltype(exp2f(0)), float>::value), "");
396 static_assert((std::is_same<decltype(exp2l(0)), long double>::value), "");
397 assert(exp2(1) == 2);
398 }
399
test_expm1()400 void test_expm1()
401 {
402 static_assert((std::is_same<decltype(expm1((double)0)), double>::value), "");
403 static_assert((std::is_same<decltype(expm1f(0)), float>::value), "");
404 static_assert((std::is_same<decltype(expm1l(0)), long double>::value), "");
405 assert(expm1(0) == 0);
406 }
407
test_fdim()408 void test_fdim()
409 {
410 static_assert((std::is_same<decltype(fdim((double)0, (double)0)), double>::value), "");
411 static_assert((std::is_same<decltype(fdimf(0,0)), float>::value), "");
412 static_assert((std::is_same<decltype(fdiml(0,0)), long double>::value), "");
413 assert(fdim(1,0) == 1);
414 }
415
test_fma()416 void test_fma()
417 {
418 static_assert((std::is_same<decltype(fma((double)0, (double)0, (double)0)), double>::value), "");
419 static_assert((std::is_same<decltype(fmaf(0,0,0)), float>::value), "");
420 static_assert((std::is_same<decltype(fmal(0,0,0)), long double>::value), "");
421 assert(fma(1,1,1) == 2);
422 }
423
test_fmax()424 void test_fmax()
425 {
426 static_assert((std::is_same<decltype(fmax((double)0, (double)0)), double>::value), "");
427 static_assert((std::is_same<decltype(fmaxf(0,0)), float>::value), "");
428 static_assert((std::is_same<decltype(fmaxl(0,0)), long double>::value), "");
429 assert(fmax(1,0) == 1);
430 }
431
test_fmin()432 void test_fmin()
433 {
434 static_assert((std::is_same<decltype(fmin((double)0, (double)0)), double>::value), "");
435 static_assert((std::is_same<decltype(fminf(0,0)), float>::value), "");
436 static_assert((std::is_same<decltype(fminl(0,0)), long double>::value), "");
437 assert(fmin(1,0) == 0);
438 }
439
test_hypot()440 void test_hypot()
441 {
442 static_assert((std::is_same<decltype(hypot((double)0, (double)0)), double>::value), "");
443 static_assert((std::is_same<decltype(hypotf(0,0)), float>::value), "");
444 static_assert((std::is_same<decltype(hypotl(0,0)), long double>::value), "");
445 assert(hypot(3,4) == 5);
446 }
447
test_ilogb()448 void test_ilogb()
449 {
450 static_assert((std::is_same<decltype(ilogb((double)0)), int>::value), "");
451 static_assert((std::is_same<decltype(ilogbf(0)), int>::value), "");
452 static_assert((std::is_same<decltype(ilogbl(0)), int>::value), "");
453 assert(ilogb(1) == 0);
454 }
455
test_lgamma()456 void test_lgamma()
457 {
458 static_assert((std::is_same<decltype(lgamma((double)0)), double>::value), "");
459 static_assert((std::is_same<decltype(lgammaf(0)), float>::value), "");
460 static_assert((std::is_same<decltype(lgammal(0)), long double>::value), "");
461 assert(lgamma(1) == 0);
462 }
463
test_llrint()464 void test_llrint()
465 {
466 static_assert((std::is_same<decltype(llrint((double)0)), long long>::value), "");
467 static_assert((std::is_same<decltype(llrintf(0)), long long>::value), "");
468 static_assert((std::is_same<decltype(llrintl(0)), long long>::value), "");
469 assert(llrint(1) == 1LL);
470 }
471
test_llround()472 void test_llround()
473 {
474 static_assert((std::is_same<decltype(llround((double)0)), long long>::value), "");
475 static_assert((std::is_same<decltype(llroundf(0)), long long>::value), "");
476 static_assert((std::is_same<decltype(llroundl(0)), long long>::value), "");
477 assert(llround(1) == 1LL);
478 }
479
test_log1p()480 void test_log1p()
481 {
482 static_assert((std::is_same<decltype(log1p((double)0)), double>::value), "");
483 static_assert((std::is_same<decltype(log1pf(0)), float>::value), "");
484 static_assert((std::is_same<decltype(log1pl(0)), long double>::value), "");
485 assert(log1p(0) == 0);
486 }
487
test_log2()488 void test_log2()
489 {
490 static_assert((std::is_same<decltype(log2((double)0)), double>::value), "");
491 static_assert((std::is_same<decltype(log2f(0)), float>::value), "");
492 static_assert((std::is_same<decltype(log2l(0)), long double>::value), "");
493 assert(log2(1) == 0);
494 }
495
test_logb()496 void test_logb()
497 {
498 static_assert((std::is_same<decltype(logb((double)0)), double>::value), "");
499 static_assert((std::is_same<decltype(logbf(0)), float>::value), "");
500 static_assert((std::is_same<decltype(logbl(0)), long double>::value), "");
501 assert(logb(1) == 0);
502 }
503
test_lrint()504 void test_lrint()
505 {
506 static_assert((std::is_same<decltype(lrint((double)0)), long>::value), "");
507 static_assert((std::is_same<decltype(lrintf(0)), long>::value), "");
508 static_assert((std::is_same<decltype(lrintl(0)), long>::value), "");
509 assert(lrint(1) == 1L);
510 }
511
test_lround()512 void test_lround()
513 {
514 static_assert((std::is_same<decltype(lround((double)0)), long>::value), "");
515 static_assert((std::is_same<decltype(lroundf(0)), long>::value), "");
516 static_assert((std::is_same<decltype(lroundl(0)), long>::value), "");
517 assert(lround(1) == 1L);
518 }
519
test_nan()520 void test_nan()
521 {
522 static_assert((std::is_same<decltype(nan("")), double>::value), "");
523 static_assert((std::is_same<decltype(nanf("")), float>::value), "");
524 static_assert((std::is_same<decltype(nanl("")), long double>::value), "");
525 }
526
test_nearbyint()527 void test_nearbyint()
528 {
529 static_assert((std::is_same<decltype(nearbyint((double)0)), double>::value), "");
530 static_assert((std::is_same<decltype(nearbyintf(0)), float>::value), "");
531 static_assert((std::is_same<decltype(nearbyintl(0)), long double>::value), "");
532 assert(nearbyint(1) == 1);
533 }
534
test_nextafter()535 void test_nextafter()
536 {
537 static_assert((std::is_same<decltype(nextafter((double)0, (double)0)), double>::value), "");
538 static_assert((std::is_same<decltype(nextafterf(0,0)), float>::value), "");
539 static_assert((std::is_same<decltype(nextafterl(0,0)), long double>::value), "");
540 assert(nextafter(0,1) == hexfloat<double>(0x1, 0, -1074));
541 }
542
test_nexttoward()543 void test_nexttoward()
544 {
545 static_assert((std::is_same<decltype(nexttoward((double)0, (long double)0)), double>::value), "");
546 static_assert((std::is_same<decltype(nexttowardf(0, (long double)0)), float>::value), "");
547 static_assert((std::is_same<decltype(nexttowardl(0, (long double)0)), long double>::value), "");
548 assert(nexttoward(0, 1) == hexfloat<double>(0x1, 0, -1074));
549 }
550
test_remainder()551 void test_remainder()
552 {
553 static_assert((std::is_same<decltype(remainder((double)0, (double)0)), double>::value), "");
554 static_assert((std::is_same<decltype(remainderf(0,0)), float>::value), "");
555 static_assert((std::is_same<decltype(remainderl(0,0)), long double>::value), "");
556 static_assert((std::is_same<decltype(remainder((int)0, (int)0)), double>::value), "");
557 assert(remainder(0.5,1) == 0.5);
558 }
559
test_remquo()560 void test_remquo()
561 {
562 int ip;
563 static_assert((std::is_same<decltype(remquo((double)0, (double)0, &ip)), double>::value), "");
564 static_assert((std::is_same<decltype(remquof(0,0, &ip)), float>::value), "");
565 static_assert((std::is_same<decltype(remquol(0,0, &ip)), long double>::value), "");
566 assert(remquo(0.5,1, &ip) == 0.5);
567 }
568
test_rint()569 void test_rint()
570 {
571 static_assert((std::is_same<decltype(rint((double)0)), double>::value), "");
572 static_assert((std::is_same<decltype(rintf(0)), float>::value), "");
573 static_assert((std::is_same<decltype(rintl(0)), long double>::value), "");
574 assert(rint(1) == 1);
575 }
576
test_round()577 void test_round()
578 {
579 static_assert((std::is_same<decltype(round((double)0)), double>::value), "");
580 static_assert((std::is_same<decltype(roundf(0)), float>::value), "");
581 static_assert((std::is_same<decltype(roundl(0)), long double>::value), "");
582 assert(round(1) == 1);
583 }
584
test_scalbln()585 void test_scalbln()
586 {
587 static_assert((std::is_same<decltype(scalbln((double)0, (long)0)), double>::value), "");
588 static_assert((std::is_same<decltype(scalblnf(0, (long)0)), float>::value), "");
589 static_assert((std::is_same<decltype(scalblnl(0, (long)0)), long double>::value), "");
590 assert(scalbln(1, 1) == 2);
591 }
592
test_scalbn()593 void test_scalbn()
594 {
595 static_assert((std::is_same<decltype(scalbn((double)0, (int)0)), double>::value), "");
596 static_assert((std::is_same<decltype(scalbnf(0, (int)0)), float>::value), "");
597 static_assert((std::is_same<decltype(scalbnl(0, (int)0)), long double>::value), "");
598 assert(scalbn(1, 1) == 2);
599 }
600
test_tgamma()601 void test_tgamma()
602 {
603 static_assert((std::is_same<decltype(tgamma((double)0)), double>::value), "");
604 static_assert((std::is_same<decltype(tgammaf(0)), float>::value), "");
605 static_assert((std::is_same<decltype(tgammal(0)), long double>::value), "");
606 assert(tgamma(1) == 1);
607 }
608
test_trunc()609 void test_trunc()
610 {
611 static_assert((std::is_same<decltype(trunc((double)0)), double>::value), "");
612 static_assert((std::is_same<decltype(truncf(0)), float>::value), "");
613 static_assert((std::is_same<decltype(truncl(0)), long double>::value), "");
614 assert(trunc(1) == 1);
615 }
616
main()617 int main()
618 {
619 test_acos();
620 test_asin();
621 test_atan();
622 test_atan2();
623 test_ceil();
624 test_cos();
625 test_cosh();
626 test_exp();
627 test_fabs();
628 test_floor();
629 test_fmod();
630 test_frexp();
631 test_ldexp();
632 test_log();
633 test_log10();
634 test_modf();
635 test_pow();
636 test_sin();
637 test_sinh();
638 test_sqrt();
639 test_tan();
640 test_tanh();
641 test_signbit();
642 test_fpclassify();
643 test_isfinite();
644 test_isinf();
645 test_isnan();
646 test_isnormal();
647 test_isgreater();
648 test_isgreaterequal();
649 test_isless();
650 test_islessequal();
651 test_islessgreater();
652 test_isunordered();
653 test_acosh();
654 test_asinh();
655 test_atanh();
656 test_cbrt();
657 test_copysign();
658 test_erf();
659 test_erfc();
660 test_exp2();
661 test_expm1();
662 test_fdim();
663 test_fma();
664 test_fmax();
665 test_fmin();
666 test_hypot();
667 test_ilogb();
668 test_lgamma();
669 test_llrint();
670 test_llround();
671 test_log1p();
672 test_log2();
673 test_logb();
674 test_lrint();
675 test_lround();
676 test_nan();
677 test_nearbyint();
678 test_nextafter();
679 test_nexttoward();
680 test_remainder();
681 test_remquo();
682 test_rint();
683 test_round();
684 test_scalbln();
685 test_scalbn();
686 test_tgamma();
687 test_trunc();
688 }
689