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