xref: /freebsd/contrib/netbsd-tests/lib/libm/t_ceil.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 /* $NetBSD: t_ceil.c,v 1.10 2014/03/03 10:39:08 martin Exp $ */
2 
3 /*-
4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jukka Ruohonen.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_ceil.c,v 1.10 2014/03/03 10:39:08 martin Exp $");
33 
34 #include <atf-c.h>
35 #include <math.h>
36 #include <limits.h>
37 #include <stdio.h>
38 
39 #ifdef __vax__
40 #define SMALL_NUM	1.0e-38
41 #else
42 #define SMALL_NUM	1.0e-40
43 #endif
44 
45 /*
46  * ceil(3)
47  */
48 ATF_TC(ceil_basic);
49 ATF_TC_HEAD(ceil_basic, tc)
50 {
51 	atf_tc_set_md_var(tc, "descr", "A basic test of ceil(3)");
52 }
53 
54 ATF_TC_BODY(ceil_basic, tc)
55 {
56 	const double x = 0.999999999999999;
57 	const double y = 0.000000000000001;
58 
59 	ATF_CHECK(fabs(ceil(x) - 1) < SMALL_NUM);
60 	ATF_CHECK(fabs(ceil(y) - 1) < SMALL_NUM);
61 }
62 
63 ATF_TC(ceil_nan);
64 ATF_TC_HEAD(ceil_nan, tc)
65 {
66 	atf_tc_set_md_var(tc, "descr", "Test ceil(NaN) == NaN");
67 }
68 
69 ATF_TC_BODY(ceil_nan, tc)
70 {
71 	const double x = 0.0L / 0.0L;
72 
73 	ATF_CHECK(isnan(ceil(x)) != 0);
74 }
75 
76 ATF_TC(ceil_inf_neg);
77 ATF_TC_HEAD(ceil_inf_neg, tc)
78 {
79 	atf_tc_set_md_var(tc, "descr", "Test ceil(-Inf) == -Inf");
80 }
81 
82 ATF_TC_BODY(ceil_inf_neg, tc)
83 {
84 	const double x = -1.0L / 0.0L;
85 	double y = ceil(x);
86 
87 	if (isinf(y) == 0 || signbit(y) == 0)
88 		atf_tc_fail_nonfatal("ceil(-Inf) != -Inf");
89 }
90 
91 ATF_TC(ceil_inf_pos);
92 ATF_TC_HEAD(ceil_inf_pos, tc)
93 {
94 	atf_tc_set_md_var(tc, "descr", "Test ceil(+Inf) == +Inf");
95 }
96 
97 ATF_TC_BODY(ceil_inf_pos, tc)
98 {
99 	const double x = 1.0L / 0.0L;
100 	double y = ceil(x);
101 
102 	if (isinf(y) == 0 || signbit(y) != 0)
103 		atf_tc_fail_nonfatal("ceil(+Inf) != +Inf");
104 }
105 
106 ATF_TC(ceil_zero_neg);
107 ATF_TC_HEAD(ceil_zero_neg, tc)
108 {
109 	atf_tc_set_md_var(tc, "descr", "Test ceil(-0.0) == -0.0");
110 }
111 
112 ATF_TC_BODY(ceil_zero_neg, tc)
113 {
114 	const double x = -0.0L;
115 	double y = ceil(x);
116 
117 	if (fabs(y) > 0.0 || signbit(y) == 0)
118 		atf_tc_fail_nonfatal("ceil(-0.0) != -0.0");
119 }
120 
121 ATF_TC(ceil_zero_pos);
122 ATF_TC_HEAD(ceil_zero_pos, tc)
123 {
124 	atf_tc_set_md_var(tc, "descr", "Test ceil(+0.0) == +0.0");
125 }
126 
127 ATF_TC_BODY(ceil_zero_pos, tc)
128 {
129 	const double x = 0.0L;
130 	double y = ceil(x);
131 
132 	if (fabs(y) > 0.0 || signbit(y) != 0)
133 		atf_tc_fail_nonfatal("ceil(+0.0) != +0.0");
134 }
135 
136 /*
137  * ceilf(3)
138  */
139 ATF_TC(ceilf_basic);
140 ATF_TC_HEAD(ceilf_basic, tc)
141 {
142 	atf_tc_set_md_var(tc, "descr", "A basic test of ceilf(3)");
143 }
144 
145 ATF_TC_BODY(ceilf_basic, tc)
146 {
147 	const float x = 0.9999999;
148 	const float y = 0.0000001;
149 
150 	ATF_CHECK(fabsf(ceilf(x) - 1) < SMALL_NUM);
151 	ATF_CHECK(fabsf(ceilf(y) - 1) < SMALL_NUM);
152 }
153 
154 ATF_TC(ceilf_nan);
155 ATF_TC_HEAD(ceilf_nan, tc)
156 {
157 	atf_tc_set_md_var(tc, "descr", "Test ceilf(NaN) == NaN");
158 }
159 
160 ATF_TC_BODY(ceilf_nan, tc)
161 {
162 	const float x = 0.0L / 0.0L;
163 
164 	ATF_CHECK(isnan(ceilf(x)) != 0);
165 }
166 
167 ATF_TC(ceilf_inf_neg);
168 ATF_TC_HEAD(ceilf_inf_neg, tc)
169 {
170 	atf_tc_set_md_var(tc, "descr", "Test ceilf(-Inf) == -Inf");
171 }
172 
173 ATF_TC_BODY(ceilf_inf_neg, tc)
174 {
175 	const float x = -1.0L / 0.0L;
176 	float y = ceilf(x);
177 
178 	if (isinf(y) == 0 || signbit(y) == 0)
179 		atf_tc_fail_nonfatal("ceilf(-Inf) != -Inf");
180 }
181 
182 ATF_TC(ceilf_inf_pos);
183 ATF_TC_HEAD(ceilf_inf_pos, tc)
184 {
185 	atf_tc_set_md_var(tc, "descr", "Test ceilf(+Inf) == +Inf");
186 }
187 
188 ATF_TC_BODY(ceilf_inf_pos, tc)
189 {
190 	const float x = 1.0L / 0.0L;
191 	float y = ceilf(x);
192 
193 	if (isinf(y) == 0 || signbit(y) != 0)
194 		atf_tc_fail_nonfatal("ceilf(+Inf) != +Inf");
195 }
196 
197 ATF_TC(ceilf_zero_neg);
198 ATF_TC_HEAD(ceilf_zero_neg, tc)
199 {
200 	atf_tc_set_md_var(tc, "descr", "Test ceilf(-0.0) == -0.0");
201 }
202 
203 ATF_TC_BODY(ceilf_zero_neg, tc)
204 {
205 	const float x = -0.0L;
206 	float y = ceilf(x);
207 
208 	if (fabsf(y) > 0.0 || signbit(y) == 0)
209 		atf_tc_fail_nonfatal("ceilf(-0.0) != -0.0");
210 }
211 
212 ATF_TC(ceilf_zero_pos);
213 ATF_TC_HEAD(ceilf_zero_pos, tc)
214 {
215 	atf_tc_set_md_var(tc, "descr", "Test ceilf(+0.0) == +0.0");
216 }
217 
218 ATF_TC_BODY(ceilf_zero_pos, tc)
219 {
220 	const float x = 0.0L;
221 	float y = ceilf(x);
222 
223 	if (fabsf(y) > 0.0 || signbit(y) != 0)
224 		atf_tc_fail_nonfatal("ceilf(+0.0) != +0.0");
225 }
226 
227 /*
228  * ceill(3)
229  */
230 ATF_TC(ceill_basic);
231 ATF_TC_HEAD(ceill_basic, tc)
232 {
233 	atf_tc_set_md_var(tc, "descr", "A basic test of ceill(3)");
234 }
235 
236 ATF_TC_BODY(ceill_basic, tc)
237 {
238 	const long double x = 0.9999999;
239 	const long double y = 0.0000001;
240 
241 	ATF_CHECK(fabsl(ceill(x) - 1) < SMALL_NUM);
242 	ATF_CHECK(fabsl(ceill(y) - 1) < SMALL_NUM);
243 }
244 
245 ATF_TC(ceill_nan);
246 ATF_TC_HEAD(ceill_nan, tc)
247 {
248 	atf_tc_set_md_var(tc, "descr", "Test ceill(NaN) == NaN");
249 }
250 
251 ATF_TC_BODY(ceill_nan, tc)
252 {
253 	const long double x = 0.0L / 0.0L;
254 
255 	ATF_CHECK(isnan(ceill(x)) != 0);
256 }
257 
258 ATF_TC(ceill_inf_neg);
259 ATF_TC_HEAD(ceill_inf_neg, tc)
260 {
261 	atf_tc_set_md_var(tc, "descr", "Test ceill(-Inf) == -Inf");
262 }
263 
264 ATF_TC_BODY(ceill_inf_neg, tc)
265 {
266 	const long double x = -1.0L / 0.0L;
267 	long double y = ceill(x);
268 
269 	if (isinf(y) == 0 || signbit(y) == 0)
270 		atf_tc_fail_nonfatal("ceill(-Inf) != -Inf");
271 }
272 
273 ATF_TC(ceill_inf_pos);
274 ATF_TC_HEAD(ceill_inf_pos, tc)
275 {
276 	atf_tc_set_md_var(tc, "descr", "Test ceill(+Inf) == +Inf");
277 }
278 
279 ATF_TC_BODY(ceill_inf_pos, tc)
280 {
281 	const long double x = 1.0L / 0.0L;
282 	long double y = ceill(x);
283 
284 	if (isinf(y) == 0 || signbit(y) != 0)
285 		atf_tc_fail_nonfatal("ceill(+Inf) != +Inf");
286 }
287 
288 ATF_TC(ceill_zero_neg);
289 ATF_TC_HEAD(ceill_zero_neg, tc)
290 {
291 	atf_tc_set_md_var(tc, "descr", "Test ceill(-0.0) == -0.0");
292 }
293 
294 ATF_TC_BODY(ceill_zero_neg, tc)
295 {
296 	const long double x = -0.0L;
297 	long double y = ceill(x);
298 
299 	if (fabsl(y) > 0.0 || signbit(y) == 0)
300 		atf_tc_fail_nonfatal("ceill(-0.0) != -0.0");
301 }
302 
303 ATF_TC(ceill_zero_pos);
304 ATF_TC_HEAD(ceill_zero_pos, tc)
305 {
306 	atf_tc_set_md_var(tc, "descr", "Test ceill(+0.0) == +0.0");
307 }
308 
309 ATF_TC_BODY(ceill_zero_pos, tc)
310 {
311 	const long double x = 0.0L;
312 	long double y = ceill(x);
313 
314 	if (fabsl(y) > 0.0 || signbit(y) != 0)
315 		atf_tc_fail_nonfatal("ceill(+0.0) != +0.0");
316 }
317 
318 /*
319  * floor(3)
320  */
321 ATF_TC(floor_basic);
322 ATF_TC_HEAD(floor_basic, tc)
323 {
324 	atf_tc_set_md_var(tc, "descr", "A basic test of floor(3)");
325 }
326 
327 ATF_TC_BODY(floor_basic, tc)
328 {
329 	const double x = 0.999999999999999;
330 	const double y = 0.000000000000001;
331 
332 	ATF_CHECK(floor(x) < SMALL_NUM);
333 	ATF_CHECK(floor(y) < SMALL_NUM);
334 }
335 
336 ATF_TC(floor_nan);
337 ATF_TC_HEAD(floor_nan, tc)
338 {
339 	atf_tc_set_md_var(tc, "descr", "Test floor(NaN) == NaN");
340 }
341 
342 ATF_TC_BODY(floor_nan, tc)
343 {
344 	const double x = 0.0L / 0.0L;
345 
346 	ATF_CHECK(isnan(floor(x)) != 0);
347 }
348 
349 ATF_TC(floor_inf_neg);
350 ATF_TC_HEAD(floor_inf_neg, tc)
351 {
352 	atf_tc_set_md_var(tc, "descr", "Test floor(-Inf) == -Inf");
353 }
354 
355 ATF_TC_BODY(floor_inf_neg, tc)
356 {
357 	const double x = -1.0L / 0.0L;
358 	double y = floor(x);
359 
360 	if (isinf(y) == 0 || signbit(y) == 0)
361 		atf_tc_fail_nonfatal("floor(-Inf) != -Inf");
362 }
363 
364 ATF_TC(floor_inf_pos);
365 ATF_TC_HEAD(floor_inf_pos, tc)
366 {
367 	atf_tc_set_md_var(tc, "descr", "Test floor(+Inf) == +Inf");
368 }
369 
370 ATF_TC_BODY(floor_inf_pos, tc)
371 {
372 	const double x = 1.0L / 0.0L;
373 	double y = floor(x);
374 
375 	if (isinf(y) == 0 || signbit(y) != 0)
376 		atf_tc_fail_nonfatal("floor(+Inf) != +Inf");
377 }
378 
379 ATF_TC(floor_zero_neg);
380 ATF_TC_HEAD(floor_zero_neg, tc)
381 {
382 	atf_tc_set_md_var(tc, "descr", "Test floor(-0.0) == -0.0");
383 }
384 
385 ATF_TC_BODY(floor_zero_neg, tc)
386 {
387 	const double x = -0.0L;
388 	double y = floor(x);
389 
390 	if (fabs(y) > 0.0 || signbit(y) == 0)
391 		atf_tc_fail_nonfatal("floor(-0.0) != -0.0");
392 }
393 
394 ATF_TC(floor_zero_pos);
395 ATF_TC_HEAD(floor_zero_pos, tc)
396 {
397 	atf_tc_set_md_var(tc, "descr", "Test floor(+0.0) == +0.0");
398 }
399 
400 ATF_TC_BODY(floor_zero_pos, tc)
401 {
402 	const double x = 0.0L;
403 	double y = floor(x);
404 
405 	if (fabs(y) > 0.0 || signbit(y) != 0)
406 		atf_tc_fail_nonfatal("floor(+0.0) != +0.0");
407 }
408 
409 /*
410  * floorf(3)
411  */
412 ATF_TC(floorf_basic);
413 ATF_TC_HEAD(floorf_basic, tc)
414 {
415 	atf_tc_set_md_var(tc, "descr", "A basic test of floorf(3)");
416 }
417 
418 ATF_TC_BODY(floorf_basic, tc)
419 {
420 	const float x = 0.9999999;
421 	const float y = 0.0000001;
422 
423 	ATF_CHECK(floorf(x) < SMALL_NUM);
424 	ATF_CHECK(floorf(y) < SMALL_NUM);
425 }
426 
427 ATF_TC(floorf_nan);
428 ATF_TC_HEAD(floorf_nan, tc)
429 {
430 	atf_tc_set_md_var(tc, "descr", "Test floorf(NaN) == NaN");
431 }
432 
433 ATF_TC_BODY(floorf_nan, tc)
434 {
435 	const float x = 0.0L / 0.0L;
436 
437 	ATF_CHECK(isnan(floorf(x)) != 0);
438 }
439 
440 ATF_TC(floorf_inf_neg);
441 ATF_TC_HEAD(floorf_inf_neg, tc)
442 {
443 	atf_tc_set_md_var(tc, "descr", "Test floorf(-Inf) == -Inf");
444 }
445 
446 ATF_TC_BODY(floorf_inf_neg, tc)
447 {
448 	const float x = -1.0L / 0.0L;
449 	float y = floorf(x);
450 
451 	if (isinf(y) == 0 || signbit(y) == 0)
452 		atf_tc_fail_nonfatal("floorf(-Inf) != -Inf");
453 }
454 
455 ATF_TC(floorf_inf_pos);
456 ATF_TC_HEAD(floorf_inf_pos, tc)
457 {
458 	atf_tc_set_md_var(tc, "descr", "Test floorf(+Inf) == +Inf");
459 }
460 
461 ATF_TC_BODY(floorf_inf_pos, tc)
462 {
463 	const float x = 1.0L / 0.0L;
464 	float y = floorf(x);
465 
466 	if (isinf(y) == 0 || signbit(y) != 0)
467 		atf_tc_fail_nonfatal("floorf(+Inf) != +Inf");
468 }
469 
470 ATF_TC(floorf_zero_neg);
471 ATF_TC_HEAD(floorf_zero_neg, tc)
472 {
473 	atf_tc_set_md_var(tc, "descr", "Test floorf(-0.0) == -0.0");
474 }
475 
476 ATF_TC_BODY(floorf_zero_neg, tc)
477 {
478 	const float x = -0.0L;
479 	float y = floorf(x);
480 
481 	if (fabsf(y) > 0.0 || signbit(y) == 0)
482 		atf_tc_fail_nonfatal("floorf(-0.0) != -0.0");
483 }
484 
485 ATF_TC(floorf_zero_pos);
486 ATF_TC_HEAD(floorf_zero_pos, tc)
487 {
488 	atf_tc_set_md_var(tc, "descr", "Test floorf(+0.0) == +0.0");
489 }
490 
491 ATF_TC_BODY(floorf_zero_pos, tc)
492 {
493 	const float x = 0.0L;
494 	float y = floorf(x);
495 
496 	if (fabsf(y) > 0.0 || signbit(y) != 0)
497 		atf_tc_fail_nonfatal("floorf(+0.0) != +0.0");
498 }
499 
500 /*
501  * floorl(3)
502  */
503 ATF_TC(floorl_basic);
504 ATF_TC_HEAD(floorl_basic, tc)
505 {
506 	atf_tc_set_md_var(tc, "descr", "A basic test of floorl(3)");
507 }
508 
509 ATF_TC_BODY(floorl_basic, tc)
510 {
511 	const long double x = 0.9999999;
512 	const long double y = 0.0000001;
513 
514 	ATF_CHECK(floorl(x) < SMALL_NUM);
515 	ATF_CHECK(floorl(y) < SMALL_NUM);
516 }
517 
518 ATF_TC(floorl_nan);
519 ATF_TC_HEAD(floorl_nan, tc)
520 {
521 	atf_tc_set_md_var(tc, "descr", "Test floorl(NaN) == NaN");
522 }
523 
524 ATF_TC_BODY(floorl_nan, tc)
525 {
526 	const long double x = 0.0L / 0.0L;
527 
528 	ATF_CHECK(isnan(floorl(x)) != 0);
529 }
530 
531 ATF_TC(floorl_inf_neg);
532 ATF_TC_HEAD(floorl_inf_neg, tc)
533 {
534 	atf_tc_set_md_var(tc, "descr", "Test floorl(-Inf) == -Inf");
535 }
536 
537 ATF_TC_BODY(floorl_inf_neg, tc)
538 {
539 	const long double x = -1.0L / 0.0L;
540 	long double y = floorl(x);
541 
542 	if (isinf(y) == 0 || signbit(y) == 0)
543 		atf_tc_fail_nonfatal("floorl(-Inf) != -Inf");
544 }
545 
546 ATF_TC(floorl_inf_pos);
547 ATF_TC_HEAD(floorl_inf_pos, tc)
548 {
549 	atf_tc_set_md_var(tc, "descr", "Test floorl(+Inf) == +Inf");
550 }
551 
552 ATF_TC_BODY(floorl_inf_pos, tc)
553 {
554 	const long double x = 1.0L / 0.0L;
555 	long double y = floorl(x);
556 
557 	if (isinf(y) == 0 || signbit(y) != 0)
558 		atf_tc_fail_nonfatal("floorl(+Inf) != +Inf");
559 }
560 
561 ATF_TC(floorl_zero_neg);
562 ATF_TC_HEAD(floorl_zero_neg, tc)
563 {
564 	atf_tc_set_md_var(tc, "descr", "Test floorl(-0.0) == -0.0");
565 }
566 
567 ATF_TC_BODY(floorl_zero_neg, tc)
568 {
569 	const long double x = -0.0L;
570 	long double y = floorl(x);
571 
572 	if (fabsl(y) > 0.0 || signbit(y) == 0)
573 		atf_tc_fail_nonfatal("floorl(-0.0) != -0.0");
574 }
575 
576 ATF_TC(floorl_zero_pos);
577 ATF_TC_HEAD(floorl_zero_pos, tc)
578 {
579 	atf_tc_set_md_var(tc, "descr", "Test floorl(+0.0) == +0.0");
580 }
581 
582 ATF_TC_BODY(floorl_zero_pos, tc)
583 {
584 	const long double x = 0.0L;
585 	long double y = floorl(x);
586 
587 	if (fabsl(y) > 0.0 || signbit(y) != 0)
588 		atf_tc_fail_nonfatal("floorl(+0.0) != +0.0");
589 }
590 
591 /*
592  * trunc(3)
593  */
594 ATF_TC(trunc_basic);
595 ATF_TC_HEAD(trunc_basic, tc)
596 {
597 	atf_tc_set_md_var(tc, "descr", "A basic test of trunc(3)");
598 }
599 
600 ATF_TC_BODY(trunc_basic, tc)
601 {
602 	const double x = 0.999999999999999;
603 	const double y = 0.000000000000001;
604 
605 	ATF_CHECK(trunc(x) < SMALL_NUM);
606 	ATF_CHECK(trunc(y) < SMALL_NUM);
607 }
608 
609 ATF_TC(trunc_nan);
610 ATF_TC_HEAD(trunc_nan, tc)
611 {
612 	atf_tc_set_md_var(tc, "descr", "Test trunc(NaN) == NaN");
613 }
614 
615 ATF_TC_BODY(trunc_nan, tc)
616 {
617 	const double x = 0.0L / 0.0L;
618 
619 	ATF_CHECK(isnan(trunc(x)) != 0);
620 }
621 
622 ATF_TC(trunc_inf_neg);
623 ATF_TC_HEAD(trunc_inf_neg, tc)
624 {
625 	atf_tc_set_md_var(tc, "descr", "Test trunc(-Inf) == -Inf");
626 }
627 
628 ATF_TC_BODY(trunc_inf_neg, tc)
629 {
630 	const double x = -1.0L / 0.0L;
631 	double y = trunc(x);
632 
633 	if (isinf(y) == 0 || signbit(y) == 0)
634 		atf_tc_fail_nonfatal("trunc(-Inf) != -Inf");
635 }
636 
637 ATF_TC(trunc_inf_pos);
638 ATF_TC_HEAD(trunc_inf_pos, tc)
639 {
640 	atf_tc_set_md_var(tc, "descr", "Test trunc(+Inf) == +Inf");
641 }
642 
643 ATF_TC_BODY(trunc_inf_pos, tc)
644 {
645 	const double x = 1.0L / 0.0L;
646 	double y = trunc(x);
647 
648 	if (isinf(y) == 0 || signbit(y) != 0)
649 		atf_tc_fail_nonfatal("trunc(+Inf) != +Inf");
650 }
651 
652 ATF_TC(trunc_zero_neg);
653 ATF_TC_HEAD(trunc_zero_neg, tc)
654 {
655 	atf_tc_set_md_var(tc, "descr", "Test trunc(-0.0) == -0.0");
656 }
657 
658 ATF_TC_BODY(trunc_zero_neg, tc)
659 {
660 	const double x = -0.0L;
661 	double y = trunc(x);
662 
663 	if (fabs(y) > 0.0 || signbit(y) == 0)
664 		atf_tc_fail_nonfatal("trunc(-0.0) != -0.0");
665 }
666 
667 ATF_TC(trunc_zero_pos);
668 ATF_TC_HEAD(trunc_zero_pos, tc)
669 {
670 	atf_tc_set_md_var(tc, "descr", "Test trunc(+0.0) == +0.0");
671 }
672 
673 ATF_TC_BODY(trunc_zero_pos, tc)
674 {
675 	const double x = 0.0L;
676 	double y = trunc(x);
677 
678 	if (fabs(y) > 0.0 || signbit(y) != 0)
679 		atf_tc_fail_nonfatal("trunc(+0.0) != +0.0");
680 }
681 
682 /*
683  * truncf(3)
684  */
685 ATF_TC(truncf_basic);
686 ATF_TC_HEAD(truncf_basic, tc)
687 {
688 	atf_tc_set_md_var(tc, "descr", "A basic test of truncf(3)");
689 }
690 
691 ATF_TC_BODY(truncf_basic, tc)
692 {
693 	const float x = 0.9999999;
694 	const float y = 0.0000001;
695 
696 	ATF_CHECK(truncf(x) < SMALL_NUM);
697 	ATF_CHECK(truncf(y) < SMALL_NUM);
698 }
699 
700 ATF_TC(truncf_nan);
701 ATF_TC_HEAD(truncf_nan, tc)
702 {
703 	atf_tc_set_md_var(tc, "descr", "Test truncf(NaN) == NaN");
704 }
705 
706 ATF_TC_BODY(truncf_nan, tc)
707 {
708 	const float x = 0.0L / 0.0L;
709 
710 	ATF_CHECK(isnan(truncf(x)) != 0);
711 }
712 
713 ATF_TC(truncf_inf_neg);
714 ATF_TC_HEAD(truncf_inf_neg, tc)
715 {
716 	atf_tc_set_md_var(tc, "descr", "Test truncf(-Inf) == -Inf");
717 }
718 
719 ATF_TC_BODY(truncf_inf_neg, tc)
720 {
721 	const float x = -1.0L / 0.0L;
722 	float y = truncf(x);
723 
724 	if (isinf(y) == 0 || signbit(y) == 0)
725 		atf_tc_fail_nonfatal("truncf(-Inf) != -Inf");
726 }
727 
728 ATF_TC(truncf_inf_pos);
729 ATF_TC_HEAD(truncf_inf_pos, tc)
730 {
731 	atf_tc_set_md_var(tc, "descr", "Test truncf(+Inf) == +Inf");
732 }
733 
734 ATF_TC_BODY(truncf_inf_pos, tc)
735 {
736 	const float x = 1.0L / 0.0L;
737 	float y = truncf(x);
738 
739 	if (isinf(y) == 0 || signbit(y) != 0)
740 		atf_tc_fail_nonfatal("truncf(+Inf) != +Inf");
741 }
742 
743 ATF_TC(truncf_zero_neg);
744 ATF_TC_HEAD(truncf_zero_neg, tc)
745 {
746 	atf_tc_set_md_var(tc, "descr", "Test truncf(-0.0) == -0.0");
747 }
748 
749 ATF_TC_BODY(truncf_zero_neg, tc)
750 {
751 	const float x = -0.0L;
752 	float y = truncf(x);
753 
754 	if (fabsf(y) > 0.0 || signbit(y) == 0)
755 		atf_tc_fail_nonfatal("truncf(-0.0) != -0.0");
756 }
757 
758 ATF_TC(truncf_zero_pos);
759 ATF_TC_HEAD(truncf_zero_pos, tc)
760 {
761 	atf_tc_set_md_var(tc, "descr", "Test truncf(+0.0) == +0.0");
762 }
763 
764 ATF_TC_BODY(truncf_zero_pos, tc)
765 {
766 	const float x = 0.0L;
767 	float y = truncf(x);
768 
769 	if (fabsf(y) > 0.0 || signbit(y) != 0)
770 		atf_tc_fail_nonfatal("truncf(+0.0) != +0.0");
771 }
772 
773 /*
774  * truncl(3)
775  */
776 ATF_TC(truncl_basic);
777 ATF_TC_HEAD(truncl_basic, tc)
778 {
779 	atf_tc_set_md_var(tc, "descr", "A basic test of truncl(3)");
780 }
781 
782 ATF_TC_BODY(truncl_basic, tc)
783 {
784 	const long double x = 0.9999999;
785 	const long double y = 0.0000001;
786 
787 	ATF_CHECK(truncl(x) < SMALL_NUM);
788 	ATF_CHECK(truncl(y) < SMALL_NUM);
789 }
790 
791 ATF_TC(truncl_nan);
792 ATF_TC_HEAD(truncl_nan, tc)
793 {
794 	atf_tc_set_md_var(tc, "descr", "Test truncl(NaN) == NaN");
795 }
796 
797 ATF_TC_BODY(truncl_nan, tc)
798 {
799 	const long double x = 0.0L / 0.0L;
800 
801 	ATF_CHECK(isnan(truncl(x)) != 0);
802 }
803 
804 ATF_TC(truncl_inf_neg);
805 ATF_TC_HEAD(truncl_inf_neg, tc)
806 {
807 	atf_tc_set_md_var(tc, "descr", "Test truncl(-Inf) == -Inf");
808 }
809 
810 ATF_TC_BODY(truncl_inf_neg, tc)
811 {
812 	const long double x = -1.0L / 0.0L;
813 	long double y = truncl(x);
814 
815 	if (isinf(y) == 0 || signbit(y) == 0)
816 		atf_tc_fail_nonfatal("truncl(-Inf) != -Inf");
817 }
818 
819 ATF_TC(truncl_inf_pos);
820 ATF_TC_HEAD(truncl_inf_pos, tc)
821 {
822 	atf_tc_set_md_var(tc, "descr", "Test truncl(+Inf) == +Inf");
823 }
824 
825 ATF_TC_BODY(truncl_inf_pos, tc)
826 {
827 	const long double x = 1.0L / 0.0L;
828 	long double y = truncl(x);
829 
830 	if (isinf(y) == 0 || signbit(y) != 0)
831 		atf_tc_fail_nonfatal("truncl(+Inf) != +Inf");
832 }
833 
834 ATF_TC(truncl_zero_neg);
835 ATF_TC_HEAD(truncl_zero_neg, tc)
836 {
837 	atf_tc_set_md_var(tc, "descr", "Test truncl(-0.0) == -0.0");
838 }
839 
840 ATF_TC_BODY(truncl_zero_neg, tc)
841 {
842 	const long double x = -0.0L;
843 	long double y = truncl(x);
844 
845 	if (fabsl(y) > 0.0 || signbit(y) == 0)
846 		atf_tc_fail_nonfatal("truncl(-0.0) != -0.0");
847 }
848 
849 ATF_TC(truncl_zero_pos);
850 ATF_TC_HEAD(truncl_zero_pos, tc)
851 {
852 	atf_tc_set_md_var(tc, "descr", "Test truncl(+0.0) == +0.0");
853 }
854 
855 ATF_TC_BODY(truncl_zero_pos, tc)
856 {
857 	const long double x = 0.0L;
858 	long double y = truncl(x);
859 
860 	if (fabsl(y) > 0.0 || signbit(y) != 0)
861 		atf_tc_fail_nonfatal("truncl(+0.0) != +0.0");
862 }
863 
864 ATF_TP_ADD_TCS(tp)
865 {
866 
867 	ATF_TP_ADD_TC(tp, ceil_basic);
868 	ATF_TP_ADD_TC(tp, ceil_nan);
869 	ATF_TP_ADD_TC(tp, ceil_inf_neg);
870 	ATF_TP_ADD_TC(tp, ceil_inf_pos);
871 	ATF_TP_ADD_TC(tp, ceil_zero_neg);
872 	ATF_TP_ADD_TC(tp, ceil_zero_pos);
873 
874 	ATF_TP_ADD_TC(tp, ceilf_basic);
875 	ATF_TP_ADD_TC(tp, ceilf_nan);
876 	ATF_TP_ADD_TC(tp, ceilf_inf_neg);
877 	ATF_TP_ADD_TC(tp, ceilf_inf_pos);
878 	ATF_TP_ADD_TC(tp, ceilf_zero_neg);
879 	ATF_TP_ADD_TC(tp, ceilf_zero_pos);
880 
881 	ATF_TP_ADD_TC(tp, ceill_basic);
882 	ATF_TP_ADD_TC(tp, ceill_nan);
883 	ATF_TP_ADD_TC(tp, ceill_inf_neg);
884 	ATF_TP_ADD_TC(tp, ceill_inf_pos);
885 	ATF_TP_ADD_TC(tp, ceill_zero_neg);
886 	ATF_TP_ADD_TC(tp, ceill_zero_pos);
887 
888 	ATF_TP_ADD_TC(tp, floor_basic);
889 	ATF_TP_ADD_TC(tp, floor_nan);
890 	ATF_TP_ADD_TC(tp, floor_inf_neg);
891 	ATF_TP_ADD_TC(tp, floor_inf_pos);
892 	ATF_TP_ADD_TC(tp, floor_zero_neg);
893 	ATF_TP_ADD_TC(tp, floor_zero_pos);
894 
895 	ATF_TP_ADD_TC(tp, floorf_basic);
896 	ATF_TP_ADD_TC(tp, floorf_nan);
897 	ATF_TP_ADD_TC(tp, floorf_inf_neg);
898 	ATF_TP_ADD_TC(tp, floorf_inf_pos);
899 	ATF_TP_ADD_TC(tp, floorf_zero_neg);
900 	ATF_TP_ADD_TC(tp, floorf_zero_pos);
901 
902 	ATF_TP_ADD_TC(tp, floorl_basic);
903 	ATF_TP_ADD_TC(tp, floorl_nan);
904 	ATF_TP_ADD_TC(tp, floorl_inf_neg);
905 	ATF_TP_ADD_TC(tp, floorl_inf_pos);
906 	ATF_TP_ADD_TC(tp, floorl_zero_neg);
907 	ATF_TP_ADD_TC(tp, floorl_zero_pos);
908 
909 	ATF_TP_ADD_TC(tp, trunc_basic);
910 	ATF_TP_ADD_TC(tp, trunc_nan);
911 	ATF_TP_ADD_TC(tp, trunc_inf_neg);
912 	ATF_TP_ADD_TC(tp, trunc_inf_pos);
913 	ATF_TP_ADD_TC(tp, trunc_zero_neg);
914 	ATF_TP_ADD_TC(tp, trunc_zero_pos);
915 
916 	ATF_TP_ADD_TC(tp, truncf_basic);
917 	ATF_TP_ADD_TC(tp, truncf_nan);
918 	ATF_TP_ADD_TC(tp, truncf_inf_neg);
919 	ATF_TP_ADD_TC(tp, truncf_inf_pos);
920 	ATF_TP_ADD_TC(tp, truncf_zero_neg);
921 	ATF_TP_ADD_TC(tp, truncf_zero_pos);
922 
923 	ATF_TP_ADD_TC(tp, truncl_basic);
924 	ATF_TP_ADD_TC(tp, truncl_nan);
925 	ATF_TP_ADD_TC(tp, truncl_inf_neg);
926 	ATF_TP_ADD_TC(tp, truncl_inf_pos);
927 	ATF_TP_ADD_TC(tp, truncl_zero_neg);
928 	ATF_TP_ADD_TC(tp, truncl_zero_pos);
929 
930 	return atf_no_error();
931 }
932