xref: /freebsd/contrib/netbsd-tests/lib/libm/t_log.c (revision 2f1217877e155a8a7de97e74eb7e82096a5ef316)
1 /* $NetBSD: t_log.c,v 1.11 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_log.c,v 1.11 2014/03/03 10:39:08 martin Exp $");
33 
34 #include <atf-c.h>
35 #include <atf-c/config.h>
36 
37 #include <math.h>
38 #include <stdio.h>
39 #include <string.h>
40 
41 /*
42  * log10(3)
43  */
44 ATF_TC(log10_base);
45 ATF_TC_HEAD(log10_base, tc)
46 {
47 	atf_tc_set_md_var(tc, "descr", "Test log10(10) == 1");
48 }
49 
50 ATF_TC_BODY(log10_base, tc)
51 {
52 	ATF_CHECK(log10(10.0) == 1.0);
53 }
54 
55 ATF_TC(log10_nan);
56 ATF_TC_HEAD(log10_nan, tc)
57 {
58 	atf_tc_set_md_var(tc, "descr", "Test log10(NaN) == NaN");
59 }
60 
61 ATF_TC_BODY(log10_nan, tc)
62 {
63 	const double x = 0.0L / 0.0L;
64 
65 	ATF_CHECK(isnan(x) != 0);
66 	ATF_CHECK(isnan(log10(x)) != 0);
67 }
68 
69 ATF_TC(log10_inf_neg);
70 ATF_TC_HEAD(log10_inf_neg, tc)
71 {
72 	atf_tc_set_md_var(tc, "descr", "Test log10(-Inf) == NaN");
73 }
74 
75 ATF_TC_BODY(log10_inf_neg, tc)
76 {
77 	const double x = -1.0L / 0.0L;
78 	const double y = log10(x);
79 
80 	ATF_CHECK(isnan(y) != 0);
81 }
82 
83 ATF_TC(log10_inf_pos);
84 ATF_TC_HEAD(log10_inf_pos, tc)
85 {
86 	atf_tc_set_md_var(tc, "descr", "Test log10(+Inf) == +Inf");
87 }
88 
89 ATF_TC_BODY(log10_inf_pos, tc)
90 {
91 	const double x = 1.0L / 0.0L;
92 
93 	ATF_CHECK(log10(x) == x);
94 }
95 
96 ATF_TC(log10_one_pos);
97 ATF_TC_HEAD(log10_one_pos, tc)
98 {
99 	atf_tc_set_md_var(tc, "descr", "Test log10(1.0) == +0.0");
100 }
101 
102 ATF_TC_BODY(log10_one_pos, tc)
103 {
104 	const double x = log10(1.0);
105 	const double y = 0.0L;
106 
107 	ATF_CHECK(x == y);
108 	ATF_CHECK(signbit(x) == 0);
109 	ATF_CHECK(signbit(y) == 0);
110 }
111 
112 ATF_TC(log10_zero_neg);
113 ATF_TC_HEAD(log10_zero_neg, tc)
114 {
115 	atf_tc_set_md_var(tc, "descr", "Test log10(-0.0) == -HUGE_VAL");
116 }
117 
118 ATF_TC_BODY(log10_zero_neg, tc)
119 {
120 	const double x = -0.0L;
121 
122 	ATF_CHECK(log10(x) == -HUGE_VAL);
123 }
124 
125 ATF_TC(log10_zero_pos);
126 ATF_TC_HEAD(log10_zero_pos, tc)
127 {
128 	atf_tc_set_md_var(tc, "descr", "Test log10(+0.0) == -HUGE_VAL");
129 }
130 
131 ATF_TC_BODY(log10_zero_pos, tc)
132 {
133 	const double x = 0.0L;
134 
135 	ATF_CHECK(log10(x) == -HUGE_VAL);
136 }
137 
138 /*
139  * log10f(3)
140  */
141 ATF_TC(log10f_base);
142 ATF_TC_HEAD(log10f_base, tc)
143 {
144 	atf_tc_set_md_var(tc, "descr", "Test log10f(10) == 1");
145 }
146 
147 ATF_TC_BODY(log10f_base, tc)
148 {
149 	ATF_CHECK(log10f(10.0) == 1.0);
150 }
151 
152 ATF_TC(log10f_nan);
153 ATF_TC_HEAD(log10f_nan, tc)
154 {
155 	atf_tc_set_md_var(tc, "descr", "Test log10f(NaN) == NaN");
156 }
157 
158 ATF_TC_BODY(log10f_nan, tc)
159 {
160 	const float x = 0.0L / 0.0L;
161 
162 	ATF_CHECK(isnan(x) != 0);
163 	ATF_CHECK(isnan(log10f(x)) != 0);
164 }
165 
166 ATF_TC(log10f_inf_neg);
167 ATF_TC_HEAD(log10f_inf_neg, tc)
168 {
169 	atf_tc_set_md_var(tc, "descr", "Test log10f(-Inf) == NaN");
170 }
171 
172 ATF_TC_BODY(log10f_inf_neg, tc)
173 {
174 	const float x = -1.0L / 0.0L;
175 	const float y = log10f(x);
176 
177 	ATF_CHECK(isnan(y) != 0);
178 }
179 
180 ATF_TC(log10f_inf_pos);
181 ATF_TC_HEAD(log10f_inf_pos, tc)
182 {
183 	atf_tc_set_md_var(tc, "descr", "Test log10f(+Inf) == +Inf");
184 }
185 
186 ATF_TC_BODY(log10f_inf_pos, tc)
187 {
188 	const float x = 1.0L / 0.0L;
189 
190 #if defined(__alpha__)
191 	atf_tc_expect_fail("PR port-alpha/46301");
192 #endif
193 
194 	ATF_CHECK(log10f(x) == x);
195 }
196 
197 ATF_TC(log10f_one_pos);
198 ATF_TC_HEAD(log10f_one_pos, tc)
199 {
200 	atf_tc_set_md_var(tc, "descr", "Test log10f(1.0) == +0.0");
201 }
202 
203 ATF_TC_BODY(log10f_one_pos, tc)
204 {
205 	const float x = log10f(1.0);
206 	const float y = 0.0L;
207 
208 	ATF_CHECK(x == y);
209 	ATF_CHECK(signbit(x) == 0);
210 	ATF_CHECK(signbit(y) == 0);
211 }
212 
213 ATF_TC(log10f_zero_neg);
214 ATF_TC_HEAD(log10f_zero_neg, tc)
215 {
216 	atf_tc_set_md_var(tc, "descr", "Test log10f(-0.0) == -HUGE_VALF");
217 }
218 
219 ATF_TC_BODY(log10f_zero_neg, tc)
220 {
221 	const float x = -0.0L;
222 
223 	ATF_CHECK(log10f(x) == -HUGE_VALF);
224 }
225 
226 ATF_TC(log10f_zero_pos);
227 ATF_TC_HEAD(log10f_zero_pos, tc)
228 {
229 	atf_tc_set_md_var(tc, "descr", "Test log10f(+0.0) == -HUGE_VALF");
230 }
231 
232 ATF_TC_BODY(log10f_zero_pos, tc)
233 {
234 	const float x = 0.0L;
235 
236 	ATF_CHECK(log10f(x) == -HUGE_VALF);
237 }
238 
239 /*
240  * log1p(3)
241  */
242 ATF_TC(log1p_nan);
243 ATF_TC_HEAD(log1p_nan, tc)
244 {
245 	atf_tc_set_md_var(tc, "descr", "Test log1p(NaN) == NaN");
246 }
247 
248 ATF_TC_BODY(log1p_nan, tc)
249 {
250 	const double x = 0.0L / 0.0L;
251 
252 	ATF_CHECK(isnan(x) != 0);
253 	ATF_CHECK(isnan(log1p(x)) != 0);
254 }
255 
256 ATF_TC(log1p_inf_neg);
257 ATF_TC_HEAD(log1p_inf_neg, tc)
258 {
259 	atf_tc_set_md_var(tc, "descr", "Test log1p(-Inf) == NaN");
260 }
261 
262 ATF_TC_BODY(log1p_inf_neg, tc)
263 {
264 	const double x = -1.0L / 0.0L;
265 	const double y = log1p(x);
266 
267 	if (isnan(y) == 0) {
268 		atf_tc_expect_fail("PR lib/45362");
269 		atf_tc_fail("log1p(-Inf) != NaN");
270 	}
271 }
272 
273 ATF_TC(log1p_inf_pos);
274 ATF_TC_HEAD(log1p_inf_pos, tc)
275 {
276 	atf_tc_set_md_var(tc, "descr", "Test log1p(+Inf) == +Inf");
277 }
278 
279 ATF_TC_BODY(log1p_inf_pos, tc)
280 {
281 	const double x = 1.0L / 0.0L;
282 
283 	ATF_CHECK(log1p(x) == x);
284 }
285 
286 ATF_TC(log1p_one_neg);
287 ATF_TC_HEAD(log1p_one_neg, tc)
288 {
289 	atf_tc_set_md_var(tc, "descr", "Test log1p(-1.0) == -HUGE_VAL");
290 }
291 
292 ATF_TC_BODY(log1p_one_neg, tc)
293 {
294 	const double x = log1p(-1.0);
295 
296 	if (x != -HUGE_VAL) {
297 		atf_tc_expect_fail("PR lib/45362");
298 		atf_tc_fail("log1p(-1.0) != -HUGE_VAL");
299 	}
300 }
301 
302 ATF_TC(log1p_zero_neg);
303 ATF_TC_HEAD(log1p_zero_neg, tc)
304 {
305 	atf_tc_set_md_var(tc, "descr", "Test log1p(-0.0) == -0.0");
306 }
307 
308 ATF_TC_BODY(log1p_zero_neg, tc)
309 {
310 	const double x = -0.0L;
311 
312 	ATF_CHECK(log1p(x) == x);
313 }
314 
315 ATF_TC(log1p_zero_pos);
316 ATF_TC_HEAD(log1p_zero_pos, tc)
317 {
318 	atf_tc_set_md_var(tc, "descr", "Test log1p(+0.0) == +0.0");
319 }
320 
321 ATF_TC_BODY(log1p_zero_pos, tc)
322 {
323 	const double x = 0.0L;
324 
325 	ATF_CHECK(log1p(x) == x);
326 }
327 
328 /*
329  * log1pf(3)
330  */
331 ATF_TC(log1pf_nan);
332 ATF_TC_HEAD(log1pf_nan, tc)
333 {
334 	atf_tc_set_md_var(tc, "descr", "Test log1pf(NaN) == NaN");
335 }
336 
337 ATF_TC_BODY(log1pf_nan, tc)
338 {
339 	const float x = 0.0L / 0.0L;
340 
341 	ATF_CHECK(isnan(x) != 0);
342 	ATF_CHECK(isnan(log1pf(x)) != 0);
343 }
344 
345 ATF_TC(log1pf_inf_neg);
346 ATF_TC_HEAD(log1pf_inf_neg, tc)
347 {
348 	atf_tc_set_md_var(tc, "descr", "Test log1pf(-Inf) == NaN");
349 }
350 
351 ATF_TC_BODY(log1pf_inf_neg, tc)
352 {
353 	const float x = -1.0L / 0.0L;
354 	const float y = log1pf(x);
355 
356 	if (isnan(y) == 0) {
357 		atf_tc_expect_fail("PR lib/45362");
358 		atf_tc_fail("log1pf(-Inf) != NaN");
359 	}
360 }
361 
362 ATF_TC(log1pf_inf_pos);
363 ATF_TC_HEAD(log1pf_inf_pos, tc)
364 {
365 	atf_tc_set_md_var(tc, "descr", "Test log1pf(+Inf) == +Inf");
366 }
367 
368 ATF_TC_BODY(log1pf_inf_pos, tc)
369 {
370 	const float x = 1.0L / 0.0L;
371 
372 	ATF_CHECK(log1pf(x) == x);
373 }
374 
375 ATF_TC(log1pf_one_neg);
376 ATF_TC_HEAD(log1pf_one_neg, tc)
377 {
378 	atf_tc_set_md_var(tc, "descr", "Test log1pf(-1.0) == -HUGE_VALF");
379 }
380 
381 ATF_TC_BODY(log1pf_one_neg, tc)
382 {
383 	const float x = log1pf(-1.0);
384 
385 	if (x != -HUGE_VALF) {
386 		atf_tc_expect_fail("PR lib/45362");
387 		atf_tc_fail("log1pf(-1.0) != -HUGE_VALF");
388 	}
389 }
390 
391 ATF_TC(log1pf_zero_neg);
392 ATF_TC_HEAD(log1pf_zero_neg, tc)
393 {
394 	atf_tc_set_md_var(tc, "descr", "Test log1pf(-0.0) == -0.0");
395 }
396 
397 ATF_TC_BODY(log1pf_zero_neg, tc)
398 {
399 	const float x = -0.0L;
400 
401 	ATF_CHECK(log1pf(x) == x);
402 }
403 
404 ATF_TC(log1pf_zero_pos);
405 ATF_TC_HEAD(log1pf_zero_pos, tc)
406 {
407 	atf_tc_set_md_var(tc, "descr", "Test log1pf(+0.0) == +0.0");
408 }
409 
410 ATF_TC_BODY(log1pf_zero_pos, tc)
411 {
412 	const float x = 0.0L;
413 
414 	ATF_CHECK(log1pf(x) == x);
415 }
416 
417 /*
418  * log2(3)
419  */
420 ATF_TC(log2_base);
421 ATF_TC_HEAD(log2_base, tc)
422 {
423 	atf_tc_set_md_var(tc, "descr", "Test log2(2) == 1");
424 }
425 
426 ATF_TC_BODY(log2_base, tc)
427 {
428 	ATF_CHECK(log2(2.0) == 1.0);
429 }
430 
431 ATF_TC(log2_nan);
432 ATF_TC_HEAD(log2_nan, tc)
433 {
434 	atf_tc_set_md_var(tc, "descr", "Test log2(NaN) == NaN");
435 }
436 
437 ATF_TC_BODY(log2_nan, tc)
438 {
439 	const double x = 0.0L / 0.0L;
440 
441 	ATF_CHECK(isnan(x) != 0);
442 	ATF_CHECK(isnan(log2(x)) != 0);
443 }
444 
445 ATF_TC(log2_inf_neg);
446 ATF_TC_HEAD(log2_inf_neg, tc)
447 {
448 	atf_tc_set_md_var(tc, "descr", "Test log2(-Inf) == NaN");
449 }
450 
451 ATF_TC_BODY(log2_inf_neg, tc)
452 {
453 	const double x = -1.0L / 0.0L;
454 	const double y = log2(x);
455 
456 	ATF_CHECK(isnan(y) != 0);
457 }
458 
459 ATF_TC(log2_inf_pos);
460 ATF_TC_HEAD(log2_inf_pos, tc)
461 {
462 	atf_tc_set_md_var(tc, "descr", "Test log2(+Inf) == +Inf");
463 }
464 
465 ATF_TC_BODY(log2_inf_pos, tc)
466 {
467 	const double x = 1.0L / 0.0L;
468 
469 	ATF_CHECK(log2(x) == x);
470 }
471 
472 ATF_TC(log2_one_pos);
473 ATF_TC_HEAD(log2_one_pos, tc)
474 {
475 	atf_tc_set_md_var(tc, "descr", "Test log2(1.0) == +0.0");
476 }
477 
478 ATF_TC_BODY(log2_one_pos, tc)
479 {
480 	const double x = log2(1.0);
481 	const double y = 0.0L;
482 
483 	ATF_CHECK(x == y);
484 	ATF_CHECK(signbit(x) == 0);
485 	ATF_CHECK(signbit(y) == 0);
486 }
487 
488 ATF_TC(log2_zero_neg);
489 ATF_TC_HEAD(log2_zero_neg, tc)
490 {
491 	atf_tc_set_md_var(tc, "descr", "Test log2(-0.0) == -HUGE_VAL");
492 }
493 
494 ATF_TC_BODY(log2_zero_neg, tc)
495 {
496 	const double x = -0.0L;
497 
498 	ATF_CHECK(log2(x) == -HUGE_VAL);
499 }
500 
501 ATF_TC(log2_zero_pos);
502 ATF_TC_HEAD(log2_zero_pos, tc)
503 {
504 	atf_tc_set_md_var(tc, "descr", "Test log2(+0.0) == -HUGE_VAL");
505 }
506 
507 ATF_TC_BODY(log2_zero_pos, tc)
508 {
509 	const double x = 0.0L;
510 
511 	ATF_CHECK(log2(x) == -HUGE_VAL);
512 }
513 
514 /*
515  * log2f(3)
516  */
517 ATF_TC(log2f_base);
518 ATF_TC_HEAD(log2f_base, tc)
519 {
520 	atf_tc_set_md_var(tc, "descr", "Test log2f(2) == 1");
521 }
522 
523 ATF_TC_BODY(log2f_base, tc)
524 {
525 	ATF_CHECK(log2f(2.0) == 1.0);
526 }
527 
528 ATF_TC(log2f_nan);
529 ATF_TC_HEAD(log2f_nan, tc)
530 {
531 	atf_tc_set_md_var(tc, "descr", "Test log2f(NaN) == NaN");
532 }
533 
534 ATF_TC_BODY(log2f_nan, tc)
535 {
536 	const float x = 0.0L / 0.0L;
537 
538 	ATF_CHECK(isnan(x) != 0);
539 	ATF_CHECK(isnan(log2f(x)) != 0);
540 }
541 
542 ATF_TC(log2f_inf_neg);
543 ATF_TC_HEAD(log2f_inf_neg, tc)
544 {
545 	atf_tc_set_md_var(tc, "descr", "Test log2f(-Inf) == NaN");
546 }
547 
548 ATF_TC_BODY(log2f_inf_neg, tc)
549 {
550 	const float x = -1.0L / 0.0L;
551 	const float y = log2f(x);
552 
553 	ATF_CHECK(isnan(y) != 0);
554 }
555 
556 ATF_TC(log2f_inf_pos);
557 ATF_TC_HEAD(log2f_inf_pos, tc)
558 {
559 	atf_tc_set_md_var(tc, "descr", "Test log2f(+Inf) == +Inf");
560 }
561 
562 ATF_TC_BODY(log2f_inf_pos, tc)
563 {
564 	const float x = 1.0L / 0.0L;
565 
566 #if defined(__alpha__)
567 	atf_tc_expect_fail("PR port-alpha/46301");
568 #endif
569 
570 	ATF_CHECK(log2f(x) == x);
571 }
572 
573 ATF_TC(log2f_one_pos);
574 ATF_TC_HEAD(log2f_one_pos, tc)
575 {
576 	atf_tc_set_md_var(tc, "descr", "Test log2f(1.0) == +0.0");
577 }
578 
579 ATF_TC_BODY(log2f_one_pos, tc)
580 {
581 	const float x = log2f(1.0);
582 	const float y = 0.0L;
583 
584 	ATF_CHECK(x == y);
585 	ATF_CHECK(signbit(x) == 0);
586 	ATF_CHECK(signbit(y) == 0);
587 }
588 
589 ATF_TC(log2f_zero_neg);
590 ATF_TC_HEAD(log2f_zero_neg, tc)
591 {
592 	atf_tc_set_md_var(tc, "descr", "Test log2f(-0.0) == -HUGE_VALF");
593 }
594 
595 ATF_TC_BODY(log2f_zero_neg, tc)
596 {
597 	const float x = -0.0L;
598 
599 	ATF_CHECK(log2f(x) == -HUGE_VALF);
600 }
601 
602 ATF_TC(log2f_zero_pos);
603 ATF_TC_HEAD(log2f_zero_pos, tc)
604 {
605 	atf_tc_set_md_var(tc, "descr", "Test log2f(+0.0) == -HUGE_VALF");
606 }
607 
608 ATF_TC_BODY(log2f_zero_pos, tc)
609 {
610 	const float x = 0.0L;
611 
612 	ATF_CHECK(log2f(x) == -HUGE_VALF);
613 }
614 
615 /*
616  * log(3)
617  */
618 ATF_TC(log_base);
619 ATF_TC_HEAD(log_base, tc)
620 {
621 	atf_tc_set_md_var(tc, "descr", "Test log(e) == 1");
622 }
623 
624 ATF_TC_BODY(log_base, tc)
625 {
626 	const double eps = 1.0e-38;
627 
628 	if (fabs(log(M_E) - 1.0) > eps)
629 		atf_tc_fail_nonfatal("log(e) != 1");
630 }
631 
632 ATF_TC(log_nan);
633 ATF_TC_HEAD(log_nan, tc)
634 {
635 	atf_tc_set_md_var(tc, "descr", "Test log(NaN) == NaN");
636 }
637 
638 ATF_TC_BODY(log_nan, tc)
639 {
640 	const double x = 0.0L / 0.0L;
641 
642 	ATF_CHECK(isnan(x) != 0);
643 	ATF_CHECK(isnan(log(x)) != 0);
644 }
645 
646 ATF_TC(log_inf_neg);
647 ATF_TC_HEAD(log_inf_neg, tc)
648 {
649 	atf_tc_set_md_var(tc, "descr", "Test log(-Inf) == NaN");
650 }
651 
652 ATF_TC_BODY(log_inf_neg, tc)
653 {
654 	const double x = -1.0L / 0.0L;
655 	const double y = log(x);
656 
657 	ATF_CHECK(isnan(y) != 0);
658 }
659 
660 ATF_TC(log_inf_pos);
661 ATF_TC_HEAD(log_inf_pos, tc)
662 {
663 	atf_tc_set_md_var(tc, "descr", "Test log(+Inf) == +Inf");
664 }
665 
666 ATF_TC_BODY(log_inf_pos, tc)
667 {
668 	const double x = 1.0L / 0.0L;
669 
670 	ATF_CHECK(log(x) == x);
671 }
672 
673 ATF_TC(log_one_pos);
674 ATF_TC_HEAD(log_one_pos, tc)
675 {
676 	atf_tc_set_md_var(tc, "descr", "Test log(1.0) == +0.0");
677 }
678 
679 ATF_TC_BODY(log_one_pos, tc)
680 {
681 	const double x = log(1.0);
682 	const double y = 0.0L;
683 
684 	ATF_CHECK(x == y);
685 	ATF_CHECK(signbit(x) == 0);
686 	ATF_CHECK(signbit(y) == 0);
687 }
688 
689 ATF_TC(log_zero_neg);
690 ATF_TC_HEAD(log_zero_neg, tc)
691 {
692 	atf_tc_set_md_var(tc, "descr", "Test log(-0.0) == -HUGE_VAL");
693 }
694 
695 ATF_TC_BODY(log_zero_neg, tc)
696 {
697 	const double x = -0.0L;
698 
699 	ATF_CHECK(log(x) == -HUGE_VAL);
700 }
701 
702 ATF_TC(log_zero_pos);
703 ATF_TC_HEAD(log_zero_pos, tc)
704 {
705 	atf_tc_set_md_var(tc, "descr", "Test log(+0.0) == -HUGE_VAL");
706 }
707 
708 ATF_TC_BODY(log_zero_pos, tc)
709 {
710 	const double x = 0.0L;
711 
712 	ATF_CHECK(log(x) == -HUGE_VAL);
713 }
714 
715 /*
716  * logf(3)
717  */
718 ATF_TC(logf_base);
719 ATF_TC_HEAD(logf_base, tc)
720 {
721 	atf_tc_set_md_var(tc, "descr", "Test logf(e) == 1");
722 }
723 
724 ATF_TC_BODY(logf_base, tc)
725 {
726 	const float eps = 1.0e-7;
727 
728 	if (fabsf(logf(M_E) - 1.0f) > eps)
729 		atf_tc_fail_nonfatal("logf(e) != 1");
730 }
731 
732 ATF_TC(logf_nan);
733 ATF_TC_HEAD(logf_nan, tc)
734 {
735 	atf_tc_set_md_var(tc, "descr", "Test logf(NaN) == NaN");
736 }
737 
738 ATF_TC_BODY(logf_nan, tc)
739 {
740 	const float x = 0.0L / 0.0L;
741 
742 	ATF_CHECK(isnan(x) != 0);
743 	ATF_CHECK(isnan(logf(x)) != 0);
744 }
745 
746 ATF_TC(logf_inf_neg);
747 ATF_TC_HEAD(logf_inf_neg, tc)
748 {
749 	atf_tc_set_md_var(tc, "descr", "Test logf(-Inf) == NaN");
750 }
751 
752 ATF_TC_BODY(logf_inf_neg, tc)
753 {
754 	const float x = -1.0L / 0.0L;
755 	const float y = logf(x);
756 
757 	ATF_CHECK(isnan(y) != 0);
758 }
759 
760 ATF_TC(logf_inf_pos);
761 ATF_TC_HEAD(logf_inf_pos, tc)
762 {
763 	atf_tc_set_md_var(tc, "descr", "Test logf(+Inf) == +Inf");
764 }
765 
766 ATF_TC_BODY(logf_inf_pos, tc)
767 {
768 	const float x = 1.0L / 0.0L;
769 
770 #if defined(__alpha__)
771 	atf_tc_expect_fail("PR port-alpha/46301");
772 #endif
773 
774 	ATF_CHECK(logf(x) == x);
775 }
776 
777 ATF_TC(logf_one_pos);
778 ATF_TC_HEAD(logf_one_pos, tc)
779 {
780 	atf_tc_set_md_var(tc, "descr", "Test logf(1.0) == +0.0");
781 }
782 
783 ATF_TC_BODY(logf_one_pos, tc)
784 {
785 	const float x = logf(1.0);
786 	const float y = 0.0L;
787 
788 	ATF_CHECK(x == y);
789 	ATF_CHECK(signbit(x) == 0);
790 	ATF_CHECK(signbit(y) == 0);
791 }
792 
793 ATF_TC(logf_zero_neg);
794 ATF_TC_HEAD(logf_zero_neg, tc)
795 {
796 	atf_tc_set_md_var(tc, "descr", "Test logf(-0.0) == -HUGE_VALF");
797 }
798 
799 ATF_TC_BODY(logf_zero_neg, tc)
800 {
801 	const float x = -0.0L;
802 
803 	ATF_CHECK(logf(x) == -HUGE_VALF);
804 }
805 
806 ATF_TC(logf_zero_pos);
807 ATF_TC_HEAD(logf_zero_pos, tc)
808 {
809 	atf_tc_set_md_var(tc, "descr", "Test logf(+0.0) == -HUGE_VALF");
810 }
811 
812 ATF_TC_BODY(logf_zero_pos, tc)
813 {
814 	const float x = 0.0L;
815 
816 	ATF_CHECK(logf(x) == -HUGE_VALF);
817 }
818 
819 ATF_TP_ADD_TCS(tp)
820 {
821 
822 	ATF_TP_ADD_TC(tp, log10_base);
823 	ATF_TP_ADD_TC(tp, log10_nan);
824 	ATF_TP_ADD_TC(tp, log10_inf_neg);
825 	ATF_TP_ADD_TC(tp, log10_inf_pos);
826 	ATF_TP_ADD_TC(tp, log10_one_pos);
827 	ATF_TP_ADD_TC(tp, log10_zero_neg);
828 	ATF_TP_ADD_TC(tp, log10_zero_pos);
829 
830 	ATF_TP_ADD_TC(tp, log10f_base);
831 	ATF_TP_ADD_TC(tp, log10f_nan);
832 	ATF_TP_ADD_TC(tp, log10f_inf_neg);
833 	ATF_TP_ADD_TC(tp, log10f_inf_pos);
834 	ATF_TP_ADD_TC(tp, log10f_one_pos);
835 	ATF_TP_ADD_TC(tp, log10f_zero_neg);
836 	ATF_TP_ADD_TC(tp, log10f_zero_pos);
837 
838 	ATF_TP_ADD_TC(tp, log1p_nan);
839 	ATF_TP_ADD_TC(tp, log1p_inf_neg);
840 	ATF_TP_ADD_TC(tp, log1p_inf_pos);
841 	ATF_TP_ADD_TC(tp, log1p_one_neg);
842 	ATF_TP_ADD_TC(tp, log1p_zero_neg);
843 	ATF_TP_ADD_TC(tp, log1p_zero_pos);
844 
845 	ATF_TP_ADD_TC(tp, log1pf_nan);
846 	ATF_TP_ADD_TC(tp, log1pf_inf_neg);
847 	ATF_TP_ADD_TC(tp, log1pf_inf_pos);
848 	ATF_TP_ADD_TC(tp, log1pf_one_neg);
849 	ATF_TP_ADD_TC(tp, log1pf_zero_neg);
850 	ATF_TP_ADD_TC(tp, log1pf_zero_pos);
851 
852 	ATF_TP_ADD_TC(tp, log2_base);
853 	ATF_TP_ADD_TC(tp, log2_nan);
854 	ATF_TP_ADD_TC(tp, log2_inf_neg);
855 	ATF_TP_ADD_TC(tp, log2_inf_pos);
856 	ATF_TP_ADD_TC(tp, log2_one_pos);
857 	ATF_TP_ADD_TC(tp, log2_zero_neg);
858 	ATF_TP_ADD_TC(tp, log2_zero_pos);
859 
860 	ATF_TP_ADD_TC(tp, log2f_base);
861 	ATF_TP_ADD_TC(tp, log2f_nan);
862 	ATF_TP_ADD_TC(tp, log2f_inf_neg);
863 	ATF_TP_ADD_TC(tp, log2f_inf_pos);
864 	ATF_TP_ADD_TC(tp, log2f_one_pos);
865 	ATF_TP_ADD_TC(tp, log2f_zero_neg);
866 	ATF_TP_ADD_TC(tp, log2f_zero_pos);
867 
868 	ATF_TP_ADD_TC(tp, log_base);
869 	ATF_TP_ADD_TC(tp, log_nan);
870 	ATF_TP_ADD_TC(tp, log_inf_neg);
871 	ATF_TP_ADD_TC(tp, log_inf_pos);
872 	ATF_TP_ADD_TC(tp, log_one_pos);
873 	ATF_TP_ADD_TC(tp, log_zero_neg);
874 	ATF_TP_ADD_TC(tp, log_zero_pos);
875 
876 	ATF_TP_ADD_TC(tp, logf_base);
877 	ATF_TP_ADD_TC(tp, logf_nan);
878 	ATF_TP_ADD_TC(tp, logf_inf_neg);
879 	ATF_TP_ADD_TC(tp, logf_inf_pos);
880 	ATF_TP_ADD_TC(tp, logf_one_pos);
881 	ATF_TP_ADD_TC(tp, logf_zero_neg);
882 	ATF_TP_ADD_TC(tp, logf_zero_pos);
883 
884 	return atf_no_error();
885 }
886