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