t_pow.c revision 276478
10SN/A/* $NetBSD: t_pow.c,v 1.3 2014/03/03 10:39:08 martin Exp $ */ 28413SN/A 30SN/A/*- 40SN/A * Copyright (c) 2011 The NetBSD Foundation, Inc. 50SN/A * All rights reserved. 60SN/A * 70SN/A * This code is derived from software contributed to The NetBSD Foundation 80SN/A * by Jukka Ruohonen. 90SN/A * 100SN/A * Redistribution and use in source and binary forms, with or without 110SN/A * modification, are permitted provided that the following conditions 120SN/A * are met: 130SN/A * 1. Redistributions of source code must retain the above copyright 140SN/A * notice, this list of conditions and the following disclaimer. 150SN/A * 2. Redistributions in binary form must reproduce the above copyright 160SN/A * notice, this list of conditions and the following disclaimer in the 170SN/A * documentation and/or other materials provided with the distribution. 180SN/A * 191472SN/A * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201472SN/A * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211472SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 220SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 230SN/A * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 240SN/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 250SN/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 260SN/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 270SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 280SN/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 290SN/A * POSSIBILITY OF SUCH DAMAGE. 308413SN/A */ 310SN/A#include <sys/cdefs.h> 320SN/A__RCSID("$NetBSD: t_pow.c,v 1.3 2014/03/03 10:39:08 martin Exp $"); 330SN/A 340SN/A#include <atf-c.h> 350SN/A#include <math.h> 360SN/A 370SN/A#ifdef __FreeBSD__ 380SN/A#define isinff isinf 390SN/A#endif 400SN/A 410SN/A/* 420SN/A * pow(3) 430SN/A */ 440SN/AATF_TC(pow_nan_x); 450SN/AATF_TC_HEAD(pow_nan_x, tc) 460SN/A{ 470SN/A atf_tc_set_md_var(tc, "descr", "Test pow(NaN, y) == NaN"); 480SN/A} 490SN/A 500SN/AATF_TC_BODY(pow_nan_x, tc) 510SN/A{ 520SN/A const double x = 0.0L / 0.0L; 530SN/A 540SN/A ATF_CHECK(isnan(pow(x, 2.0)) != 0); 550SN/A} 560SN/A 570SN/AATF_TC(pow_nan_y); 580SN/AATF_TC_HEAD(pow_nan_y, tc) 590SN/A{ 600SN/A atf_tc_set_md_var(tc, "descr", "Test pow(x, NaN) == NaN"); 610SN/A} 620SN/A 630SN/AATF_TC_BODY(pow_nan_y, tc) 640SN/A{ 650SN/A const double y = 0.0L / 0.0L; 660SN/A 671668SN/A ATF_CHECK(isnan(pow(2.0, y)) != 0); 680SN/A} 690SN/A 700SN/AATF_TC(pow_inf_neg_x); 710SN/AATF_TC_HEAD(pow_inf_neg_x, tc) 720SN/A{ 730SN/A atf_tc_set_md_var(tc, "descr", "Test pow(-Inf, y) == +-Inf || +-0.0"); 740SN/A} 750SN/A 760SN/AATF_TC_BODY(pow_inf_neg_x, tc) 770SN/A{ 780SN/A const double x = -1.0L / 0.0L; 790SN/A double z; 800SN/A 810SN/A /* 820SN/A * If y is odd, y > 0, and x is -Inf, -Inf is returned. 833602SN/A * If y is even, y > 0, and x is -Inf, +Inf is returned. 840SN/A */ 850SN/A z = pow(x, 3.0); 860SN/A 878556SN/A if (isinf(z) == 0 || signbit(z) == 0) 880SN/A atf_tc_fail_nonfatal("pow(-Inf, 3.0) != -Inf"); 890SN/A 900SN/A z = pow(x, 4.0); 918556SN/A 920SN/A if (isinf(z) == 0 || signbit(z) != 0) 930SN/A atf_tc_fail_nonfatal("pow(-Inf, 4.0) != +Inf"); 940SN/A 953602SN/A /* 960SN/A * If y is odd, y < 0, and x is -Inf, -0.0 is returned. 970SN/A * If y is even, y < 0, and x is -Inf, +0.0 is returned. 980SN/A */ 990SN/A z = pow(x, -3.0); 1000SN/A 1010SN/A if (fabs(z) > 0.0 || signbit(z) == 0) 1020SN/A atf_tc_fail_nonfatal("pow(-Inf, -3.0) != -0.0"); 1030SN/A 1040SN/A z = pow(x, -4.0); 1050SN/A 1060SN/A if (fabs(z) > 0.0 || signbit(z) != 0) 1070SN/A atf_tc_fail_nonfatal("pow(-Inf -4.0) != +0.0"); 1080SN/A} 1090SN/A 1100SN/AATF_TC(pow_inf_neg_y); 1110SN/AATF_TC_HEAD(pow_inf_neg_y, tc) 1120SN/A{ 1130SN/A atf_tc_set_md_var(tc, "descr", "Test pow(x, -Inf) == +Inf || +0.0"); 1140SN/A} 1150SN/A 1160SN/AATF_TC_BODY(pow_inf_neg_y, tc) 1170SN/A{ 1180SN/A const double y = -1.0L / 0.0L; 1190SN/A double z; 1200SN/A 1210SN/A /* 1220SN/A * If |x| < 1 and y is -Inf, +Inf is returned. 1230SN/A * If |x| > 1 and y is -Inf, +0.0 is returned. 1240SN/A */ 1250SN/A z = pow(0.1, y); 1260SN/A 1270SN/A if (isinf(z) == 0 || signbit(z) != 0) 1280SN/A atf_tc_fail_nonfatal("pow(0.1, -Inf) != +Inf"); 1290SN/A 1300SN/A z = pow(1.1, y); 1310SN/A 1320SN/A if (fabs(z) > 0.0 || signbit(z) != 0) 1330SN/A atf_tc_fail_nonfatal("pow(1.1, -Inf) != +0.0"); 1340SN/A} 1350SN/A 1361668SN/AATF_TC(pow_inf_pos_x); 1371668SN/AATF_TC_HEAD(pow_inf_pos_x, tc) 1380SN/A{ 1390SN/A atf_tc_set_md_var(tc, "descr", "Test pow(+Inf, y) == +Inf || +0.0"); 1400SN/A} 1410SN/A 1420SN/AATF_TC_BODY(pow_inf_pos_x, tc) 1430SN/A{ 1440SN/A const double x = 1.0L / 0.0L; 1450SN/A double z; 1460SN/A 1470SN/A /* 1480SN/A * For y < 0, if x is +Inf, +0.0 is returned. 1490SN/A * For y > 0, if x is +Inf, +Inf is returned. 1500SN/A */ 1510SN/A z = pow(x, -2.0); 1520SN/A 1530SN/A if (fabs(z) > 0.0 || signbit(z) != 0) 1540SN/A atf_tc_fail_nonfatal("pow(+Inf, -2.0) != +0.0"); 1550SN/A 1560SN/A z = pow(x, 2.0); 1570SN/A 1580SN/A if (isinf(z) == 0 || signbit(z) != 0) 1590SN/A atf_tc_fail_nonfatal("pow(+Inf, 2.0) != +Inf"); 1600SN/A} 1610SN/A 1620SN/AATF_TC(pow_inf_pos_y); 1630SN/AATF_TC_HEAD(pow_inf_pos_y, tc) 1640SN/A{ 1650SN/A atf_tc_set_md_var(tc, "descr", "Test pow(x, +Inf) == +Inf || +0.0"); 1660SN/A} 1670SN/A 1680SN/AATF_TC_BODY(pow_inf_pos_y, tc) 1690SN/A{ 1700SN/A const double y = 1.0L / 0.0L; 1710SN/A double z; 1720SN/A 1730SN/A /* 1740SN/A * If |x| < 1 and y is +Inf, +0.0 is returned. 1750SN/A * If |x| > 1 and y is +Inf, +Inf is returned. 1760SN/A */ 1770SN/A z = pow(0.1, y); 1780SN/A 1790SN/A if (fabs(z) > 0.0 || signbit(z) != 0) 1800SN/A atf_tc_fail_nonfatal("pow(0.1, +Inf) != +0.0"); 1810SN/A 1820SN/A z = pow(1.1, y); 1830SN/A 1840SN/A if (isinf(z) == 0 || signbit(z) != 0) 1850SN/A atf_tc_fail_nonfatal("pow(1.1, +Inf) != +Inf"); 1860SN/A} 1870SN/A 1880SN/AATF_TC(pow_one_neg_x); 1890SN/AATF_TC_HEAD(pow_one_neg_x, tc) 1900SN/A{ 1910SN/A atf_tc_set_md_var(tc, "descr", "Test pow(-1.0, +-Inf) == 1.0"); 1920SN/A} 1930SN/A 1940SN/AATF_TC_BODY(pow_one_neg_x, tc) 1950SN/A{ 1960SN/A const double infp = 1.0L / 0.0L; 1970SN/A const double infn = -1.0L / 0.0L; 1980SN/A 1990SN/A /* 2000SN/A * If x is -1.0, and y is +-Inf, 1.0 shall be returned. 2010SN/A */ 2020SN/A ATF_REQUIRE(isinf(infp) != 0); 2030SN/A ATF_REQUIRE(isinf(infn) != 0); 2040SN/A 2050SN/A if (pow(-1.0, infp) != 1.0) { 2060SN/A atf_tc_expect_fail("PR lib/45372"); 2070SN/A atf_tc_fail_nonfatal("pow(-1.0, +Inf) != 1.0"); 2080SN/A } 2090SN/A 2100SN/A if (pow(-1.0, infn) != 1.0) { 2110SN/A atf_tc_expect_fail("PR lib/45372"); 2120SN/A atf_tc_fail_nonfatal("pow(-1.0, -Inf) != 1.0"); 2130SN/A } 2140SN/A} 2150SN/A 2160SN/AATF_TC(pow_one_pos_x); 2170SN/AATF_TC_HEAD(pow_one_pos_x, tc) 2180SN/A{ 2190SN/A atf_tc_set_md_var(tc, "descr", "Test pow(1.0, y) == 1.0"); 2200SN/A} 2210SN/A 2220SN/AATF_TC_BODY(pow_one_pos_x, tc) 2231668SN/A{ 2241668SN/A const double y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 }; 2250SN/A const double z = 0.0L / 0.0L; 2260SN/A size_t i; 2270SN/A 2280SN/A /* 2290SN/A * For any value of y (including NaN), 2300SN/A * if x is 1.0, 1.0 shall be returned. 2310SN/A */ 2320SN/A if (pow(1.0, z) != 1.0) 2330SN/A atf_tc_fail_nonfatal("pow(1.0, NaN) != 1.0"); 2340SN/A 2350SN/A for (i = 0; i < __arraycount(y); i++) { 2360SN/A 2370SN/A if (pow(1.0, y[i]) != 1.0) 2380SN/A atf_tc_fail_nonfatal("pow(1.0, %0.01f) != 1.0", y[i]); 2390SN/A } 2400SN/A} 2410SN/A 2420SN/AATF_TC(pow_zero_x); 2430SN/AATF_TC_HEAD(pow_zero_x, tc) 2440SN/A{ 2450SN/A atf_tc_set_md_var(tc, "descr", "Test pow(+-0.0, y) == +-0.0 || HUGE"); 2460SN/A} 2470SN/A 2480SN/AATF_TC_BODY(pow_zero_x, tc) 2490SN/A{ 2500SN/A double z; 2510SN/A 2520SN/A /* 2530SN/A * If x is +0.0 or -0.0, y > 0, and y 2540SN/A * is an odd integer, x is returned. 2550SN/A */ 2560SN/A z = pow(+0.0, 3.0); 2570SN/A 2580SN/A if (fabs(z) > 0.0 || signbit(z) != 0) 2590SN/A atf_tc_fail_nonfatal("pow(+0.0, 3.0) != +0.0"); 2600SN/A 2610SN/A z = pow(-0.0, 3.0); 2620SN/A 2630SN/A if (fabs(z) > 0.0 || signbit(z) == 0) 2640SN/A atf_tc_fail_nonfatal("pow(-0.0, 3.0) != -0.0"); 2650SN/A 2660SN/A /* 2670SN/A * If y > 0 and not an odd integer, 268 * if x is +0.0 or -0.0, +0.0 is returned. 269 */ 270 z = pow(+0.0, 4.0); 271 272 if (fabs(z) > 0.0 || signbit(z) != 0) 273 atf_tc_fail_nonfatal("pow(+0.0, 4.0) != +0.0"); 274 275 z = pow(-0.0, 4.0); 276 277 if (fabs(z) > 0.0 || signbit(z) != 0) 278 atf_tc_fail_nonfatal("pow(-0.0, 4.0) != +0.0"); 279 280 /* 281 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL, 282 * +-HUGE_VALF, or +-HUGE_VALL shall be returned. 283 */ 284 z = pow(+0.0, -4.0); 285 286 if (z != HUGE_VAL) { 287 atf_tc_expect_fail("PR port-amd64/45391"); 288 atf_tc_fail_nonfatal("pow(+0.0, -4.0) != HUGE_VAL"); 289 } 290 291 z = pow(-0.0, -4.0); 292 293 if (z != HUGE_VAL) { 294 atf_tc_expect_fail("PR port-amd64/45391"); 295 atf_tc_fail_nonfatal("pow(-0.0, -4.0) != HUGE_VAL"); 296 } 297 298 z = pow(+0.0, -5.0); 299 300 if (z != HUGE_VAL) { 301 atf_tc_expect_fail("PR port-amd64/45391"); 302 atf_tc_fail_nonfatal("pow(+0.0, -5.0) != HUGE_VAL"); 303 } 304 305 z = pow(-0.0, -5.0); 306 307 if (z != -HUGE_VAL) 308 atf_tc_fail_nonfatal("pow(-0.0, -5.0) != -HUGE_VAL"); 309} 310 311ATF_TC(pow_zero_y); 312ATF_TC_HEAD(pow_zero_y, tc) 313{ 314 atf_tc_set_md_var(tc, "descr", "Test pow(x, +-0.0) == 1.0"); 315} 316 317ATF_TC_BODY(pow_zero_y, tc) 318{ 319 const double x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 }; 320 const double z = 0.0L / 0.0L; 321 size_t i; 322 323 /* 324 * For any value of x (including NaN), 325 * if y is +0.0 or -0.0, 1.0 is returned. 326 */ 327 if (pow(z, +0.0) != 1.0) 328 atf_tc_fail_nonfatal("pow(NaN, +0.0) != 1.0"); 329 330 if (pow(z, -0.0) != 1.0) 331 atf_tc_fail_nonfatal("pow(NaN, -0.0) != 1.0"); 332 333 for (i = 0; i < __arraycount(x); i++) { 334 335 if (pow(x[i], +0.0) != 1.0) 336 atf_tc_fail_nonfatal("pow(%0.01f, +0.0) != 1.0", x[i]); 337 338 if (pow(x[i], -0.0) != 1.0) 339 atf_tc_fail_nonfatal("pow(%0.01f, -0.0) != 1.0", x[i]); 340 } 341} 342 343/* 344 * powf(3) 345 */ 346ATF_TC(powf_nan_x); 347ATF_TC_HEAD(powf_nan_x, tc) 348{ 349 atf_tc_set_md_var(tc, "descr", "Test powf(NaN, y) == NaN"); 350} 351 352ATF_TC_BODY(powf_nan_x, tc) 353{ 354 const float x = 0.0L / 0.0L; 355 356 ATF_CHECK(isnanf(powf(x, 2.0)) != 0); 357} 358 359ATF_TC(powf_nan_y); 360ATF_TC_HEAD(powf_nan_y, tc) 361{ 362 atf_tc_set_md_var(tc, "descr", "Test powf(x, NaN) == NaN"); 363} 364 365ATF_TC_BODY(powf_nan_y, tc) 366{ 367 const float y = 0.0L / 0.0L; 368 369 ATF_CHECK(isnanf(powf(2.0, y)) != 0); 370} 371 372ATF_TC(powf_inf_neg_x); 373ATF_TC_HEAD(powf_inf_neg_x, tc) 374{ 375 atf_tc_set_md_var(tc, "descr", "Test powf(-Inf, y) == +-Inf || +-0.0"); 376} 377 378ATF_TC_BODY(powf_inf_neg_x, tc) 379{ 380 const float x = -1.0L / 0.0L; 381 float z; 382 383 /* 384 * If y is odd, y > 0, and x is -Inf, -Inf is returned. 385 * If y is even, y > 0, and x is -Inf, +Inf is returned. 386 */ 387 z = powf(x, 3.0); 388 389 if (isinff(z) == 0 || signbit(z) == 0) 390 atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf"); 391 392 z = powf(x, 4.0); 393 394 if (isinff(z) == 0 || signbit(z) != 0) 395 atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf"); 396 397 /* 398 * If y is odd, y < 0, and x is -Inf, -0.0 is returned. 399 * If y is even, y < 0, and x is -Inf, +0.0 is returned. 400 */ 401 z = powf(x, -3.0); 402 403 if (fabsf(z) > 0.0 || signbit(z) == 0) { 404 atf_tc_expect_fail("PR lib/45372"); 405 atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0"); 406 } 407 408 z = powf(x, -4.0); 409 410 if (fabsf(z) > 0.0 || signbit(z) != 0) 411 atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0"); 412} 413 414ATF_TC(powf_inf_neg_y); 415ATF_TC_HEAD(powf_inf_neg_y, tc) 416{ 417 atf_tc_set_md_var(tc, "descr", "Test powf(x, -Inf) == +Inf || +0.0"); 418} 419 420ATF_TC_BODY(powf_inf_neg_y, tc) 421{ 422 const float y = -1.0L / 0.0L; 423 float z; 424 425 /* 426 * If |x| < 1 and y is -Inf, +Inf is returned. 427 * If |x| > 1 and y is -Inf, +0.0 is returned. 428 */ 429 z = powf(0.1, y); 430 431 if (isinff(z) == 0 || signbit(z) != 0) 432 atf_tc_fail_nonfatal("powf(0.1, -Inf) != +Inf"); 433 434 z = powf(1.1, y); 435 436 if (fabsf(z) > 0.0 || signbit(z) != 0) 437 atf_tc_fail_nonfatal("powf(1.1, -Inf) != +0.0"); 438} 439 440ATF_TC(powf_inf_pos_x); 441ATF_TC_HEAD(powf_inf_pos_x, tc) 442{ 443 atf_tc_set_md_var(tc, "descr", "Test powf(+Inf, y) == +Inf || +0.0"); 444} 445 446ATF_TC_BODY(powf_inf_pos_x, tc) 447{ 448 const float x = 1.0L / 0.0L; 449 float z; 450 451 /* 452 * For y < 0, if x is +Inf, +0.0 is returned. 453 * For y > 0, if x is +Inf, +Inf is returned. 454 */ 455 z = powf(x, -2.0); 456 457 if (fabsf(z) > 0.0 || signbit(z) != 0) 458 atf_tc_fail_nonfatal("powf(+Inf, -2.0) != +0.0"); 459 460 z = powf(x, 2.0); 461 462 if (isinff(z) == 0 || signbit(z) != 0) 463 atf_tc_fail_nonfatal("powf(+Inf, 2.0) != +Inf"); 464} 465 466ATF_TC(powf_inf_pos_y); 467ATF_TC_HEAD(powf_inf_pos_y, tc) 468{ 469 atf_tc_set_md_var(tc, "descr", "Test powf(x, +Inf) == +Inf || +0.0"); 470} 471 472ATF_TC_BODY(powf_inf_pos_y, tc) 473{ 474 const float y = 1.0L / 0.0L; 475 float z; 476 477 /* 478 * If |x| < 1 and y is +Inf, +0.0 is returned. 479 * If |x| > 1 and y is +Inf, +Inf is returned. 480 */ 481 z = powf(0.1, y); 482 483 if (fabsf(z) > 0.0 || signbit(z) != 0) 484 atf_tc_fail_nonfatal("powf(0.1, +Inf) != +0.0"); 485 486 z = powf(1.1, y); 487 488 if (isinff(z) == 0 || signbit(z) != 0) 489 atf_tc_fail_nonfatal("powf(1.1, +Inf) != +Inf"); 490} 491 492ATF_TC(powf_one_neg_x); 493ATF_TC_HEAD(powf_one_neg_x, tc) 494{ 495 atf_tc_set_md_var(tc, "descr", "Test powf(-1.0, +-Inf) == 1.0"); 496} 497 498ATF_TC_BODY(powf_one_neg_x, tc) 499{ 500 const float infp = 1.0L / 0.0L; 501 const float infn = -1.0L / 0.0L; 502 503 /* 504 * If x is -1.0, and y is +-Inf, 1.0 shall be returned. 505 */ 506 ATF_REQUIRE(isinff(infp) != 0); 507 ATF_REQUIRE(isinff(infn) != 0); 508 509 if (powf(-1.0, infp) != 1.0) { 510 atf_tc_expect_fail("PR lib/45372"); 511 atf_tc_fail_nonfatal("powf(-1.0, +Inf) != 1.0"); 512 } 513 514 if (powf(-1.0, infn) != 1.0) { 515 atf_tc_expect_fail("PR lib/45372"); 516 atf_tc_fail_nonfatal("powf(-1.0, -Inf) != 1.0"); 517 } 518} 519 520ATF_TC(powf_one_pos_x); 521ATF_TC_HEAD(powf_one_pos_x, tc) 522{ 523 atf_tc_set_md_var(tc, "descr", "Test powf(1.0, y) == 1.0"); 524} 525 526ATF_TC_BODY(powf_one_pos_x, tc) 527{ 528 const float y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 }; 529 const float z = 0.0L / 0.0L; 530 size_t i; 531 532 /* 533 * For any value of y (including NaN), 534 * if x is 1.0, 1.0 shall be returned. 535 */ 536 if (powf(1.0, z) != 1.0) 537 atf_tc_fail_nonfatal("powf(1.0, NaN) != 1.0"); 538 539 for (i = 0; i < __arraycount(y); i++) { 540 541 if (powf(1.0, y[i]) != 1.0) 542 atf_tc_fail_nonfatal("powf(1.0, %0.01f) != 1.0", y[i]); 543 } 544} 545 546ATF_TC(powf_zero_x); 547ATF_TC_HEAD(powf_zero_x, tc) 548{ 549 atf_tc_set_md_var(tc, "descr", "Test powf(+-0.0, y) == +-0.0 || HUGE"); 550} 551 552ATF_TC_BODY(powf_zero_x, tc) 553{ 554 float z; 555 556 /* 557 * If x is +0.0 or -0.0, y > 0, and y 558 * is an odd integer, x is returned. 559 */ 560 z = powf(+0.0, 3.0); 561 562 if (fabsf(z) > 0.0 || signbit(z) != 0) 563 atf_tc_fail_nonfatal("powf(+0.0, 3.0) != +0.0"); 564 565 z = powf(-0.0, 3.0); 566 567 if (fabsf(z) > 0.0 || signbit(z) == 0) 568 atf_tc_fail_nonfatal("powf(-0.0, 3.0) != -0.0"); 569 570 /* 571 * If y > 0 and not an odd integer, 572 * if x is +0.0 or -0.0, +0.0 is returned. 573 */ 574 z = powf(+0.0, 4.0); 575 576 if (fabsf(z) > 0.0 || signbit(z) != 0) 577 atf_tc_fail_nonfatal("powf(+0.0, 4.0) != +0.0"); 578 579 z = powf(-0.0, 4.0); 580 581 if (fabsf(z) > 0.0 || signbit(z) != 0) 582 atf_tc_fail_nonfatal("powf(-0.0, 4.0) != +0.0"); 583 584 /* 585 * If y < 0 and x is +0.0 or -0.0, either +-HUGE_VAL, 586 * +-HUGE_VALF, or +-HUGE_VALL shall be returned. 587 */ 588 z = powf(+0.0, -4.0); 589 590 if (z != HUGE_VALF) { 591 atf_tc_expect_fail("PR port-amd64/45391"); 592 atf_tc_fail_nonfatal("powf(+0.0, -4.0) != HUGE_VALF"); 593 } 594 595 z = powf(-0.0, -4.0); 596 597 if (z != HUGE_VALF) { 598 atf_tc_expect_fail("PR port-amd64/45391"); 599 atf_tc_fail_nonfatal("powf(-0.0, -4.0) != HUGE_VALF"); 600 } 601 602 z = powf(+0.0, -5.0); 603 604 if (z != HUGE_VALF) { 605 atf_tc_expect_fail("PR port-amd64/45391"); 606 atf_tc_fail_nonfatal("powf(+0.0, -5.0) != HUGE_VALF"); 607 } 608 609 z = powf(-0.0, -5.0); 610 611 if (z != -HUGE_VALF) 612 atf_tc_fail_nonfatal("powf(-0.0, -5.0) != -HUGE_VALF"); 613} 614 615ATF_TC(powf_zero_y); 616ATF_TC_HEAD(powf_zero_y, tc) 617{ 618 atf_tc_set_md_var(tc, "descr", "Test powf(x, +-0.0) == 1.0"); 619} 620 621ATF_TC_BODY(powf_zero_y, tc) 622{ 623 const float x[] = { 0.1, -3.0, 77.0, 99.99, 101.0000001 }; 624 const float z = 0.0L / 0.0L; 625 size_t i; 626 627 /* 628 * For any value of x (including NaN), 629 * if y is +0.0 or -0.0, 1.0 is returned. 630 */ 631 if (powf(z, +0.0) != 1.0) 632 atf_tc_fail_nonfatal("powf(NaN, +0.0) != 1.0"); 633 634 if (powf(z, -0.0) != 1.0) 635 atf_tc_fail_nonfatal("powf(NaN, -0.0) != 1.0"); 636 637 for (i = 0; i < __arraycount(x); i++) { 638 639 if (powf(x[i], +0.0) != 1.0) 640 atf_tc_fail_nonfatal("powf(%0.01f, +0.0) != 1.0",x[i]); 641 642 if (powf(x[i], -0.0) != 1.0) 643 atf_tc_fail_nonfatal("powf(%0.01f, -0.0) != 1.0",x[i]); 644 } 645} 646 647ATF_TP_ADD_TCS(tp) 648{ 649 650 ATF_TP_ADD_TC(tp, pow_nan_x); 651 ATF_TP_ADD_TC(tp, pow_nan_y); 652 ATF_TP_ADD_TC(tp, pow_inf_neg_x); 653 ATF_TP_ADD_TC(tp, pow_inf_neg_y); 654 ATF_TP_ADD_TC(tp, pow_inf_pos_x); 655 ATF_TP_ADD_TC(tp, pow_inf_pos_y); 656 ATF_TP_ADD_TC(tp, pow_one_neg_x); 657 ATF_TP_ADD_TC(tp, pow_one_pos_x); 658 ATF_TP_ADD_TC(tp, pow_zero_x); 659 ATF_TP_ADD_TC(tp, pow_zero_y); 660 661 ATF_TP_ADD_TC(tp, powf_nan_x); 662 ATF_TP_ADD_TC(tp, powf_nan_y); 663 ATF_TP_ADD_TC(tp, powf_inf_neg_x); 664 ATF_TP_ADD_TC(tp, powf_inf_neg_y); 665 ATF_TP_ADD_TC(tp, powf_inf_pos_x); 666 ATF_TP_ADD_TC(tp, powf_inf_pos_y); 667 ATF_TP_ADD_TC(tp, powf_one_neg_x); 668 ATF_TP_ADD_TC(tp, powf_one_pos_x); 669 ATF_TP_ADD_TC(tp, powf_zero_x); 670 ATF_TP_ADD_TC(tp, powf_zero_y); 671 672 return atf_no_error(); 673} 674