Atlas - testautomation_math.c

Home / ext / SDL / test Lines: 1 | Size: 100261 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/** 2 * Math test suite 3 */ 4 5#include <float.h> 6#include <math.h> 7 8#include <SDL3/SDL.h> 9#include <SDL3/SDL_test.h> 10#include "testautomation_suites.h" 11 12/* ================= Test Constants ================== */ 13 14/* Range tests parameters */ 15#define RANGE_TEST_ITERATIONS 10000000 16#define RANGE_TEST_STEP ((Uint32)(SDL_MAX_UINT32 / RANGE_TEST_ITERATIONS)) 17 18/* Margin of error for imprecise tests */ 19#define EPSILON 1.0E-10 20 21/* Euler constant (used in exp/log) */ 22#ifndef M_E 23#define EULER 2.7182818284590450907955982984276488423347473144531250 24#else 25#define EULER M_E 26#endif 27 28#define IS_INFINITY(V) ISINF(V) 29 30/* Square root of 3 (used in atan2) */ 31#define SQRT3 1.7320508075688771931766041234368458390235900878906250 32 33/* ================= Test Structs ================== */ 34 35/** 36 * Stores a single input and the expected result 37 */ 38typedef struct 39{ 40 double input; 41 double expected; 42} d_to_d; 43 44/** 45 * Stores a pair of inputs and the expected result 46 */ 47typedef struct 48{ 49 double x_input, y_input; 50 double expected; 51} dd_to_d; 52 53/* 54 NB: You cannot create an array of these structures containing INFINITY or NAN. 55 On platforms such as OS/2, they are defined as 'extern const double' making them 56 not compile-time constant. 57*/ 58 59/* ================= Test Helpers ================== */ 60 61typedef double(SDLCALL *d_to_d_func)(double); 62typedef double(SDLCALL *dd_to_d_func)(double, double); 63 64/** 65 * Runs all the cases on a given function with a signature double -> double. 66 * The result is expected to be exact. 67 * 68 * \param func_name a printable name for the tested function. 69 * \param func the function to call. 70 * \param cases an array of all the cases. 71 * \param cases_size the size of the cases array. 72 */ 73static int 74helper_dtod(const char *func_name, d_to_d_func func, 75 const d_to_d *cases, const size_t cases_size) 76{ 77 Uint32 i; 78 for (i = 0; i < cases_size; i++) { 79 const double result = func(cases[i].input); 80 SDLTest_AssertCheck(SDL_fabs(result - cases[i].expected) < FLT_EPSILON, 81 "%s(%f), expected %f, got %f", 82 func_name, 83 cases[i].input, 84 cases[i].expected, result); 85 } 86 87 return TEST_COMPLETED; 88} 89 90/** 91 * Runs all the cases on a given function with a signature double -> double. 92 * Checks if the result between expected +/- EPSILON. 93 * 94 * \param func_name a printable name for the tested function. 95 * \param func the function to call. 96 * \param cases an array of all the cases. 97 * \param cases_size the size of the cases array. 98 */ 99static int 100helper_dtod_inexact(const char *func_name, d_to_d_func func, 101 const d_to_d *cases, const size_t cases_size) 102{ 103 Uint32 i; 104 for (i = 0; i < cases_size; i++) { 105 const double result = func(cases[i].input); 106 double diff = result - cases[i].expected; 107 double max_err = (cases[i].expected + 1.) * EPSILON; 108 if (diff < 0) { 109 diff = -diff; 110 } 111 if (max_err < 0) { 112 max_err = -max_err; 113 } 114 SDLTest_AssertCheck(diff <= max_err, 115 "%s(%f), expected %f +/- %g, got %f", 116 func_name, 117 cases[i].input, 118 cases[i].expected, max_err, 119 result); 120 } 121 122 return TEST_COMPLETED; 123} 124 125/** 126 * Runs all the cases on a given function with a signature 127 * (double, double) -> double. The result is expected to be exact. 128 * 129 * \param func_name a printable name for the tested function. 130 * \param func the function to call. 131 * \param cases an array of all the cases. 132 * \param cases_size the size of the cases array. 133 */ 134static int 135helper_ddtod(const char *func_name, dd_to_d_func func, 136 const dd_to_d *cases, const size_t cases_size) 137{ 138 Uint32 i; 139 for (i = 0; i < cases_size; i++) { 140 const double result = func(cases[i].x_input, cases[i].y_input); 141 SDLTest_AssertCheck(result == cases[i].expected, 142 "%s(%f,%f), expected %f, got %f", 143 func_name, 144 cases[i].x_input, cases[i].y_input, 145 cases[i].expected, result); 146 } 147 148 return TEST_COMPLETED; 149} 150 151/** 152 * Runs all the cases on a given function with a signature 153 * (double, double) -> double. Checks if the result between expected +/- EPSILON. 154 * 155 * \param func_name a printable name for the tested function. 156 * \param func the function to call. 157 * \param cases an array of all the cases. 158 * \param cases_size the size of the cases array. 159 */ 160static int 161helper_ddtod_inexact(const char *func_name, dd_to_d_func func, 162 const dd_to_d *cases, const size_t cases_size) 163{ 164 Uint32 i; 165 for (i = 0; i < cases_size; i++) { 166 const double result = func(cases[i].x_input, cases[i].y_input); 167 double diff = result - cases[i].expected; 168 double max_err = (cases[i].expected + 1.) * EPSILON; 169 if (diff < 0) { 170 diff = -diff; 171 } 172 if (max_err < 0) { 173 max_err = -max_err; 174 } 175 176 SDLTest_AssertCheck(diff <= max_err, 177 "%s(%f,%f), expected %f +/- %g, got %f", 178 func_name, 179 cases[i].x_input, cases[i].y_input, 180 cases[i].expected, max_err, 181 result); 182 } 183 184 return TEST_COMPLETED; 185} 186 187/** 188 * Runs a range of values on a given function with a signature double -> double 189 * 190 * This function is only meant to test functions that returns the input value if it is 191 * integral: f(x) -> x for x in N. 192 * 193 * \param func_name a printable name for the tested function. 194 * \param func the function to call. 195 */ 196static int 197helper_range(const char *func_name, d_to_d_func func) 198{ 199 Uint32 i; 200 double test_value = 0.0; 201 202 SDLTest_AssertPass("%s: Testing a range of %u values with steps of %" SDL_PRIu32, 203 func_name, 204 RANGE_TEST_ITERATIONS, 205 RANGE_TEST_STEP); 206 207 for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) { 208 double result; 209 /* These are tested elsewhere */ 210 if (ISNAN(test_value) || ISINF(test_value)) { 211 continue; 212 } 213 214 result = func(test_value); 215 if (result != test_value) { /* Only log failures to save performances */ 216 SDLTest_AssertCheck(false, 217 "%s(%.1f), expected %.1f, got %.1f", 218 func_name, test_value, 219 test_value, result); 220 return TEST_ABORTED; 221 } 222 } 223 224 return TEST_COMPLETED; 225} 226 227/* ================= Test Case Implementation ================== */ 228 229/* SDL_floor tests functions */ 230 231/** 232 * Inputs: +/-Infinity. 233 * Expected: Infinity is returned as-is. 234 */ 235static int SDLCALL 236floor_infCases(void *args) 237{ 238 double result; 239 240 result = SDL_floor(INFINITY); 241 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 242 "Floor(%f), expected %f, got %f", 243 INFINITY, INFINITY, result); 244 245 result = SDL_floor(-INFINITY); 246 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 247 "Floor(%f), expected %f, got %f", 248 -INFINITY, -INFINITY, result); 249 250 return TEST_COMPLETED; 251} 252 253/** 254 * Inputs: +/-0.0. 255 * Expected: Zero is returned as-is. 256 */ 257static int SDLCALL 258floor_zeroCases(void *args) 259{ 260 const d_to_d zero_cases[] = { 261 { 0.0, 0.0 }, 262 { -0.0, -0.0 } 263 }; 264 return helper_dtod("Floor", SDL_floor, zero_cases, SDL_arraysize(zero_cases)); 265} 266 267/** 268 * Input: NAN. 269 * Expected: NAN is returned. 270 */ 271static int SDLCALL 272floor_nanCase(void *args) 273{ 274 const double result = SDL_floor(NAN); 275 SDLTest_AssertCheck(ISNAN(result), 276 "Floor(nan), expected nan, got %f", 277 result); 278 return TEST_COMPLETED; 279} 280 281/** 282 * Inputs: integral values. 283 * Expected: the input value is returned as-is. 284 */ 285static int SDLCALL 286floor_roundNumbersCases(void *args) 287{ 288 const d_to_d round_cases[] = { 289 { 1.0, 1.0 }, 290 { -1.0, -1.0 }, 291 { 15.0, 15.0 }, 292 { -15.0, -15.0 }, 293 { 125.0, 125.0 }, 294 { -125.0, -125.0 }, 295 { 1024.0, 1024.0 }, 296 { -1024.0, -1024.0 } 297 }; 298 return helper_dtod("Floor", SDL_floor, round_cases, SDL_arraysize(round_cases)); 299} 300 301/** 302 * Inputs: fractional values. 303 * Expected: the lower integral value is returned. 304 */ 305static int SDLCALL 306floor_fractionCases(void *args) 307{ 308 const d_to_d frac_cases[] = { 309 { 1.0 / 2.0, 0.0 }, 310 { -1.0 / 2.0, -1.0 }, 311 { 4.0 / 3.0, 1.0 }, 312 { -4.0 / 3.0, -2.0 }, 313 { 76.0 / 7.0, 10.0 }, 314 { -76.0 / 7.0, -11.0 }, 315 { 535.0 / 8.0, 66.0 }, 316 { -535.0 / 8.0, -67.0 }, 317 { 19357.0 / 53.0, 365.0 }, 318 { -19357.0 / 53.0, -366.0 } 319 }; 320 return helper_dtod("Floor", SDL_floor, frac_cases, SDL_arraysize(frac_cases)); 321} 322 323/** 324 * Inputs: values in the range [0, UINT32_MAX]. 325 * Expected: the input value is returned as-is. 326 */ 327static int SDLCALL 328floor_rangeTest(void *args) 329{ 330 return helper_range("Floor", SDL_floor); 331} 332 333/* SDL_ceil tests functions */ 334 335/** 336 * Inputs: +/-Infinity. 337 * Expected: Infinity is returned as-is. 338 */ 339static int SDLCALL 340ceil_infCases(void *args) 341{ 342 double result; 343 344 result = SDL_ceil(INFINITY); 345 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 346 "Ceil(%f), expected %f, got %f", 347 INFINITY, INFINITY, result); 348 349 result = SDL_ceil(-INFINITY); 350 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 351 "Ceil(%f), expected %f, got %f", 352 -INFINITY, -INFINITY, result); 353 354 return TEST_COMPLETED; 355} 356 357/** 358 * Inputs: +/-0.0. 359 * Expected: Zero is returned as-is. 360 */ 361static int SDLCALL 362ceil_zeroCases(void *args) 363{ 364 const d_to_d zero_cases[] = { 365 { 0.0, 0.0 }, 366 { -0.0, -0.0 } 367 }; 368 return helper_dtod("Ceil", SDL_ceil, zero_cases, SDL_arraysize(zero_cases)); 369} 370 371/** 372 * Input: NAN. 373 * Expected: NAN is returned. 374 */ 375static int SDLCALL 376ceil_nanCase(void *args) 377{ 378 const double result = SDL_ceil(NAN); 379 SDLTest_AssertCheck(ISNAN(result), 380 "Ceil(nan), expected nan, got %f", 381 result); 382 return TEST_COMPLETED; 383} 384 385/** 386 * Inputs: integral values. 387 * Expected: the input value is returned as-is. 388 */ 389static int SDLCALL 390ceil_roundNumbersCases(void *args) 391{ 392 const d_to_d round_cases[] = { 393 { 1.0, 1.0 }, 394 { -1.0, -1.0 }, 395 { 15.0, 15.0 }, 396 { -15.0, -15.0 }, 397 { 125.0, 125.0 }, 398 { -125.0, -125.0 }, 399 { 1024.0, 1024.0 }, 400 { -1024.0, -1024.0 } 401 }; 402 return helper_dtod("Ceil", SDL_ceil, round_cases, SDL_arraysize(round_cases)); 403} 404 405/** 406 * Inputs: fractional values. 407 * Expected: the higher integral value is returned. 408 */ 409static int SDLCALL 410ceil_fractionCases(void *args) 411{ 412 const d_to_d frac_cases[] = { 413 { 1.0 / 2.0, 1.0 }, 414 { -1.0 / 2.0, -0.0 }, 415 { 4.0 / 3.0, 2.0 }, 416 { -4.0 / 3.0, -1.0 }, 417 { 76.0 / 7.0, 11.0 }, 418 { -76.0 / 7.0, -10.0 }, 419 { 535.0 / 8.0, 67.0 }, 420 { -535.0 / 8.0, -66.0 }, 421 { 19357.0 / 53.0, 366.0 }, 422 { -19357.0 / 53.0, -365.0 } 423 }; 424 return helper_dtod("Ceil", SDL_ceil, frac_cases, SDL_arraysize(frac_cases)); 425} 426 427/** 428 * Inputs: values in the range [0, UINT32_MAX]. 429 * Expected: the input value is returned as-is. 430 */ 431static int SDLCALL 432ceil_rangeTest(void *args) 433{ 434 return helper_range("Ceil", SDL_ceil); 435} 436 437/* SDL_trunc tests functions */ 438 439/** 440 * Inputs: +/-Infinity. 441 * Expected: Infinity is returned as-is. 442 */ 443static int SDLCALL 444trunc_infCases(void *args) 445{ 446 double result; 447 448 result = SDL_trunc(INFINITY); 449 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 450 "Trunc(%f), expected %f, got %f", 451 INFINITY, INFINITY, result); 452 453 result = SDL_trunc(-INFINITY); 454 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 455 "Trunc(%f), expected %f, got %f", 456 -INFINITY, -INFINITY, result); 457 458 return TEST_COMPLETED; 459} 460 461/** 462 * Inputs: +/-0.0. 463 * Expected: Zero is returned as-is. 464 */ 465static int SDLCALL 466trunc_zeroCases(void *args) 467{ 468 const d_to_d zero_cases[] = { 469 { 0.0, 0.0 }, 470 { -0.0, -0.0 } 471 }; 472 return helper_dtod("Trunc", SDL_trunc, zero_cases, SDL_arraysize(zero_cases)); 473} 474 475/** 476 * Input: NAN. 477 * Expected: NAN is returned. 478 */ 479static int SDLCALL 480trunc_nanCase(void *args) 481{ 482 const double result = SDL_trunc(NAN); 483 SDLTest_AssertCheck(ISNAN(result), 484 "Trunc(nan), expected nan, got %f", 485 result); 486 return TEST_COMPLETED; 487} 488 489/** 490 * Inputs: integral values. 491 * Expected: the input value is returned as-is. 492 */ 493static int SDLCALL 494trunc_roundNumbersCases(void *args) 495{ 496 const d_to_d round_cases[] = { 497 { 1.0, 1.0 }, 498 { -1.0, -1.0 }, 499 { 15.0, 15.0 }, 500 { -15.0, -15.0 }, 501 { 125.0, 125.0 }, 502 { -125.0, -125.0 }, 503 { 1024.0, 1024.0 }, 504 { -1024.0, -1024.0 } 505 }; 506 return helper_dtod("Trunc", SDL_trunc, round_cases, SDL_arraysize(round_cases)); 507} 508 509/** 510 * Inputs: fractional values. 511 * Expected: the integral part is returned. 512 */ 513static int SDLCALL 514trunc_fractionCases(void *args) 515{ 516 const d_to_d frac_cases[] = { 517 { 1.0 / 2.0, 0.0 }, 518 { -1.0 / 2.0, -0.0 }, 519 { 4.0 / 3.0, 1.0 }, 520 { -4.0 / 3.0, -1.0 }, 521 { 76.0 / 7.0, 10.0 }, 522 { -76.0 / 7.0, -10.0 }, 523 { 535.0 / 8.0, 66.0 }, 524 { -535.0 / 8.0, -66.0 }, 525 { 19357.0 / 53.0, 365.0 }, 526 { -19357.0 / 53.0, -365.0 } 527 }; 528 return helper_dtod("Trunc", SDL_trunc, frac_cases, SDL_arraysize(frac_cases)); 529} 530 531/** 532 * Inputs: values in the range [0, UINT32_MAX]. 533 * Expected: the input value is returned as-is. 534 */ 535static int SDLCALL 536trunc_rangeTest(void *args) 537{ 538 return helper_range("Trunc", SDL_trunc); 539} 540 541/* SDL_round tests functions */ 542 543/** 544 * Inputs: +/-Infinity. 545 * Expected: Infinity is returned as-is. 546 */ 547static int SDLCALL 548round_infCases(void *args) 549{ 550 double result; 551 552 result = SDL_round(INFINITY); 553 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 554 "Round(%f), expected %f, got %f", 555 INFINITY, INFINITY, result); 556 557 result = SDL_round(-INFINITY); 558 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 559 "Round(%f), expected %f, got %f", 560 -INFINITY, -INFINITY, result); 561 562 return TEST_COMPLETED; 563} 564 565/** 566 * Inputs: +/-0.0. 567 * Expected: Zero is returned as-is. 568 */ 569static int SDLCALL 570round_zeroCases(void *args) 571{ 572 const d_to_d zero_cases[] = { 573 { 0.0, 0.0 }, 574 { -0.0, -0.0 } 575 }; 576 return helper_dtod("Round", SDL_round, zero_cases, SDL_arraysize(zero_cases)); 577} 578 579/** 580 * Input: NAN. 581 * Expected: NAN is returned. 582 */ 583static int SDLCALL 584round_nanCase(void *args) 585{ 586 const double result = SDL_round(NAN); 587 SDLTest_AssertCheck(ISNAN(result), 588 "Round(nan), expected nan, got %f", 589 result); 590 return TEST_COMPLETED; 591} 592 593/** 594 * Inputs: integral values. 595 * Expected: the input value is returned as-is. 596 */ 597static int SDLCALL 598round_roundNumbersCases(void *args) 599{ 600 const d_to_d round_cases[] = { 601 { 1.0, 1.0 }, 602 { -1.0, -1.0 }, 603 { 15.0, 15.0 }, 604 { -15.0, -15.0 }, 605 { 125.0, 125.0 }, 606 { -125.0, -125.0 }, 607 { 1024.0, 1024.0 }, 608 { -1024.0, -1024.0 } 609 }; 610 return helper_dtod("Round", SDL_round, round_cases, SDL_arraysize(round_cases)); 611} 612 613/** 614 * Inputs: fractional values. 615 * Expected: the nearest integral value is returned. 616 */ 617static int SDLCALL 618round_fractionCases(void *args) 619{ 620 const d_to_d frac_cases[] = { 621 { 1.0 / 2.0, 1.0 }, 622 { -1.0 / 2.0, -1.0 }, 623 { 4.0 / 3.0, 1.0 }, 624 { -4.0 / 3.0, -1.0 }, 625 { 76.0 / 7.0, 11.0 }, 626 { -76.0 / 7.0, -11.0 }, 627 { 535.0 / 8.0, 67.0 }, 628 { -535.0 / 8.0, -67.0 }, 629 { 19357.0 / 53.0, 365.0 }, 630 { -19357.0 / 53.0, -365.0 } 631 }; 632 return helper_dtod("Round", SDL_round, frac_cases, SDL_arraysize(frac_cases)); 633} 634 635/** 636 * Inputs: values in the range [0, UINT32_MAX]. 637 * Expected: the input value is returned as-is. 638 */ 639static int SDLCALL 640round_rangeTest(void *args) 641{ 642 return helper_range("Round", SDL_round); 643} 644 645/* SDL_fabs tests functions */ 646 647/** 648 * Inputs: +/-Infinity. 649 * Expected: Positive Infinity is returned. 650 */ 651static int SDLCALL 652fabs_infCases(void *args) 653{ 654 double result; 655 656 result = SDL_fabs(INFINITY); 657 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 658 "Fabs(%f), expected %f, got %f", 659 INFINITY, INFINITY, result); 660 661 result = SDL_fabs(-INFINITY); 662 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 663 "Fabs(%f), expected %f, got %f", 664 -INFINITY, INFINITY, result); 665 666 return TEST_COMPLETED; 667} 668 669/** 670 * Inputs: +/-0.0. 671 * Expected: Positive zero is returned. 672 */ 673static int SDLCALL 674fabs_zeroCases(void *args) 675{ 676 const d_to_d zero_cases[] = { 677 { 0.0, 0.0 }, 678 { -0.0, 0.0 } 679 }; 680 return helper_dtod("Fabs", SDL_fabs, zero_cases, SDL_arraysize(zero_cases)); 681} 682 683/** 684 * Input: NAN. 685 * Expected: NAN is returned. 686 */ 687static int SDLCALL 688fabs_nanCase(void *args) 689{ 690 const double result = SDL_fabs(NAN); 691 SDLTest_AssertCheck(ISNAN(result), 692 "Fabs(nan), expected nan, got %f", 693 result); 694 return TEST_COMPLETED; 695} 696 697/** 698 * Inputs: values in the range [0, UINT32_MAX]. 699 * Expected: the input value is returned as-is. 700 */ 701static int SDLCALL 702fabs_rangeTest(void *args) 703{ 704 return helper_range("Fabs", SDL_fabs); 705} 706 707/* SDL_copysign tests functions */ 708 709/** 710 * Inputs: (+/-Infinity, +/-1.0). 711 * Expected: Infinity with the sign of 1.0 is returned. 712 */ 713static int SDLCALL 714copysign_infCases(void *args) 715{ 716 double result; 717 718 result = SDL_copysign(INFINITY, -1.0); 719 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 720 "Copysign(%f,%.1f), expected %f, got %f", 721 INFINITY, -1.0, -INFINITY, result); 722 723 result = SDL_copysign(INFINITY, 1.0); 724 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 725 "Copysign(%f,%.1f), expected %f, got %f", 726 INFINITY, 1.0, INFINITY, result); 727 728 result = SDL_copysign(-INFINITY, -1.0); 729 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 730 "Copysign(%f,%.1f), expected %f, got %f", 731 -INFINITY, -1.0, -INFINITY, result); 732 733 result = SDL_copysign(-INFINITY, 1.0); 734 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 735 "Copysign(%f,%.1f), expected %f, got %f", 736 -INFINITY, 1.0, INFINITY, result); 737 738 return TEST_COMPLETED; 739} 740 741/** 742 * Inputs: (+/-0.0, +/-1.0). 743 * Expected: 0.0 with the sign of 1.0 is returned. 744 */ 745static int SDLCALL 746copysign_zeroCases(void *args) 747{ 748 const dd_to_d zero_cases[] = { 749 { 0.0, 1.0, 0.0 }, 750 { 0.0, -1.0, -0.0 }, 751 { -0.0, 1.0, 0.0 }, 752 { -0.0, -1.0, -0.0 } 753 }; 754 return helper_ddtod("Copysign", SDL_copysign, zero_cases, SDL_arraysize(zero_cases)); 755} 756 757/** 758 * Inputs: (NAN, +/-1.0). 759 * Expected: NAN with the sign of 1.0 is returned. 760 * NOTE: On some platforms signed NAN is not supported, so we only check if the result is still NAN. 761 */ 762static int SDLCALL 763copysign_nanCases(void *args) 764{ 765 double result; 766 767 result = SDL_copysign(NAN, 1.0); 768 SDLTest_AssertCheck(ISNAN(result), 769 "Copysign(nan,1.0), expected nan, got %f", 770 result); 771 772 result = SDL_copysign(NAN, -1.0); 773 SDLTest_AssertCheck(ISNAN(result), 774 "Copysign(nan,-1.0), expected nan, got %f", 775 result); 776 return TEST_COMPLETED; 777} 778 779/** 780 * Inputs: values in the range [0, UINT32_MAX], +/-1.0. 781 * Expected: the input value with the sign of 1.0 is returned. 782 */ 783static int SDLCALL 784copysign_rangeTest(void *args) 785{ 786 Uint32 i; 787 double test_value = 0.0; 788 789 SDLTest_AssertPass("Copysign: Testing a range of %u values with steps of %" SDL_PRIu32, 790 RANGE_TEST_ITERATIONS, 791 RANGE_TEST_STEP); 792 793 for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) { 794 double result; 795 /* These are tested elsewhere */ 796 if (ISNAN(test_value) || ISINF(test_value)) { 797 continue; 798 } 799 800 /* Only log failures to save performances */ 801 result = SDL_copysign(test_value, 1.0); 802 if (result != test_value) { 803 SDLTest_AssertCheck(false, 804 "Copysign(%.1f,%.1f), expected %.1f, got %.1f", 805 test_value, 1.0, test_value, result); 806 return TEST_ABORTED; 807 } 808 809 result = SDL_copysign(test_value, -1.0); 810 if (result != -test_value) { 811 SDLTest_AssertCheck(false, 812 "Copysign(%.1f,%.1f), expected %.1f, got %.1f", 813 test_value, -1.0, -test_value, result); 814 return TEST_ABORTED; 815 } 816 } 817 return TEST_COMPLETED; 818} 819 820/* SDL_fmod tests functions */ 821 822/** 823 * Inputs: (+/-Infinity, +/-1.0). 824 * Expected: NAN is returned. 825 */ 826static int SDLCALL 827fmod_divOfInfCases(void *args) 828{ 829 double result; 830 831 result = SDL_fmod(INFINITY, -1.0); 832 SDLTest_AssertCheck(ISNAN(result), 833 "Fmod(%f,%.1f), expected %f, got %f", 834 INFINITY, -1.0, NAN, result); 835 836 result = SDL_fmod(INFINITY, 1.0); 837 SDLTest_AssertCheck(ISNAN(result), 838 "Fmod(%f,%.1f), expected %f, got %f", 839 INFINITY, 1.0, NAN, result); 840 841 result = SDL_fmod(-INFINITY, -1.0); 842 SDLTest_AssertCheck(ISNAN(result), 843 "Fmod(%f,%.1f), expected %f, got %f", 844 -INFINITY, -1.0, NAN, result); 845 846 result = SDL_fmod(-INFINITY, 1.0); 847 SDLTest_AssertCheck(ISNAN(result), 848 "Fmod(%f,%.1f), expected %f, got %f", 849 -INFINITY, 1.0, NAN, result); 850 851 return TEST_COMPLETED; 852} 853 854/** 855 * Inputs: (+/-1.0, +/-Infinity). 856 * Expected: 1.0 is returned as-is. 857 */ 858static int SDLCALL 859fmod_divByInfCases(void *args) 860{ 861 double result; 862 863 result = SDL_fmod(1.0, INFINITY); 864 SDLTest_AssertCheck(1.0 == result, 865 "Fmod(%.1f,%f), expected %f, got %f", 866 1.0, INFINITY, 1.0, result); 867 868 result = SDL_fmod(-1.0, INFINITY); 869 SDLTest_AssertCheck(-1.0 == result, 870 "Fmod(%.1f,%f), expected %f, got %f", 871 -1.0, INFINITY, -1.0, result); 872 873 result = SDL_fmod(1.0, -INFINITY); 874 SDLTest_AssertCheck(1.0 == result, 875 "Fmod(%.1f,%f), expected %f, got %f", 876 1.0, -INFINITY, 1.0, result); 877 878 result = SDL_fmod(-1.0, -INFINITY); 879 SDLTest_AssertCheck(-1.0 == result, 880 "Fmod(%.1f,%f), expected %f, got %f", 881 -1.0, -INFINITY, -1.0, result); 882 883 return TEST_COMPLETED; 884} 885 886/** 887 * Inputs: (+/-0.0, +/-1.0). 888 * Expected: Zero is returned as-is. 889 */ 890static int SDLCALL 891fmod_divOfZeroCases(void *args) 892{ 893 const dd_to_d zero_cases[] = { 894 { 0.0, 1.0, 0.0 }, 895 { 0.0, -1.0, 0.0 }, 896 { -0.0, 1.0, -0.0 }, 897 { -0.0, -1.0, -0.0 } 898 }; 899 return helper_ddtod("Fmod", SDL_fmod, zero_cases, SDL_arraysize(zero_cases)); 900} 901 902/** 903 * Inputs: (+/-1.0, +/-0.0). 904 * Expected: NAN is returned. 905 */ 906static int SDLCALL 907fmod_divByZeroCases(void *args) 908{ 909 double result; 910 911 result = SDL_fmod(1.0, 0.0); 912 SDLTest_AssertCheck(ISNAN(result), 913 "Fmod(1.0,0.0), expected nan, got %f", 914 result); 915 916 result = SDL_fmod(-1.0, 0.0); 917 SDLTest_AssertCheck(ISNAN(result), 918 "Fmod(-1.0,0.0), expected nan, got %f", 919 result); 920 921 result = SDL_fmod(1.0, -0.0); 922 SDLTest_AssertCheck(ISNAN(result), 923 "Fmod(1.0,-0.0), expected nan, got %f", 924 result); 925 926 result = SDL_fmod(-1.0, -0.0); 927 SDLTest_AssertCheck(ISNAN(result), 928 "Fmod(-1.0,-0.0), expected nan, got %f", 929 result); 930 931 return TEST_COMPLETED; 932} 933 934/** 935 * Inputs: all permutation of NAN and +/-1.0. 936 * Expected: NAN is returned. 937 */ 938static int SDLCALL 939fmod_nanCases(void *args) 940{ 941 double result; 942 943 result = SDL_fmod(NAN, 1.0); 944 SDLTest_AssertCheck(ISNAN(result), 945 "Fmod(nan,1.0), expected nan, got %f", 946 result); 947 948 result = SDL_fmod(NAN, -1.0); 949 SDLTest_AssertCheck(ISNAN(result), 950 "Fmod(nan,-1.0), expected nan, got %f", 951 result); 952 953 result = SDL_fmod(1.0, NAN); 954 SDLTest_AssertCheck(ISNAN(result), 955 "Fmod(1.0,nan), expected nan, got %f", 956 result); 957 958 result = SDL_fmod(-1.0, NAN); 959 SDLTest_AssertCheck(ISNAN(result), 960 "Fmod(-1.0,nan), expected nan, got %f", 961 result); 962 963 return TEST_COMPLETED; 964} 965 966/** 967 * Inputs: values within the domain of the function. 968 * Expected: the correct result is returned. 969 */ 970static int SDLCALL 971fmod_regularCases(void *args) 972{ 973 const dd_to_d regular_cases[] = { 974 { 3.5, 2.0, 1.5 }, 975 { -6.25, 3.0, -0.25 }, 976 { 7.5, 2.5, 0.0 }, 977 { 2.0 / 3.0, -1.0 / 3.0, 0.0 } 978 }; 979 return helper_ddtod("Fmod", SDL_fmod, regular_cases, SDL_arraysize(regular_cases)); 980} 981 982/** 983 * Inputs: values in the range [0, UINT32_MAX] divided by 1.0. 984 * Expected: Positive zero is always returned. 985 */ 986static int SDLCALL 987fmod_rangeTest(void *args) 988{ 989 Uint32 i; 990 double test_value = 0.0; 991 992 SDLTest_AssertPass("Fmod: Testing a range of %u values with steps of %" SDL_PRIu32, 993 RANGE_TEST_ITERATIONS, 994 RANGE_TEST_STEP); 995 996 for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) { 997 double result; 998 /* These are tested elsewhere */ 999 if (ISNAN(test_value) || ISINF(test_value)) { 1000 continue; 1001 } 1002 1003 /* Only log failures to save performances */ 1004 result = SDL_fmod(test_value, 1.0); 1005 if (0.0 != result) { 1006 SDLTest_AssertCheck(false, 1007 "Fmod(%.1f,%.1f), expected %.1f, got %.1f", 1008 test_value, 1.0, 0.0, result); 1009 return TEST_ABORTED; 1010 } 1011 } 1012 return TEST_COMPLETED; 1013} 1014 1015/* SDL_exp tests functions */ 1016 1017/** 1018 * Inputs: +/-Infinity. 1019 * Expected: Infinity is returned as-is. 1020 */ 1021static int SDLCALL 1022exp_infCases(void *args) 1023{ 1024 double result; 1025 1026 result = SDL_exp(INFINITY); 1027 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1028 "Exp(%f), expected %f, got %f", 1029 INFINITY, INFINITY, result); 1030 1031 result = SDL_exp(-INFINITY); 1032 SDLTest_AssertCheck(0.0 == result, 1033 "Exp(%f), expected %f, got %f", 1034 -INFINITY, 0.0, result); 1035 1036 return TEST_COMPLETED; 1037} 1038 1039/** 1040 * Inputs: +/-0.0. 1041 * Expected: 1.0 is returned. 1042 */ 1043static int SDLCALL 1044exp_zeroCases(void *args) 1045{ 1046 const d_to_d zero_cases[] = { 1047 { 0.0, 1.0 }, 1048 { -0.0, 1.0 } 1049 }; 1050 return helper_dtod("Exp", SDL_exp, zero_cases, SDL_arraysize(zero_cases)); 1051} 1052 1053/** 1054 * Input: 710.0 (overflows for 64bits double). 1055 * Expected: Infinity is returned. 1056 * NOTE: This test is skipped for double types larger than 64 bits. 1057 */ 1058static int SDLCALL 1059exp_overflowCase(void *args) 1060{ 1061 double result; 1062 1063 const bool double_is_larger_than_64bit = sizeof(double) > 8; 1064 if (double_is_larger_than_64bit) { 1065 return TEST_SKIPPED; 1066 } 1067 1068 result = SDL_exp(710.0); 1069 SDLTest_AssertCheck(ISINF(result), 1070 "Exp(%f), expected %f, got %f", 1071 710.0, INFINITY, result); 1072 return TEST_COMPLETED; 1073} 1074 1075/** 1076 * Input: 1.0 1077 * Expected: The euler constant. 1078 */ 1079static int SDLCALL 1080exp_baseCase(void *args) 1081{ 1082 const double result = SDL_exp(1.0); 1083 SDLTest_AssertCheck(result >= EULER - EPSILON && 1084 result <= EULER + EPSILON, 1085 "Exp(%f), expected [%f,%f], got %f", 1086 1.0, EULER - EPSILON, EULER + EPSILON, result); 1087 return TEST_COMPLETED; 1088} 1089 1090/** 1091 * Inputs: values within the domain of the function. 1092 * Expected: the correct result is returned. 1093 */ 1094static int SDLCALL 1095exp_regularCases(void *args) 1096{ 1097 /* Hexadecimal floating constants are not supported on C89 compilers */ 1098 const d_to_d regular_cases[] = { 1099 { -101.0, 1.36853947117385291381565719268793547578002532127613087E-44 }, 1100 { -15.73, 0.00000014741707833928422931856502906683425990763681 }, 1101 { -1.0, 0.36787944117144233402427744294982403516769409179688 }, 1102 { -0.5, 0.60653065971263342426311737654032185673713684082031 }, 1103 { 0.5, 1.64872127070012819416433558217249810695648193359375 }, 1104 { 2.25, 9.48773583635852624240669683786109089851379394531250 }, 1105 { 34.125, 661148770968660.375 }, 1106 { 112.89, 10653788283588960962604279261058893737879589093376.0 }, 1107 { 539.483, 1970107755334319939701129934673541628417235942656909222826926175622435588279443011110464355295725187195188154768877850257012251677751742837992843520967922303961718983154427294786640886286983037548604937796221048661733679844353544028160.0 }, 1108 }; 1109 return helper_dtod_inexact("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases)); 1110} 1111 1112/* SDL_log tests functions */ 1113 1114/** 1115 * Inputs: Positive Infinity and +/-0.0. 1116 * Expected: Positive and negative Infinity respectively. 1117 */ 1118static int SDLCALL 1119log_limitCases(void *args) 1120{ 1121 double result; 1122 1123 result = SDL_log(INFINITY); 1124 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1125 "Log(%f), expected %f, got %f", 1126 INFINITY, INFINITY, result); 1127 1128 result = SDL_log(0.0); 1129 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 1130 "Log(%f), expected %f, got %f", 1131 0.0, -INFINITY, result); 1132 1133 result = SDL_log(-0.0); 1134 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 1135 "Log(%f), expected %f, got %f", 1136 -0.0, -INFINITY, result); 1137 1138 return TEST_COMPLETED; 1139} 1140 1141/** 1142 * Inputs: 1.0 and the Euler constant. 1143 * Expected: 0.0 and 1.0 respectively. 1144 */ 1145static int SDLCALL 1146log_baseCases(void *args) 1147{ 1148 double result; 1149 1150 result = SDL_log(1.0); 1151 SDLTest_AssertCheck(0.0 == result, 1152 "Log(%f), expected %f, got %f", 1153 1.0, 0.0, result); 1154 1155 result = SDL_log(EULER); 1156 SDLTest_AssertCheck(SDL_fabs(result - 1.) < FLT_EPSILON, 1157 "Log(%f), expected %f, got %f", 1158 EULER, 1.0, result); 1159 1160 return TEST_COMPLETED; 1161} 1162 1163/** 1164 * Inputs: NAN and a negative value. 1165 * Expected: NAN is returned. 1166 */ 1167static int SDLCALL 1168log_nanCases(void *args) 1169{ 1170 double result; 1171 1172 result = SDL_log(NAN); 1173 SDLTest_AssertCheck(ISNAN(result), 1174 "Log(%f), expected %f, got %f", 1175 NAN, NAN, result); 1176 1177 result = SDL_log(-1234.5678); 1178 SDLTest_AssertCheck(ISNAN(result), 1179 "Log(%f), expected %f, got %f", 1180 -1234.5678, NAN, result); 1181 1182 return TEST_COMPLETED; 1183} 1184 1185/** 1186 * Inputs: values within the domain of the function. 1187 * Expected: the correct result is returned. 1188 */ 1189static int SDLCALL 1190log_regularCases(void *args) 1191{ 1192 const d_to_d regular_cases[] = { 1193 { 5.0, 1.60943791243410028179994242236716672778129577636718750 }, 1194 { 10.0, 2.302585092994045901093613792909309267997741699218750 }, 1195 { 56.32, 4.031049711849786554296315443934872746467590332031250 }, 1196 { 789.123, 6.670922202231861497523368598194792866706848144531250 }, 1197 { 2734.876324, 7.91384149408957959792587644187733530998229980468750 } 1198 }; 1199 return helper_dtod("Log", SDL_log, regular_cases, SDL_arraysize(regular_cases)); 1200} 1201 1202/* SDL_log10 tests functions */ 1203 1204/** 1205 * Inputs: Positive Infinity and +/-0.0. 1206 * Expected: Positive and negative Infinity respectively. 1207 */ 1208static int SDLCALL 1209log10_limitCases(void *args) 1210{ 1211 double result; 1212 1213 result = SDL_log10(INFINITY); 1214 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1215 "Log10(%f), expected %f, got %f", 1216 INFINITY, INFINITY, result); 1217 1218 result = SDL_log10(0.0); 1219 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 1220 "Log10(%f), expected %f, got %f", 1221 0.0, -INFINITY, result); 1222 1223 result = SDL_log10(-0.0); 1224 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 1225 "Log10(%f), expected %f, got %f", 1226 -0.0, -INFINITY, result); 1227 1228 return TEST_COMPLETED; 1229} 1230 1231/** 1232 * Inputs: Powers of ten from 0 to 9. 1233 * Expected: the exact power of ten is returned. 1234 */ 1235static int SDLCALL 1236log10_baseCases(void *args) 1237{ 1238 const d_to_d base_cases[] = { 1239 { 1.0, 0.0 }, 1240 { 10.0, 1.0 }, 1241 { 100.0, 2.0 }, 1242 { 1000.0, 3.0 }, 1243 { 10000.0, 4.0 }, 1244 { 100000.0, 5.0 }, 1245 { 1000000.0, 6.0 }, 1246 { 10000000.0, 7.0 }, 1247 { 100000000.0, 8.0 }, 1248 { 1000000000.0, 9.0 }, 1249 }; 1250 return helper_dtod("Log10", SDL_log10, base_cases, SDL_arraysize(base_cases)); 1251} 1252 1253/** 1254 * Inputs: NAN and a negative value. 1255 * Expected: NAN is returned. 1256 */ 1257static int SDLCALL 1258log10_nanCases(void *args) 1259{ 1260 double result; 1261 1262 result = SDL_log10(NAN); 1263 SDLTest_AssertCheck(ISNAN(result), 1264 "Log10(%f), expected %f, got %f", 1265 NAN, NAN, result); 1266 1267 result = SDL_log10(-1234.5678); 1268 SDLTest_AssertCheck(ISNAN(result), 1269 "Log10(%f), expected %f, got %f", 1270 -1234.5678, NAN, result); 1271 1272 return TEST_COMPLETED; 1273} 1274 1275/** 1276 * Inputs: values within the domain of the function. 1277 * Expected: the correct result is returned. 1278 */ 1279static int SDLCALL 1280log10_regularCases(void *args) 1281{ 1282 const d_to_d regular_cases[] = { 1283 { 5.0, 0.698970004336018857493684208748163655400276184082031250 }, 1284 { 12.5, 1.09691001300805646145875016372883692383766174316406250 }, 1285 { 56.32, 1.750662646134055755453573510749265551567077636718750 }, 1286 { 789.123, 2.8971447016351858927407647570362314581871032714843750 }, 1287 { 2734.876324, 3.436937691540090433761633903486654162406921386718750 } 1288 }; 1289 return helper_dtod_inexact("Log10", SDL_log10, regular_cases, SDL_arraysize(regular_cases)); 1290} 1291 1292/* SDL_modf tests functions */ 1293 1294static int SDLCALL 1295modf_baseCases(void *args) 1296{ 1297 double fractional, integral; 1298 1299 fractional = SDL_modf(1.25, &integral); 1300 SDLTest_AssertCheck(integral == 1.0, 1301 "modf(%f), expected integral %f, got %f", 1302 1.25, 1.0, integral); 1303 SDLTest_AssertCheck(fractional == 0.25, 1304 "modf(%f), expected fractional %f, got %f", 1305 1.25, 0.25, fractional); 1306 1307 return TEST_COMPLETED; 1308} 1309 1310/* SDL_pow tests functions */ 1311 1312/* Tests with positive and negative infinities as exponents */ 1313 1314/** 1315 * Inputs: (-1.0, +/-Infinity). 1316 * Expected: 1.0 is returned. 1317 */ 1318static int SDLCALL 1319pow_baseNOneExpInfCases(void *args) 1320{ 1321 double result; 1322 1323 result = SDL_pow(-1.0, INFINITY); 1324 SDLTest_AssertCheck(1.0 == result, 1325 "Pow(%f,%f), expected %f, got %f", 1326 -1.0, INFINITY, 1.0, result); 1327 1328 result = SDL_pow(-1.0, -INFINITY); 1329 SDLTest_AssertCheck(1.0 == result, 1330 "Pow(%f,%f), expected %f, got %f", 1331 -1.0, -INFINITY, 1.0, result); 1332 1333 return TEST_COMPLETED; 1334} 1335/** 1336 * Inputs: (+/-0.0, -Infinity). 1337 * Expected: Infinity is returned. 1338 */ 1339static int SDLCALL 1340pow_baseZeroExpNInfCases(void *args) 1341{ 1342 double result; 1343 1344 result = SDL_pow(0.0, -INFINITY); 1345 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1346 "Pow(%f,%f), expected %f, got %f", 1347 0.0, -INFINITY, INFINITY, result); 1348 1349 result = SDL_pow(-0.0, -INFINITY); 1350 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1351 "Pow(%f,%f), expected %f, got %f", 1352 -0.0, -INFINITY, INFINITY, result); 1353 1354 return TEST_COMPLETED; 1355} 1356 1357/** 1358 * Inputs: (x, +/-Infinity) where x is not +/-0.0. 1359 * Expected: 0.0 when x < 1, Infinity when x > 1. 1360 */ 1361static int SDLCALL 1362pow_expInfCases(void *args) 1363{ 1364 double result; 1365 1366 result = SDL_pow(0.5, INFINITY); 1367 SDLTest_AssertCheck(0.0 == result, 1368 "Pow(%f,%f), expected %f, got %f", 1369 0.5, INFINITY, 0.0, result); 1370 1371 result = SDL_pow(1.5, INFINITY); 1372 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1373 "Pow(%f,%f), expected %f, got %f", 1374 1.5, INFINITY, INFINITY, result); 1375 1376 result = SDL_pow(0.5, -INFINITY); 1377 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1378 "Pow(%f,%f), expected %f, got %f", 1379 0.5, INFINITY, INFINITY, result); 1380 1381 result = SDL_pow(1.5, -INFINITY); 1382 SDLTest_AssertCheck(0.0 == result, 1383 "Pow(%f,%f), expected %f, got %f", 1384 1.5, -INFINITY, 0.0, result); 1385 1386 return TEST_COMPLETED; 1387} 1388 1389/* Tests with positive and negative infinities as base */ 1390 1391/** 1392 * Inputs: (Positive Infinity, x) where x is not +/-0.0. 1393 * Expected: 0.0 when x is < 0, positive Infinity when x > 0. 1394 */ 1395static int SDLCALL 1396pow_basePInfCases(void *args) 1397{ 1398 double result; 1399 1400 result = SDL_pow(INFINITY, -3.0); 1401 SDLTest_AssertCheck(0.0 == result, 1402 "Pow(%f,%f), expected %f, got %f", 1403 INFINITY, -3.0, 0.0, result); 1404 1405 result = SDL_pow(INFINITY, 2.0); 1406 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1407 "Pow(%f,%f), expected %f, got %f", 1408 INFINITY, 2.0, INFINITY, result); 1409 1410 result = SDL_pow(INFINITY, -2.12345); 1411 SDLTest_AssertCheck(0.0 == result, 1412 "Pow(%f,%f), expected %f, got %f", 1413 INFINITY, -2.12345, 0.0, result); 1414 1415 result = SDL_pow(INFINITY, 3.1345); 1416 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1417 "Pow(%f,%f), expected %f, got %f", 1418 INFINITY, 3.12345, INFINITY, result); 1419 1420 return TEST_COMPLETED; 1421} 1422 1423/** 1424 * Inputs: (Negative Infinity, x) where x is not +/-0.0. 1425 * Expected: 1426 * - -0.0 when x is a negative odd integer, 1427 * - 0.0 when x is a negative even integer or negative non-integer, 1428 * - Negative Infinity when x is a positive odd integer, 1429 * - Positive Infinity when x is a positive even integer or positive non-integer. 1430 */ 1431static int SDLCALL 1432pow_baseNInfCases(void *args) 1433{ 1434 double result; 1435 1436 result = SDL_pow(-INFINITY, -3.0); 1437 SDLTest_AssertCheck(-0.0 == result, 1438 "Pow(%f,%f), expected %f, got %f", 1439 -INFINITY, -3.0, -0.0, result); 1440 1441 result = SDL_pow(-INFINITY, -2.0); 1442 SDLTest_AssertCheck(0.0 == result, 1443 "Pow(%f,%f), expected %f, got %f", 1444 -INFINITY, -2.0, 0.0, result); 1445 1446 result = SDL_pow(-INFINITY, -5.5); 1447 SDLTest_AssertCheck(0.0 == result, 1448 "Pow(%f,%f), expected %f, got %f", 1449 -INFINITY, -5.5, 0.0, result); 1450 1451 result = SDL_pow(-INFINITY, 3.0); 1452 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 1453 "Pow(%f,%f), expected %f, got %f", 1454 -INFINITY, 3.0, -INFINITY, result); 1455 1456 result = SDL_pow(-INFINITY, 2.0); 1457 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1458 "Pow(%f,%f), expected %f, got %f", 1459 -INFINITY, 2.0, INFINITY, result); 1460 1461 result = SDL_pow(-INFINITY, 5.5); 1462 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1463 "Pow(%f,%f), expected %f, got %f", 1464 -INFINITY, 5.5, INFINITY, result); 1465 1466 return TEST_COMPLETED; 1467} 1468 1469/* Tests related to NAN */ 1470 1471/** 1472 * Inputs: 1473 * - finite and negative base, 1474 * - finite and non-integer exponent. 1475 * Expected: NAN is returned. 1476 */ 1477static int SDLCALL 1478pow_badOperationCase(void *args) 1479{ 1480 const double result = SDL_pow(-2.0, 4.2); 1481 SDLTest_AssertCheck(ISNAN(result), 1482 "Pow(%f,%f), expected %f, got %f", 1483 -2.0, 4.2, NAN, result); 1484 return TEST_COMPLETED; 1485} 1486 1487/** 1488 * Inputs: (1.0, NAN) 1489 * Expected: 1.0 is returned. 1490 */ 1491static int SDLCALL 1492pow_base1ExpNanCase(void *args) 1493{ 1494 const double result = SDL_pow(1.0, NAN); 1495 SDLTest_AssertCheck(1.0 == result, 1496 "Pow(%f,%f), expected %f, got %f", 1497 1.0, NAN, 1.0, result); 1498 return TEST_COMPLETED; 1499} 1500 1501/** 1502 * Inputs: (NAN, +/-0.0) 1503 * Expected: 1.0 is returned. 1504 */ 1505static int SDLCALL 1506pow_baseNanExp0Cases(void *args) 1507{ 1508 double result; 1509 1510 result = SDL_pow(NAN, 0.0); 1511 SDLTest_AssertCheck(1.0 == result, 1512 "Pow(%f,%f), expected %f, got %f", 1513 NAN, 0.0, 1.0, result); 1514 1515 result = SDL_pow(NAN, -0.0); 1516 SDLTest_AssertCheck(1.0 == result, 1517 "Pow(%f,%f), expected %f, got %f", 1518 NAN, -0.0, 1.0, result); 1519 1520 return TEST_COMPLETED; 1521} 1522 1523/** 1524 * Inputs: NAN as base, exponent or both. 1525 * Expected: NAN is returned. 1526 */ 1527static int SDLCALL 1528pow_nanArgsCases(void *args) 1529{ 1530 double result; 1531 1532 result = SDL_pow(7.8, NAN); 1533 SDLTest_AssertCheck(ISNAN(result), 1534 "Pow(%f,%f), expected %f, got %f", 1535 7.8, NAN, NAN, result); 1536 1537 result = SDL_pow(NAN, 10.0); 1538 SDLTest_AssertCheck(ISNAN(result), 1539 "Pow(%f,%f), expected %f, got %f", 1540 NAN, 10.0, NAN, result); 1541 1542 result = SDL_pow(NAN, NAN); 1543 SDLTest_AssertCheck(ISNAN(result), 1544 "Pow(%f,%f), expected %f, got %f", 1545 NAN, NAN, NAN, result); 1546 1547 return TEST_COMPLETED; 1548} 1549 1550/* Tests with positive and negative zeros as base */ 1551 1552/** 1553 * Inputs: (-0.0, x) where x is an odd integer. 1554 * Expected: 1555 * - Negative Infinity with a negative exponent, 1556 * - -0.0 with a positive exponent. 1557 */ 1558static int SDLCALL 1559pow_baseNZeroExpOddCases(void *args) 1560{ 1561 double result; 1562 1563 result = SDL_pow(-0.0, -3.0); 1564 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 1565 "Pow(%f,%f), expected %f, got %f", 1566 -0.0, -3.0, -INFINITY, result); 1567 1568 result = SDL_pow(-0.0, 3.0); 1569 SDLTest_AssertCheck(-0.0 == result, 1570 "Pow(%f,%f), expected %f, got %f", 1571 -0.0, 3.0, -0.0, result); 1572 1573 return TEST_COMPLETED; 1574} 1575 1576/** 1577 * Inputs: (0.0, x) where x is an odd integer. 1578 * Expected: 1579 * - 0.0 with a positive exponent, 1580 * - Positive Infinity with a negative exponent. 1581 */ 1582static int SDLCALL 1583pow_basePZeroExpOddCases(void *args) 1584{ 1585 double result; 1586 1587 result = SDL_pow(0.0, -5.0); 1588 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1589 "Pow(%f,%f), expected %f, got %f", 1590 0.0, -5.0, INFINITY, result); 1591 1592 result = SDL_pow(0.0, 5.0); 1593 SDLTest_AssertCheck(0.0 == result, 1594 "Pow(%f,%f), expected %f, got %f", 1595 0.0, 5.0, 0.0, result); 1596 1597 return TEST_COMPLETED; 1598} 1599 1600/** 1601 * Inputs: (-0.0, x), with x either: 1602 * - finite and even, 1603 * - finite and non-integer. 1604 * Expected: 1605 * - Positive Infinity if the exponent is negative, 1606 * - 0.0 if the exponent is positive. 1607 */ 1608static int SDLCALL 1609pow_baseNZeroCases(void *args) 1610{ 1611 double result; 1612 1613 result = SDL_pow(-0.0, -3.5); 1614 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1615 "Pow(%f,%f), expected %f, got %f", 1616 -0.0, -3.5, INFINITY, result); 1617 1618 result = SDL_pow(-0.0, -4.0); 1619 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1620 "Pow(%f,%f), expected %f, got %f", 1621 -0.0, -4.0, INFINITY, result); 1622 1623 result = SDL_pow(-0.0, 3.5); 1624 SDLTest_AssertCheck(0.0 == result, 1625 "Pow(%f,%f), expected %f, got %f", 1626 -0.0, 3.5, 0.0, result); 1627 1628 result = SDL_pow(-0.0, 4.0); 1629 SDLTest_AssertCheck(0.0 == result, 1630 "Pow(%f,%f), expected %f, got %f", 1631 -0.0, 4.0, 0.0, result); 1632 1633 return TEST_COMPLETED; 1634} 1635 1636/** 1637 * Inputs: (0.0, x), with x either: 1638 * - finite and even, 1639 * - finite and non-integer. 1640 * Expected: 1641 * - Positive Infinity if the exponent is negative, 1642 * - 0.0 if the exponent is positive. 1643 */ 1644static int SDLCALL 1645pow_basePZeroCases(void *args) 1646{ 1647 double result; 1648 1649 result = SDL_pow(0.0, -3.5); 1650 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1651 "Pow(%f,%f), expected %f, got %f", 1652 0.0, -3.5, INFINITY, result); 1653 1654 result = SDL_pow(0.0, -4.0); 1655 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1656 "Pow(%f,%f), expected %f, got %f", 1657 0.0, -4.0, INFINITY, result); 1658 1659 result = SDL_pow(0.0, 3.5); 1660 SDLTest_AssertCheck(0.0 == result, 1661 "Pow(%f,%f), expected %f, got %f", 1662 0.0, 3.5, 0.0, result); 1663 1664 result = SDL_pow(0.0, 4.0); 1665 SDLTest_AssertCheck(0.0 == result, 1666 "Pow(%f,%f), expected %f, got %f", 1667 0.0, 4.0, 0.0, result); 1668 1669 return TEST_COMPLETED; 1670} 1671 1672/* Remaining tests */ 1673 1674/** 1675 * Inputs: values within the domain of the function. 1676 * Expected: the correct result is returned. 1677 */ 1678static int SDLCALL 1679pow_regularCases(void *args) 1680{ 1681 const dd_to_d regular_cases[] = { 1682#if 0 /* These tests fail when using the Mingw C runtime, we'll disable them for now */ 1683 { -391.25, -2.0, 0.00000653267870448815438463212659780943170062528224661946296691894531250 }, 1684 { -72.3, 12.0, 20401381050275984310272.0 }, 1685#endif 1686 { -5.0, 3.0, -125.0 }, 1687 { 3.0, 2.5, 15.58845726811989607085706666111946105957031250 }, 1688 { 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 }, 1689 { 478.972, 12.125, 315326359630449587856007411793920.0 } 1690 }; 1691 return helper_ddtod_inexact("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases)); 1692} 1693 1694/** 1695 * Inputs: (2.0, x), with x in range [0, 8]. 1696 * Expected: the correct result is returned. 1697 */ 1698static int SDLCALL 1699pow_powerOfTwo(void *args) 1700{ 1701 const dd_to_d power_of_two_cases[] = { 1702 { 2.0, 1.0, 2.0 }, 1703 { 2.0, 2.0, 4.0 }, 1704 { 2.0, 3.0, 8.0 }, 1705 { 2.0, 4.0, 16.0 }, 1706 { 2.0, 5.0, 32.0 }, 1707 { 2.0, 6.0, 64.0 }, 1708 { 2.0, 7.0, 128.0 }, 1709 { 2.0, 8.0, 256.0 }, 1710 }; 1711 return helper_ddtod("Pow", SDL_pow, power_of_two_cases, SDL_arraysize(power_of_two_cases)); 1712} 1713 1714/** 1715 * Inputs: values in the range [0, UINT32_MAX] to the power of +/-0.0. 1716 * Expected: 1.0 is always returned. 1717 */ 1718static int SDLCALL 1719pow_rangeTest(void *args) 1720{ 1721 Uint32 i; 1722 double test_value = 0.0; 1723 1724 SDLTest_AssertPass("Pow: Testing a range of %u values with steps of %" SDL_PRIu32, 1725 RANGE_TEST_ITERATIONS, 1726 RANGE_TEST_STEP); 1727 1728 for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) { 1729 double result; 1730 /* These are tested elsewhere */ 1731 if (ISNAN(test_value) || ISINF(test_value)) { 1732 continue; 1733 } 1734 1735 /* Only log failures to save performances */ 1736 result = SDL_pow(test_value, 0.0); 1737 if (result != 1.0) { 1738 SDLTest_AssertCheck(false, 1739 "Pow(%.1f,%.1f), expected %.1f, got %.1f", 1740 test_value, 1.0, 1.0, result); 1741 return TEST_ABORTED; 1742 } 1743 1744 result = SDL_pow(test_value, -0.0); 1745 if (result != 1.0) { 1746 SDLTest_AssertCheck(false, 1747 "Pow(%.1f,%.1f), expected %.1f, got %.1f", 1748 test_value, -0.0, 1.0, result); 1749 return TEST_ABORTED; 1750 } 1751 } 1752 return TEST_COMPLETED; 1753} 1754 1755/* SDL_sqrt tests functions */ 1756 1757/** 1758 * Input: Positive Infinity. 1759 * Expected: Positive Infinity is returned. 1760 */ 1761static int SDLCALL 1762sqrt_infCase(void *args) 1763{ 1764 const double result = SDL_sqrt(INFINITY); 1765 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1766 "Sqrt(%f), expected %f, got %f", 1767 INFINITY, INFINITY, result); 1768 return TEST_COMPLETED; 1769} 1770 1771/** 1772 * Input: NAN. 1773 * Expected: NAN is returned. 1774 */ 1775static int SDLCALL 1776sqrt_nanCase(void *args) 1777{ 1778 const double result = SDL_sqrt(NAN); 1779 SDLTest_AssertCheck(ISNAN(result), 1780 "Sqrt(%f), expected %f, got %f", 1781 NAN, NAN, result); 1782 return TEST_COMPLETED; 1783} 1784 1785/** 1786 * Inputs: values outside the domain of the function. 1787 * Expected: NAN is returned. 1788 */ 1789static int SDLCALL 1790sqrt_outOfDomainCases(void *args) 1791{ 1792 double result; 1793 1794 result = SDL_sqrt(-1.0); 1795 SDLTest_AssertCheck(ISNAN(result), 1796 "Sqrt(%f), expected %f, got %f", 1797 -1.0, NAN, result); 1798 1799 result = SDL_sqrt(-12345.6789); 1800 SDLTest_AssertCheck(ISNAN(result), 1801 "Sqrt(%f), expected %f, got %f", 1802 -12345.6789, NAN, result); 1803 1804 result = SDL_sqrt(-INFINITY); 1805 SDLTest_AssertCheck(ISNAN(result), 1806 "Sqrt(%f), expected %f, got %f", 1807 -INFINITY, NAN, result); 1808 1809 return TEST_COMPLETED; 1810} 1811 1812/** 1813 * Inputs: +/-0.0 and 1.0. 1814 * Expected: the input value is returned as-is. 1815 */ 1816static int SDLCALL 1817sqrt_baseCases(void *args) 1818{ 1819 const d_to_d base_cases[] = { 1820 { -0.0, -0.0 }, 1821 { 0.0, 0.0 }, 1822 { 1.0, 1.0 } 1823 }; 1824 return helper_dtod("Sqrt", SDL_sqrt, base_cases, SDL_arraysize(base_cases)); 1825} 1826 1827/** 1828 * Inputs: values within the domain of the function. 1829 * Expected: the correct result is returned. 1830 */ 1831static int SDLCALL 1832sqrt_regularCases(void *args) 1833{ 1834 const d_to_d regular_cases[] = { 1835 { 4.0, 2.0 }, 1836 { 9.0, 3.0 }, 1837 { 27.2, 5.21536192416211896727418206864967942237854003906250 }, 1838 { 240.250, 15.5 }, 1839 { 1337.0, 36.565010597564445049556525191292166709899902343750 }, 1840 { 2887.12782400000014604302123188972473144531250, 53.732 }, 1841 { 65600.0156250, 256.125 } 1842 }; 1843 return helper_dtod_inexact("Sqrt", SDL_sqrt, regular_cases, SDL_arraysize(regular_cases)); 1844} 1845 1846/* SDL_scalbn tests functions */ 1847 1848/** 1849 * Input: (+/-Infinity, 1). 1850 * Expected: Infinity is returned as-is. 1851 */ 1852static int SDLCALL 1853scalbn_infCases(void *args) 1854{ 1855 double result; 1856 1857 result = SDL_scalbn(INFINITY, 1); 1858 SDLTest_AssertCheck(IS_INFINITY(result) && result > 0, 1859 "Scalbn(%f,%d), expected %f, got %f", 1860 INFINITY, 1, INFINITY, result); 1861 1862 result = SDL_scalbn(-INFINITY, 1); 1863 SDLTest_AssertCheck(IS_INFINITY(result) && result < 0, 1864 "Scalbn(%f,%d), expected %f, got %f", 1865 -INFINITY, 1, -INFINITY, result); 1866 1867 return TEST_COMPLETED; 1868} 1869 1870/** 1871 * Inputs: (+/-0.0, 1). 1872 * Expected: Zero is returned as-is. 1873 */ 1874static int SDLCALL 1875scalbn_baseZeroCases(void *args) 1876{ 1877 double result; 1878 1879 result = SDL_scalbn(0.0, 1); 1880 SDLTest_AssertCheck(0.0 == result, 1881 "Scalbn(%f,%d), expected %f, got %f", 1882 0.0, 1, 0.0, result); 1883 1884 result = SDL_scalbn(-0.0, 1); 1885 SDLTest_AssertCheck(-0.0 == result, 1886 "Scalbn(%f,%d), expected %f, got %f", 1887 -0.0, 1, -0.0, result); 1888 1889 return TEST_COMPLETED; 1890} 1891 1892/** 1893 * Input: (x, 0) 1894 * Expected: x is returned as-is. 1895 */ 1896static int SDLCALL 1897scalbn_expZeroCase(void *args) 1898{ 1899 const double result = SDL_scalbn(42.0, 0); 1900 SDLTest_AssertCheck(42.0 == result, 1901 "Scalbn(%f,%d), expected %f, got %f", 1902 42.0, 0, 42.0, result); 1903 return TEST_COMPLETED; 1904} 1905 1906/** 1907 * Input: (NAN, x). 1908 * Expected: NAN is returned. 1909 */ 1910static int SDLCALL 1911scalbn_nanCase(void *args) 1912{ 1913 const double result = SDL_scalbn(NAN, 2); 1914 SDLTest_AssertCheck(ISNAN(result), 1915 "Scalbn(%f,%d), expected %f, got %f", 1916 NAN, 2, NAN, result); 1917 return TEST_COMPLETED; 1918} 1919 1920/** 1921 * Inputs: values inside the domain of the function. 1922 * Expected: the correct result is returned. 1923 * NOTE: This test depends on SDL_pow and FLT_RADIX. 1924 */ 1925static int SDLCALL 1926scalbn_regularCases(void *args) 1927{ 1928 double result, expected; 1929 1930 result = SDL_scalbn(2.0, 2); 1931 expected = 2.0 * SDL_pow(FLT_RADIX, 2); 1932 SDLTest_AssertCheck(result == expected, 1933 "Scalbn(%f,%d), expected %f, got %f", 1934 2.0, 2, expected, result); 1935 1936 result = SDL_scalbn(1.0, 13); 1937 expected = 1.0 * SDL_pow(FLT_RADIX, 13); 1938 SDLTest_AssertCheck(result == expected, 1939 "Scalbn(%f,%d), expected %f, got %f", 1940 1.0, 13, expected, result); 1941 1942 result = SDL_scalbn(2.0, -5); 1943 expected = 2.0 * SDL_pow(FLT_RADIX, -5); 1944 SDLTest_AssertCheck(result == expected, 1945 "Scalbn(%f,%d), expected %f, got %f", 1946 2.0, -5, expected, result); 1947 1948 result = SDL_scalbn(-1.0, -13); 1949 expected = -1.0 * SDL_pow(FLT_RADIX, -13); 1950 SDLTest_AssertCheck(result == expected, 1951 "Scalbn(%f,%d), expected %f, got %f", 1952 -1.0, -13, expected, result); 1953 1954 return TEST_COMPLETED; 1955} 1956 1957/* SDL_cos tests functions */ 1958 1959/** 1960 * Inputs: +/-Infinity. 1961 * Expected: NAN is returned. 1962 */ 1963static int SDLCALL 1964cos_infCases(void *args) 1965{ 1966 double result; 1967 1968 result = SDL_cos(INFINITY); 1969 SDLTest_AssertCheck(ISNAN(result), 1970 "Cos(%f), expected %f, got %f", 1971 INFINITY, NAN, result); 1972 1973 result = SDL_cos(-INFINITY); 1974 SDLTest_AssertCheck(ISNAN(result), 1975 "Cos(%f), expected %f, got %f", 1976 -INFINITY, NAN, result); 1977 1978 return TEST_COMPLETED; 1979} 1980 1981/** 1982 * Input: NAN. 1983 * Expected: NAN is returned. 1984 */ 1985static int SDLCALL 1986cos_nanCase(void *args) 1987{ 1988 const double result = SDL_cos(NAN); 1989 SDLTest_AssertCheck(ISNAN(result), 1990 "Cos(%f), expected %f, got %f", 1991 NAN, NAN, result); 1992 return TEST_COMPLETED; 1993} 1994 1995/** 1996 * Inputs: +/-0.0 and +/-Pi. 1997 * Expected: +1.0 and -1.0 respectively. 1998 */ 1999static int SDLCALL 2000cos_regularCases(void *args) 2001{ 2002 const d_to_d regular_cases[] = { 2003 { -SDL_PI_D, -1.0 }, 2004 { -0.0, 1.0 }, 2005 { 0.0, 1.0 }, 2006 { SDL_PI_D, -1.0 } 2007 }; 2008 return helper_dtod("Cos", SDL_cos, regular_cases, SDL_arraysize(regular_cases)); 2009} 2010 2011/** 2012 * Inputs: Angles between 1/10 and 9/10 of Pi (positive and negative). 2013 * Expected: The correct result is returned (+/-EPSILON). 2014 */ 2015static int SDLCALL 2016cos_precisionTest(void *args) 2017{ 2018 const d_to_d precision_cases[] = { 2019 { SDL_PI_D * 1.0 / 10.0, 0.9510565162951535 }, 2020 { SDL_PI_D * 2.0 / 10.0, 0.8090169943749475 }, 2021 { SDL_PI_D * 3.0 / 10.0, 0.5877852522924731 }, 2022 { SDL_PI_D * 4.0 / 10.0, 0.30901699437494745 }, 2023 { SDL_PI_D * 5.0 / 10.0, 0.0 }, 2024 { SDL_PI_D * 6.0 / 10.0, -0.30901699437494734 }, 2025 { SDL_PI_D * 7.0 / 10.0, -0.587785252292473 }, 2026 { SDL_PI_D * 8.0 / 10.0, -0.8090169943749473 }, 2027 { SDL_PI_D * 9.0 / 10.0, -0.9510565162951535 }, 2028 { SDL_PI_D * -1.0 / 10.0, 0.9510565162951535 }, 2029 { SDL_PI_D * -2.0 / 10.0, 0.8090169943749475 }, 2030 { SDL_PI_D * -3.0 / 10.0, 0.5877852522924731 }, 2031 { SDL_PI_D * -4.0 / 10.0, 0.30901699437494745 }, 2032 { SDL_PI_D * -5.0 / 10.0, 0.0 }, 2033 { SDL_PI_D * -6.0 / 10.0, -0.30901699437494734 }, 2034 { SDL_PI_D * -7.0 / 10.0, -0.587785252292473 }, 2035 { SDL_PI_D * -8.0 / 10.0, -0.8090169943749473 }, 2036 { SDL_PI_D * -9.0 / 10.0, -0.9510565162951535 } 2037 }; 2038 return helper_dtod_inexact("Cos", SDL_cos, precision_cases, SDL_arraysize(precision_cases)); 2039} 2040 2041/** 2042 * Inputs: Values in the range [0, UINT32_MAX]. 2043 * Expected: A value between 0 and 1 is returned. 2044 */ 2045static int SDLCALL 2046cos_rangeTest(void *args) 2047{ 2048 Uint32 i; 2049 double test_value = 0.0; 2050 2051 SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %" SDL_PRIu32, 2052 RANGE_TEST_ITERATIONS, 2053 RANGE_TEST_STEP); 2054 2055 for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) { 2056 double result; 2057 /* These are tested elsewhere */ 2058 if (ISNAN(test_value) || ISINF(test_value)) { 2059 continue; 2060 } 2061 2062 /* Only log failures to save performances */ 2063 result = SDL_cos(test_value); 2064 if (result < -1.0 || result > 1.0) { 2065 SDLTest_AssertCheck(false, 2066 "Cos(%.1f), expected [%.1f,%.1f], got %.1f", 2067 test_value, -1.0, 1.0, result); 2068 return TEST_ABORTED; 2069 } 2070 } 2071 return TEST_COMPLETED; 2072} 2073 2074/* SDL_sin tests functions */ 2075 2076/** 2077 * Inputs: +/-Infinity. 2078 * Expected: NAN is returned. 2079 */ 2080static int SDLCALL 2081sin_infCases(void *args) 2082{ 2083 double result; 2084 2085 result = SDL_sin(INFINITY); 2086 SDLTest_AssertCheck(ISNAN(result), 2087 "Sin(%f), expected %f, got %f", 2088 INFINITY, NAN, result); 2089 2090 result = SDL_sin(-INFINITY); 2091 SDLTest_AssertCheck(ISNAN(result), 2092 "Sin(%f), expected %f, got %f", 2093 -INFINITY, NAN, result); 2094 2095 return TEST_COMPLETED; 2096} 2097 2098/** 2099 * Input: NAN. 2100 * Expected: NAN is returned. 2101 */ 2102static int SDLCALL 2103sin_nanCase(void *args) 2104{ 2105 const double result = SDL_sin(NAN); 2106 SDLTest_AssertCheck(ISNAN(result), 2107 "Sin(%f), expected %f, got %f", 2108 NAN, NAN, result); 2109 return TEST_COMPLETED; 2110} 2111 2112/** 2113 * Inputs: +/-0.0 and +/-Pi/2. 2114 * Expected: +/-0.0 and +/-1.0 respectively. 2115 */ 2116static int SDLCALL 2117sin_regularCases(void *args) 2118{ 2119 const d_to_d regular_cases[] = { 2120 { -SDL_PI_D / 2, -1.0 }, 2121 { -0.0, -0.0 }, 2122 { 0.0, 0.0 }, 2123 { SDL_PI_D / 2, 1.0 } 2124 }; 2125 return helper_dtod("Sin", SDL_sin, regular_cases, SDL_arraysize(regular_cases)); 2126} 2127 2128/** 2129 * Inputs: Angles between 1/10 and 10/10 of Pi (positive and negative). 2130 * Expected: The correct result is returned (+/-EPSILON). 2131 * NOTE: +/-Pi/2 is tested in the regular cases. 2132 */ 2133static int SDLCALL 2134sin_precisionTest(void *args) 2135{ 2136 const d_to_d precision_cases[] = { 2137 { SDL_PI_D * 1.0 / 10.0, 0.3090169943749474 }, 2138 { SDL_PI_D * 2.0 / 10.0, 0.5877852522924731 }, 2139 { SDL_PI_D * 3.0 / 10.0, 0.8090169943749475 }, 2140 { SDL_PI_D * 4.0 / 10.0, 0.9510565162951535 }, 2141 { SDL_PI_D * 6.0 / 10.0, 0.9510565162951536 }, 2142 { SDL_PI_D * 7.0 / 10.0, 0.8090169943749475 }, 2143 { SDL_PI_D * 8.0 / 10.0, 0.5877852522924732 }, 2144 { SDL_PI_D * 9.0 / 10.0, 0.3090169943749475 }, 2145 { SDL_PI_D, 0.0 }, 2146 { SDL_PI_D * -1.0 / 10.0, -0.3090169943749474 }, 2147 { SDL_PI_D * -2.0 / 10.0, -0.5877852522924731 }, 2148 { SDL_PI_D * -3.0 / 10.0, -0.8090169943749475 }, 2149 { SDL_PI_D * -4.0 / 10.0, -0.9510565162951535 }, 2150 { SDL_PI_D * -6.0 / 10.0, -0.9510565162951536 }, 2151 { SDL_PI_D * -7.0 / 10.0, -0.8090169943749475 }, 2152 { SDL_PI_D * -8.0 / 10.0, -0.5877852522924732 }, 2153 { SDL_PI_D * -9.0 / 10.0, -0.3090169943749475 }, 2154 { -SDL_PI_D, 0.0 }, 2155 }; 2156 return helper_dtod_inexact("Sin", SDL_sin, precision_cases, SDL_arraysize(precision_cases)); 2157} 2158 2159/** 2160 * Inputs: Values in the range [0, UINT32_MAX]. 2161 * Expected: A value between 0 and 1 is returned. 2162 */ 2163static int SDLCALL 2164sin_rangeTest(void *args) 2165{ 2166 Uint32 i; 2167 double test_value = 0.0; 2168 2169 SDLTest_AssertPass("Sin: Testing a range of %u values with steps of %" SDL_PRIu32, 2170 RANGE_TEST_ITERATIONS, 2171 RANGE_TEST_STEP); 2172 2173 for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) { 2174 double result; 2175 /* These are tested elsewhere */ 2176 if (ISNAN(test_value) || ISINF(test_value)) { 2177 continue; 2178 } 2179 2180 /* Only log failures to save performances */ 2181 result = SDL_sin(test_value); 2182 if (result < -1.0 || result > 1.0) { 2183 SDLTest_AssertCheck(false, 2184 "Sin(%.1f), expected [%.1f,%.1f], got %.1f", 2185 test_value, -1.0, 1.0, result); 2186 return TEST_ABORTED; 2187 } 2188 } 2189 return TEST_COMPLETED; 2190} 2191 2192/* SDL_tan tests functions */ 2193 2194/** 2195 * Inputs: +/-Infinity. 2196 * Expected: NAN is returned. 2197 */ 2198static int SDLCALL 2199tan_infCases(void *args) 2200{ 2201 double result; 2202 2203 result = SDL_tan(INFINITY); 2204 SDLTest_AssertCheck(ISNAN(result), 2205 "Tan(%f), expected %f, got %f", 2206 INFINITY, NAN, result); 2207 2208 result = SDL_tan(-INFINITY); 2209 SDLTest_AssertCheck(ISNAN(result), 2210 "Tan(%f), expected %f, got %f", 2211 -INFINITY, NAN, result); 2212 2213 return TEST_COMPLETED; 2214} 2215 2216/** 2217 * Input: NAN. 2218 * Expected: NAN is returned. 2219 */ 2220static int SDLCALL 2221tan_nanCase(void *args) 2222{ 2223 const double result = SDL_tan(NAN); 2224 SDLTest_AssertCheck(ISNAN(result), 2225 "Tan(%f), expected %f, got %f", 2226 NAN, NAN, result); 2227 return TEST_COMPLETED; 2228} 2229 2230/** 2231 * Inputs: +/-0.0. 2232 * Expected: Zero is returned as-is. 2233 */ 2234static int SDLCALL 2235tan_zeroCases(void *args) 2236{ 2237 const d_to_d regular_cases[] = { 2238 { -0.0, -0.0 }, 2239 { 0.0, 0.0 } 2240 }; 2241 return helper_dtod("Tan", SDL_tan, regular_cases, SDL_arraysize(regular_cases)); 2242} 2243 2244/** 2245 * Inputs: Angles between 1/11 and 10/11 of Pi (positive and negative). 2246 * Expected: The correct result is returned (+/-EPSILON). 2247 * NOTE: +/-Pi/2 is intentionally avoided as it returns garbage values. 2248 */ 2249static int SDLCALL 2250tan_precisionTest(void *args) 2251{ 2252 const d_to_d precision_cases[] = { 2253 { SDL_PI_D * 1.0 / 11.0, 0.29362649293836673 }, 2254 { SDL_PI_D * 2.0 / 11.0, 0.642660977168331 }, 2255 { SDL_PI_D * 3.0 / 11.0, 1.1540615205330094 }, 2256 { SDL_PI_D * 4.0 / 11.0, 2.189694562989681 }, 2257 { SDL_PI_D * 5.0 / 11.0, 6.9551527717734745 }, 2258 { SDL_PI_D * 6.0 / 11.0, -6.955152771773481 }, 2259 { SDL_PI_D * 7.0 / 11.0, -2.189694562989682 }, 2260 { SDL_PI_D * 8.0 / 11.0, -1.1540615205330096 }, 2261 { SDL_PI_D * 9.0 / 11.0, -0.6426609771683314 }, 2262 { SDL_PI_D * 10.0 / 11.0, -0.2936264929383667 }, 2263 { SDL_PI_D * -1.0 / 11.0, -0.29362649293836673 }, 2264 { SDL_PI_D * -2.0 / 11.0, -0.642660977168331 }, 2265 { SDL_PI_D * -3.0 / 11.0, -1.1540615205330094 }, 2266 { SDL_PI_D * -4.0 / 11.0, -2.189694562989681 }, 2267 { SDL_PI_D * -5.0 / 11.0, -6.9551527717734745 }, 2268 { SDL_PI_D * -6.0 / 11.0, 6.955152771773481 }, 2269 { SDL_PI_D * -7.0 / 11.0, 2.189694562989682 }, 2270 { SDL_PI_D * -8.0 / 11.0, 1.1540615205330096 }, 2271 { SDL_PI_D * -9.0 / 11.0, 0.6426609771683314 }, 2272 { SDL_PI_D * -10.0 / 11.0, 0.2936264929383667 } 2273 }; 2274 return helper_dtod_inexact("Tan", SDL_tan, precision_cases, SDL_arraysize(precision_cases)); 2275} 2276 2277/* SDL_acos tests functions */ 2278 2279/** 2280 * Inputs: +/-1.0. 2281 * Expected: 0.0 and Pi respectively. 2282 */ 2283static int SDLCALL 2284acos_limitCases(void *args) 2285{ 2286 double result; 2287 2288 result = SDL_acos(1.0); 2289 SDLTest_AssertCheck(0.0 == result, 2290 "Acos(%f), expected %f, got %f", 2291 1.0, 0.0, result); 2292 2293 result = SDL_acos(-1.0); 2294 SDLTest_AssertCheck(SDL_fabs(SDL_PI_D - result) <= EPSILON, 2295 "Acos(%f), expected %f, got %f", 2296 -1.0, SDL_PI_D, result); 2297 2298 return TEST_COMPLETED; 2299} 2300 2301/** 2302 * Inputs: Values outside the domain of [-1, 1]. 2303 * Expected: NAN is returned. 2304 */ 2305static int SDLCALL 2306acos_outOfDomainCases(void *args) 2307{ 2308 double result; 2309 2310 result = SDL_acos(1.1); 2311 SDLTest_AssertCheck(ISNAN(result), 2312 "Acos(%f), expected %f, got %f", 2313 1.1, NAN, result); 2314 2315 result = SDL_acos(-1.1); 2316 SDLTest_AssertCheck(ISNAN(result), 2317 "Acos(%f), expected %f, got %f", 2318 -1.1, NAN, result); 2319 2320 return TEST_COMPLETED; 2321} 2322 2323/** 2324 * Input: NAN. 2325 * Expected: NAN is returned. 2326 */ 2327static int SDLCALL 2328acos_nanCase(void *args) 2329{ 2330 const double result = SDL_acos(NAN); 2331 SDLTest_AssertCheck(ISNAN(result), 2332 "Acos(%f), expected %f, got %f", 2333 NAN, NAN, result); 2334 return TEST_COMPLETED; 2335} 2336 2337/** 2338 * Inputs: Values between -0.9 and 0.9 with steps of 0.1. 2339 * Expected: The correct result is returned (+/-EPSILON). 2340 */ 2341static int SDLCALL 2342acos_precisionTest(void *args) 2343{ 2344 const d_to_d precision_cases[] = { 2345 { 0.9, 0.4510268117 }, 2346 { 0.8, 0.6435011087 }, 2347 { 0.7, 0.7953988301 }, 2348 { 0.6, 0.9272952180 }, 2349 { 0.5, 1.0471975511 }, 2350 { 0.4, 1.1592794807 }, 2351 { 0.3, 1.2661036727 }, 2352 { 0.2, 1.3694384060 }, 2353 { 0.1, 1.4706289056 }, 2354 { 0.0, 1.5707963267 }, 2355 { -0.0, 1.5707963267 }, 2356 { -0.1, 1.6709637479 }, 2357 { -0.2, 1.7721542475 }, 2358 { -0.3, 1.8754889808 }, 2359 { -0.4, 1.9823131728 }, 2360 { -0.5, 2.0943951023 }, 2361 { -0.6, 2.2142974355 }, 2362 { -0.7, 2.3461938234 }, 2363 { -0.8, 2.4980915447 }, 2364 { -0.9, 2.6905658417 }, 2365 }; 2366 return helper_dtod_inexact("Acos", SDL_acos, precision_cases, SDL_arraysize(precision_cases)); 2367} 2368 2369/* SDL_asin tests functions */ 2370 2371/** 2372 * Inputs: +/-1.0. 2373 * Expected: +/-Pi/2 is returned. 2374 */ 2375static int SDLCALL 2376asin_limitCases(void *args) 2377{ 2378 double result; 2379 2380 result = SDL_asin(1.0); 2381 SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 2.0 - result) <= EPSILON, 2382 "Asin(%f), expected %f, got %f", 2383 1.0, SDL_PI_D / 2.0, result); 2384 2385 result = SDL_asin(-1.0); 2386 SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 2.0 - result) <= EPSILON, 2387 "Asin(%f), expected %f, got %f", 2388 -1.0, -SDL_PI_D / 2.0, result); 2389 2390 return TEST_COMPLETED; 2391} 2392 2393/** 2394 * Inputs: Values outside the domain of [-1, 1]. 2395 * Expected: NAN is returned. 2396 */ 2397static int SDLCALL 2398asin_outOfDomainCases(void *args) 2399{ 2400 double result; 2401 2402 result = SDL_asin(1.1); 2403 SDLTest_AssertCheck(ISNAN(result), 2404 "Asin(%f), expected %f, got %f", 2405 1.1, NAN, result); 2406 2407 result = SDL_asin(-1.1); 2408 SDLTest_AssertCheck(ISNAN(result), 2409 "Asin(%f), expected %f, got %f", 2410 -1.1, NAN, result); 2411 2412 return TEST_COMPLETED; 2413} 2414 2415/** 2416 * Input: NAN. 2417 * Expected: NAN is returned. 2418 */ 2419static int SDLCALL 2420asin_nanCase(void *args) 2421{ 2422 const double result = SDL_asin(NAN); 2423 SDLTest_AssertCheck(ISNAN(result), 2424 "Asin(%f), expected %f, got %f", 2425 NAN, NAN, result); 2426 return TEST_COMPLETED; 2427} 2428 2429/** 2430 * Inputs: Values between -0.9 and 0.9 with steps of 0.1. 2431 * Expected: The correct result is returned (+/-EPSILON). 2432 */ 2433static int SDLCALL 2434asin_precisionTest(void *args) 2435{ 2436 const d_to_d precision_cases[] = { 2437 { 0.9, 1.1197695149986342 }, 2438 { 0.8, 0.9272952180016123 }, 2439 { 0.7, 0.775397496610753 }, 2440 { 0.6, 0.6435011087932844 }, 2441 { 0.5, 0.5235987755982989 }, 2442 { 0.4, 0.41151684606748806 }, 2443 { 0.3, 0.3046926540153976 }, 2444 { 0.2, 0.20135792079033074 }, 2445 { 0.1, 0.10016742116155977 }, 2446 { 0.0, 0.0 }, 2447 { -0.0, -0.0 }, 2448 { -0.1, -0.10016742116155977 }, 2449 { -0.2, -0.20135792079033074 }, 2450 { -0.3, -0.3046926540153976 }, 2451 { -0.4, -0.41151684606748806 }, 2452 { -0.5, -0.5235987755982989 }, 2453 { -0.6, -0.6435011087932844 }, 2454 { -0.7, -0.775397496610753 }, 2455 { -0.8, -0.9272952180016123 }, 2456 { -0.9, -1.1197695149986342 } 2457 }; 2458 return helper_dtod_inexact("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases)); 2459} 2460 2461/* SDL_atan tests functions */ 2462 2463/** 2464 * Inputs: +/-Infinity. 2465 * Expected: +/-Pi/2 is returned. 2466 */ 2467static int SDLCALL 2468atan_limitCases(void *args) 2469{ 2470 double result; 2471 2472 result = SDL_atan(INFINITY); 2473 SDLTest_AssertCheck((SDL_PI_D / 2.0) - EPSILON <= result && 2474 result <= (SDL_PI_D / 2.0) + EPSILON, 2475 "Atan(%f), expected %f, got %f", 2476 INFINITY, SDL_PI_D / 2.0, result); 2477 2478 result = SDL_atan(-INFINITY); 2479 SDLTest_AssertCheck((-SDL_PI_D / 2.0) - EPSILON <= result && 2480 result <= (-SDL_PI_D / 2.0) + EPSILON, 2481 "Atan(%f), expected %f, got %f", 2482 -INFINITY, -SDL_PI_D / 2.0, result); 2483 2484 return TEST_COMPLETED; 2485} 2486 2487/** 2488 * Inputs: +/-0.0. 2489 * Expected: Zero is returned as-is. 2490 */ 2491static int SDLCALL 2492atan_zeroCases(void *args) 2493{ 2494 double result; 2495 2496 result = SDL_atan(0.0); 2497 SDLTest_AssertCheck(0.0 == result, 2498 "Atan(%f), expected %f, got %f", 2499 0.0, 0.0, result); 2500 2501 result = SDL_atan(-0.0); 2502 SDLTest_AssertCheck(-0.0 == result, 2503 "Atan(%f), expected %f, got %f", 2504 -0.0, -0.0, result); 2505 2506 return TEST_COMPLETED; 2507} 2508 2509/** 2510 * Input: NAN. 2511 * Expected: NAN is returned. 2512 */ 2513static int SDLCALL 2514atan_nanCase(void *args) 2515{ 2516 const double result = SDL_atan(NAN); 2517 SDLTest_AssertCheck(ISNAN(result), 2518 "Atan(%f), expected %f, got %f", 2519 NAN, NAN, result); 2520 return TEST_COMPLETED; 2521} 2522 2523/** 2524 * Inputs: Values corresponding to angles between 9Pi/20 and -9Pi/20 with steps of Pi/20. 2525 * Expected: The correct result is returned (+/-EPSILON). 2526 */ 2527static int SDLCALL 2528atan_precisionTest(void *args) 2529{ 2530 const d_to_d precision_cases[] = { 2531 { 6.313751514675041, 1.413716694115407 }, 2532 { 3.0776835371752527, 1.2566370614359172 }, 2533 { 1.9626105055051504, 1.0995574287564276 }, 2534 { 1.3763819204711734, 0.9424777960769379 }, 2535 { 1.0, 0.7853981633974483 }, 2536 { 0.7265425280053609, 0.6283185307179586 }, 2537 { 0.5095254494944288, 0.47123889803846897 }, 2538 { 0.3249196962329063, 0.3141592653589793 }, 2539 { 0.15838444032453627, 0.15707963267948966 }, 2540 { -0.15838444032453627, -0.15707963267948966 }, 2541 { -0.3249196962329063, -0.3141592653589793 }, 2542 { -0.5095254494944288, -0.47123889803846897 }, 2543 { -0.7265425280053609, -0.6283185307179586 }, 2544 { -1.0, -0.7853981633974483 }, 2545 { -1.3763819204711734, -0.9424777960769379 }, 2546 { -1.9626105055051504, -1.0995574287564276 }, 2547 { -3.0776835371752527, -1.2566370614359172 }, 2548 { -6.313751514675041, -1.413716694115407 }, 2549 }; 2550 return helper_dtod_inexact("Atan", SDL_atan, precision_cases, SDL_arraysize(precision_cases)); 2551} 2552 2553/* SDL_atan2 tests functions */ 2554 2555/* Zero cases */ 2556 2557/** 2558 * Inputs: (+/-0.0, +/-0.0). 2559 * Expected: 2560 * - Zero if the second argument is positive zero. 2561 * - Pi if the second argument is negative zero. 2562 * - The sign is inherited from the first argument. 2563 */ 2564static int SDLCALL 2565atan2_bothZeroCases(void *args) 2566{ 2567 const dd_to_d cases[] = { 2568 { 0.0, 0.0, 0.0 }, 2569 { -0.0, 0.0, -0.0 }, 2570 { 0.0, -0.0, SDL_PI_D }, 2571 { -0.0, -0.0, -SDL_PI_D }, 2572 }; 2573 return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases)); 2574} 2575 2576/** 2577 * Inputs: (+/-0.0, +/-1.0). 2578 * Expected: 2579 * - Zero if the second argument is positive. 2580 * - Pi if the second argument is negative. 2581 * - The sign is inherited from the first argument. 2582 */ 2583static int SDLCALL 2584atan2_yZeroCases(void *args) 2585{ 2586 const dd_to_d cases[] = { 2587 { 0.0, 1.0, 0.0 }, 2588 { 0.0, -1.0, SDL_PI_D }, 2589 { -0.0, 1.0, -0.0 }, 2590 { -0.0, -1.0, -SDL_PI_D } 2591 }; 2592 return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases)); 2593} 2594 2595/** 2596 * Inputs: (+/-1.0, +/-0.0). 2597 * Expected: Pi/2 with the sign of the first argument. 2598 */ 2599static int SDLCALL 2600atan2_xZeroCases(void *args) 2601{ 2602 const dd_to_d cases[] = { 2603 { 1.0, 0.0, SDL_PI_D / 2.0 }, 2604 { -1.0, 0.0, -SDL_PI_D / 2.0 }, 2605 { 1.0, -0.0, SDL_PI_D / 2.0 }, 2606 { -1.0, -0.0, -SDL_PI_D / 2.0 } 2607 }; 2608 return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases)); 2609} 2610 2611/* Infinity cases */ 2612 2613/** 2614 * Inputs: (+/-Infinity, +/-Infinity). 2615 * Expected: 2616 * - (+int, +inf) -> Pi/4, 2617 * - (+int, -inf) -> 3Pi/4, 2618 * - (-int, +inf) -> -Pi/4, 2619 * - (-int, -inf) -> Pi. 2620 */ 2621static int SDLCALL 2622atan2_bothInfCases(void *args) 2623{ 2624 double result; 2625 2626 result = SDL_atan2(INFINITY, INFINITY); 2627 SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 4.0 - result) <= EPSILON, 2628 "Atan2(%f,%f), expected %f, got %f", 2629 INFINITY, INFINITY, SDL_PI_D / 4.0, result); 2630 2631 result = SDL_atan2(INFINITY, -INFINITY); 2632 SDLTest_AssertCheck(SDL_fabs(3.0 * SDL_PI_D / 4.0 - result) <= EPSILON, 2633 "Atan2(%f,%f), expected %f, got %f", 2634 INFINITY, -INFINITY, 3.0 * SDL_PI_D / 4.0, result); 2635 2636 result = SDL_atan2(-INFINITY, INFINITY); 2637 SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 4.0 - result) <= EPSILON, 2638 "Atan2(%f,%f), expected %f, got %f", 2639 -INFINITY, INFINITY, -SDL_PI_D / 4.0, result); 2640 2641 result = SDL_atan2(-INFINITY, -INFINITY); 2642 SDLTest_AssertCheck(SDL_fabs(-3.0 * SDL_PI_D / 4.0 - result) <= EPSILON, 2643 "Atan2(%f,%f), expected %f, got %f", 2644 -INFINITY, -INFINITY, -3.0 * SDL_PI_D / 4.0, result); 2645 2646 return TEST_COMPLETED; 2647} 2648 2649/** 2650 * Inputs: (+/-Infinity, +/-1.0). 2651 * Expected: Pi/2 with the sign of the first argument. 2652 */ 2653static int SDLCALL 2654atan2_yInfCases(void *args) 2655{ 2656 double result; 2657 2658 result = SDL_atan2(INFINITY, 1.0); 2659 SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 2.0 - result) <= EPSILON, 2660 "Atan2(%f,%f), expected %f, got %f", 2661 INFINITY, 1.0, SDL_PI_D / 2.0, result); 2662 2663 result = SDL_atan2(INFINITY, -1.0); 2664 SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 2.0 - result) <= EPSILON, 2665 "Atan2(%f,%f), expected %f, got %f", 2666 INFINITY, -1.0, SDL_PI_D / 2.0, result); 2667 2668 result = SDL_atan2(-INFINITY, 1.0); 2669 SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 2.0 - result) <= EPSILON, 2670 "Atan2(%f,%f), expected %f, got %f", 2671 -INFINITY, 1.0, -SDL_PI_D / 2.0, result); 2672 2673 result = SDL_atan2(-INFINITY, -1.0); 2674 SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 2.0 - result) <= EPSILON, 2675 "Atan2(%f,%f), expected %f, got %f", 2676 -INFINITY, -1.0, -SDL_PI_D / 2.0, result); 2677 2678 return TEST_COMPLETED; 2679} 2680 2681/** 2682 * Inputs: (+/-1.0, +/-Infinity). 2683 * Expected: 2684 * - (+/-1.0, +inf) -> +/-0.0 2685 * - (+/-1.0, -inf) -> +/-Pi. 2686 */ 2687static int SDLCALL 2688atan2_xInfCases(void *args) 2689{ 2690 double result; 2691 2692 result = SDL_atan2(1.0, INFINITY); 2693 SDLTest_AssertCheck(0.0 == result, 2694 "Atan2(%f,%f), expected %f, got %f", 2695 1.0, INFINITY, 0.0, result); 2696 2697 result = SDL_atan2(-1.0, INFINITY); 2698 SDLTest_AssertCheck(-0.0 == result, 2699 "Atan2(%f,%f), expected %f, got %f", 2700 -1.0, INFINITY, -0.0, result); 2701 2702 result = SDL_atan2(1.0, -INFINITY); 2703 SDLTest_AssertCheck(SDL_fabs(SDL_PI_D - result) <= EPSILON, 2704 "Atan2(%f,%f), expected %f, got %f", 2705 1.0, -INFINITY, SDL_PI_D, result); 2706 2707 result = SDL_atan2(-1.0, -INFINITY); 2708 SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D - result) <= EPSILON, 2709 "Atan2(%f,%f), expected %f, got %f", 2710 -1.0, -INFINITY, -SDL_PI_D, result); 2711 2712 return TEST_COMPLETED; 2713} 2714 2715/* Miscelanious cases */ 2716 2717/** 2718 * Inputs: NAN as either or both of the arguments. 2719 * Expected: NAN is returned. 2720 */ 2721static int SDLCALL 2722atan2_nanCases(void *args) 2723{ 2724 double result; 2725 2726 result = SDL_atan2(NAN, NAN); 2727 SDLTest_AssertCheck(ISNAN(result), 2728 "Atan2(%f,%f), expected %f, got %f", 2729 NAN, NAN, NAN, result); 2730 2731 result = SDL_atan2(NAN, 1.0); 2732 SDLTest_AssertCheck(ISNAN(result), 2733 "Atan2(%f,%f), expected %f, got %f", 2734 NAN, 1.0, NAN, result); 2735 2736 result = SDL_atan2(1.0, NAN); 2737 SDLTest_AssertCheck(ISNAN(result), 2738 "Atan2(%f,%f), expected %f, got %f", 2739 1.0, NAN, NAN, result); 2740 2741 return TEST_COMPLETED; 2742} 2743 2744/** 2745 * Inputs: (y, x) with x and y positive. 2746 * Expected: Angle in the top right quadrant. 2747 */ 2748static int SDLCALL 2749atan2_topRightQuadrantTest(void *args) 2750{ 2751 const dd_to_d top_right_cases[] = { 2752 { 1.0, 1.0, SDL_PI_D / 4.0 }, 2753 { SQRT3, 3.0, SDL_PI_D / 6.0 }, 2754 { SQRT3, 1.0, SDL_PI_D / 3.0 } 2755 }; 2756 return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_right_cases, SDL_arraysize(top_right_cases)); 2757} 2758 2759/** 2760 * Inputs: (y, x) with x negative and y positive. 2761 * Expected: Angle in the top left quadrant. 2762 */ 2763static int SDLCALL 2764atan2_topLeftQuadrantTest(void *args) 2765{ 2766 const dd_to_d top_left_cases[] = { 2767 { 1.0, -1.0, 3.0 * SDL_PI_D / 4.0 }, 2768 { SQRT3, -3.0, 5.0 * SDL_PI_D / 6.0 }, 2769 { SQRT3, -1.0, 2.0 * SDL_PI_D / 3.0 } 2770 }; 2771 return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_left_cases, SDL_arraysize(top_left_cases)); 2772} 2773 2774/** 2775 * Inputs: (y, x) with x positive and y negative. 2776 * Expected: Angle in the bottom right quadrant. 2777 */ 2778static int SDLCALL 2779atan2_bottomRightQuadrantTest(void *args) 2780{ 2781 const dd_to_d bottom_right_cases[] = { 2782 { -1.0, 1.0, -SDL_PI_D / 4 }, 2783 { -SQRT3, 3.0, -SDL_PI_D / 6.0 }, 2784 { -SQRT3, 1.0, -SDL_PI_D / 3.0 } 2785 }; 2786 return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_right_cases, SDL_arraysize(bottom_right_cases)); 2787} 2788 2789/** 2790 * Inputs: (y, x) with x and y negative. 2791 * Expected: Angle in the bottom left quadrant. 2792 */ 2793static int SDLCALL 2794atan2_bottomLeftQuadrantTest(void *args) 2795{ 2796 const dd_to_d bottom_left_cases[] = { 2797 { -1.0, -1.0, -3.0 * SDL_PI_D / 4.0 }, 2798 { -SQRT3, -3.0, -5.0 * SDL_PI_D / 6.0 }, 2799 { -SQRT3, -1.0, -4.0 * SDL_PI_D / 6.0 } 2800 }; 2801 return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_left_cases, SDL_arraysize(bottom_left_cases)); 2802} 2803 2804/* ================= Test References ================== */ 2805 2806/* SDL_floor test cases */ 2807 2808static const SDLTest_TestCaseReference floorTestInf = { 2809 floor_infCases, "floor_infCases", 2810 "Checks positive and negative infinity", TEST_ENABLED 2811}; 2812static const SDLTest_TestCaseReference floorTestZero = { 2813 floor_zeroCases, "floor_zeroCases", 2814 "Checks positive and negative zero", TEST_ENABLED 2815}; 2816static const SDLTest_TestCaseReference floorTestNan = { 2817 floor_nanCase, "floor_nanCase", 2818 "Checks NAN", TEST_ENABLED 2819}; 2820static const SDLTest_TestCaseReference floorTestRound = { 2821 floor_roundNumbersCases, "floor_roundNumberCases", 2822 "Checks a set of integral values", TEST_ENABLED 2823}; 2824static const SDLTest_TestCaseReference floorTestFraction = { 2825 floor_fractionCases, "floor_fractionCases", 2826 "Checks a set of fractions", TEST_ENABLED 2827}; 2828static const SDLTest_TestCaseReference floorTestRange = { 2829 floor_rangeTest, "floor_rangeTest", 2830 "Checks a range of positive integer", TEST_ENABLED 2831}; 2832 2833/* SDL_ceil test cases */ 2834 2835static const SDLTest_TestCaseReference ceilTestInf = { 2836 ceil_infCases, "ceil_infCases", 2837 "Checks positive and negative infinity", TEST_ENABLED 2838}; 2839static const SDLTest_TestCaseReference ceilTestZero = { 2840 ceil_zeroCases, "ceil_zeroCases", 2841 "Checks positive and negative zero", TEST_ENABLED 2842}; 2843static const SDLTest_TestCaseReference ceilTestNan = { 2844 ceil_nanCase, "ceil_nanCase", 2845 "Checks NAN", TEST_ENABLED 2846}; 2847static const SDLTest_TestCaseReference ceilTestRound = { 2848 ceil_roundNumbersCases, "ceil_roundNumberCases", 2849 "Checks a set of integral values", TEST_ENABLED 2850}; 2851static const SDLTest_TestCaseReference ceilTestFraction = { 2852 ceil_fractionCases, "ceil_fractionCases", 2853 "Checks a set of fractions", TEST_ENABLED 2854}; 2855static const SDLTest_TestCaseReference ceilTestRange = { 2856 ceil_rangeTest, "ceil_rangeTest", 2857 "Checks a range of positive integer", TEST_ENABLED 2858}; 2859 2860/* SDL_trunc test cases */ 2861 2862static const SDLTest_TestCaseReference truncTestInf = { 2863 trunc_infCases, "trunc_infCases", 2864 "Checks positive and negative infinity", TEST_ENABLED 2865}; 2866static const SDLTest_TestCaseReference truncTestZero = { 2867 trunc_zeroCases, "trunc_zeroCases", 2868 "Checks positive and negative zero", TEST_ENABLED 2869}; 2870static const SDLTest_TestCaseReference truncTestNan = { 2871 trunc_nanCase, "trunc_nanCase", 2872 "Checks NAN", TEST_ENABLED 2873}; 2874static const SDLTest_TestCaseReference truncTestRound = { 2875 trunc_roundNumbersCases, "trunc_roundNumberCases", 2876 "Checks a set of integral values", TEST_ENABLED 2877}; 2878static const SDLTest_TestCaseReference truncTestFraction = { 2879 trunc_fractionCases, "trunc_fractionCases", 2880 "Checks a set of fractions", TEST_ENABLED 2881}; 2882static const SDLTest_TestCaseReference truncTestRange = { 2883 trunc_rangeTest, "trunc_rangeTest", 2884 "Checks a range of positive integer", TEST_ENABLED 2885}; 2886 2887/* SDL_round test cases */ 2888 2889static const SDLTest_TestCaseReference roundTestInf = { 2890 round_infCases, "round_infCases", 2891 "Checks positive and negative infinity", TEST_ENABLED 2892}; 2893static const SDLTest_TestCaseReference roundTestZero = { 2894 round_zeroCases, "round_zeroCases", 2895 "Checks positive and negative zero", TEST_ENABLED 2896}; 2897static const SDLTest_TestCaseReference roundTestNan = { 2898 round_nanCase, "round_nanCase", 2899 "Checks NAN", TEST_ENABLED 2900}; 2901static const SDLTest_TestCaseReference roundTestRound = { 2902 round_roundNumbersCases, "round_roundNumberCases", 2903 "Checks a set of integral values", TEST_ENABLED 2904}; 2905static const SDLTest_TestCaseReference roundTestFraction = { 2906 round_fractionCases, "round_fractionCases", 2907 "Checks a set of fractions", TEST_ENABLED 2908}; 2909static const SDLTest_TestCaseReference roundTestRange = { 2910 round_rangeTest, "round_rangeTest", 2911 "Checks a range of positive integer", TEST_ENABLED 2912}; 2913 2914/* SDL_fabs test cases */ 2915 2916static const SDLTest_TestCaseReference fabsTestInf = { 2917 fabs_infCases, "fabs_infCases", 2918 "Checks positive and negative infinity", TEST_ENABLED 2919}; 2920static const SDLTest_TestCaseReference fabsTestZero = { 2921 fabs_zeroCases, "fabs_zeroCases", 2922 "Checks positive and negative zero", TEST_ENABLED 2923}; 2924static const SDLTest_TestCaseReference fabsTestNan = { 2925 fabs_nanCase, "fabs_nanCase", 2926 "Checks NAN", TEST_ENABLED 2927}; 2928static const SDLTest_TestCaseReference fabsTestRange = { 2929 fabs_rangeTest, "fabs_rangeTest", 2930 "Checks a range of positive integer", TEST_ENABLED 2931}; 2932 2933/* SDL_copysign test cases */ 2934 2935static const SDLTest_TestCaseReference copysignTestInf = { 2936 copysign_infCases, "copysign_infCases", 2937 "Checks positive and negative infinity", TEST_ENABLED 2938}; 2939static const SDLTest_TestCaseReference copysignTestZero = { 2940 copysign_zeroCases, "copysign_zeroCases", 2941 "Checks positive and negative zero", TEST_ENABLED 2942}; 2943static const SDLTest_TestCaseReference copysignTestNan = { 2944 copysign_nanCases, "copysign_nanCases", 2945 "Checks NANs", TEST_ENABLED 2946}; 2947static const SDLTest_TestCaseReference copysignTestRange = { 2948 copysign_rangeTest, "copysign_rangeTest", 2949 "Checks a range of positive integer", TEST_ENABLED 2950}; 2951 2952/* SDL_fmod test cases */ 2953 2954static const SDLTest_TestCaseReference fmodTestDivOfInf = { 2955 fmod_divOfInfCases, "fmod_divOfInfCases", 2956 "Checks division of positive and negative infinity", TEST_ENABLED 2957}; 2958static const SDLTest_TestCaseReference fmodTestDivByInf = { 2959 fmod_divByInfCases, "fmod_divByInfCases", 2960 "Checks division by positive and negative infinity", TEST_ENABLED 2961}; 2962static const SDLTest_TestCaseReference fmodTestDivOfZero = { 2963 fmod_divOfZeroCases, "fmod_divOfZeroCases", 2964 "Checks division of positive and negative zero", TEST_ENABLED 2965}; 2966static const SDLTest_TestCaseReference fmodTestDivByZero = { 2967 fmod_divByZeroCases, "fmod_divByZeroCases", 2968 "Checks division by positive and negative zero", TEST_ENABLED 2969}; 2970static const SDLTest_TestCaseReference fmodTestNan = { 2971 fmod_nanCases, "fmod_nanCases", 2972 "Checks NANs", TEST_ENABLED 2973}; 2974static const SDLTest_TestCaseReference fmodTestRegular = { 2975 fmod_regularCases, "fmod_regularCases", 2976 "Checks a set of regular values", TEST_ENABLED 2977}; 2978static const SDLTest_TestCaseReference fmodTestRange = { 2979 fmod_rangeTest, "fmod_rangeTest", 2980 "Checks a range of positive integer", TEST_ENABLED 2981}; 2982 2983/* SDL_exp test cases */ 2984 2985static const SDLTest_TestCaseReference expTestInf = { 2986 exp_infCases, "exp_infCases", 2987 "Checks positive and negative infinity", TEST_ENABLED 2988}; 2989static const SDLTest_TestCaseReference expTestZero = { 2990 exp_zeroCases, "exp_zeroCases", 2991 "Checks for positive and negative zero", TEST_ENABLED 2992}; 2993static const SDLTest_TestCaseReference expTestOverflow = { 2994 exp_overflowCase, "exp_overflowCase", 2995 "Checks for overflow", TEST_ENABLED 2996}; 2997static const SDLTest_TestCaseReference expTestBase = { 2998 exp_baseCase, "exp_baseCase", 2999 "Checks the base case", TEST_ENABLED 3000}; 3001static const SDLTest_TestCaseReference expTestRegular = { 3002 exp_regularCases, "exp_regularCases", 3003 "Checks a set of regular values", TEST_ENABLED 3004}; 3005 3006/* SDL_log test cases */ 3007 3008static const SDLTest_TestCaseReference logTestLimit = { 3009 log_limitCases, "log_limitCases", 3010 "Checks the domain limits", TEST_ENABLED 3011}; 3012static const SDLTest_TestCaseReference logTestNan = { 3013 log_nanCases, "log_nanCases", 3014 "Checks NAN and negative values", TEST_ENABLED 3015}; 3016static const SDLTest_TestCaseReference logTestBase = { 3017 log_baseCases, "log_baseCases", 3018 "Checks the base cases", TEST_ENABLED 3019}; 3020static const SDLTest_TestCaseReference logTestRegular = { 3021 log_regularCases, "log_regularCases", 3022 "Checks a set of regular values", TEST_ENABLED 3023}; 3024 3025/* SDL_log10 test cases */ 3026 3027static const SDLTest_TestCaseReference log10TestLimit = { 3028 log10_limitCases, "log10_limitCases", 3029 "Checks the domain limits", TEST_ENABLED 3030}; 3031static const SDLTest_TestCaseReference log10TestNan = { 3032 log10_nanCases, "log10_nanCases", 3033 "Checks NAN and negative values", TEST_ENABLED 3034}; 3035static const SDLTest_TestCaseReference log10TestBase = { 3036 log10_baseCases, "log10_baseCases", 3037 "Checks the base cases", TEST_ENABLED 3038}; 3039static const SDLTest_TestCaseReference log10TestRegular = { 3040 log10_regularCases, "log10_regularCases", 3041 "Checks a set of regular values", TEST_ENABLED 3042}; 3043 3044/* SDL_modf test cases */ 3045 3046static const SDLTest_TestCaseReference modfTestBase = { 3047 modf_baseCases, "modf_baseCases", 3048 "Checks the base cases", TEST_ENABLED 3049}; 3050 3051/* SDL_pow test cases */ 3052 3053static const SDLTest_TestCaseReference powTestExpInf1 = { 3054 pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases", 3055 "Checks for SDL_pow(-1, +/-inf)", TEST_ENABLED 3056}; 3057static const SDLTest_TestCaseReference powTestExpInf2 = { 3058 pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases", 3059 "Checks for SDL_pow(+/-0, -inf)", TEST_ENABLED 3060}; 3061static const SDLTest_TestCaseReference powTestExpInf3 = { 3062 pow_expInfCases, "pow_expInfCases", 3063 "Checks for SDL_pow(x, +/-inf)", TEST_ENABLED 3064}; 3065static const SDLTest_TestCaseReference powTestBaseInf1 = { 3066 pow_basePInfCases, "pow_basePInfCases", 3067 "Checks for SDL_pow(inf, x)", TEST_ENABLED 3068}; 3069static const SDLTest_TestCaseReference powTestBaseInf2 = { 3070 pow_baseNInfCases, "pow_baseNInfCases", 3071 "Checks for SDL_pow(-inf, x)", TEST_ENABLED 3072}; 3073static const SDLTest_TestCaseReference powTestNan1 = { 3074 pow_badOperationCase, "pow_badOperationCase", 3075 "Checks for negative finite base and non-integer finite exponent", TEST_ENABLED 3076}; 3077static const SDLTest_TestCaseReference powTestNan2 = { 3078 pow_base1ExpNanCase, "pow_base1ExpNanCase", 3079 "Checks for SDL_pow(1.0, NAN)", TEST_ENABLED 3080}; 3081static const SDLTest_TestCaseReference powTestNan3 = { 3082 pow_baseNanExp0Cases, "pow_baseNanExp0Cases", 3083 "Checks for SDL_pow(NAN, +/-0)", TEST_ENABLED 3084}; 3085static const SDLTest_TestCaseReference powTestNan4 = { 3086 pow_nanArgsCases, "pow_nanArgsCases", 3087 "Checks for SDL_pow(x, y) with either x or y being NAN", TEST_ENABLED 3088}; 3089static const SDLTest_TestCaseReference powTestZero1 = { 3090 pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases", 3091 "Checks for SDL_pow(-0.0, y), with y an odd integer.", TEST_ENABLED 3092}; 3093static const SDLTest_TestCaseReference powTestZero2 = { 3094 pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases", 3095 "Checks for SDL_pow(0.0, y), with y an odd integer.", TEST_ENABLED 3096}; 3097static const SDLTest_TestCaseReference powTestZero3 = { 3098 pow_baseNZeroCases, "pow_baseNZeroCases", 3099 "Checks for SDL_pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED 3100}; 3101static const SDLTest_TestCaseReference powTestZero4 = { 3102 pow_basePZeroCases, "pow_basePZeroCases", 3103 "Checks for SDL_pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED 3104}; 3105static const SDLTest_TestCaseReference powTestRegular = { 3106 pow_regularCases, "pow_regularCases", 3107 "Checks a set of regular values", TEST_ENABLED 3108}; 3109static const SDLTest_TestCaseReference powTestPowOf2 = { 3110 pow_powerOfTwo, "pow_powerOfTwo", 3111 "Checks the powers of two from 1 to 8", TEST_ENABLED 3112}; 3113static const SDLTest_TestCaseReference powTestRange = { 3114 pow_rangeTest, "pow_rangeTest", 3115 "Checks a range of positive integer to the power of 0", TEST_ENABLED 3116}; 3117 3118/* SDL_sqrt test cases */ 3119 3120static const SDLTest_TestCaseReference sqrtTestInf = { 3121 sqrt_infCase, "sqrt_infCase", 3122 "Checks positive infinity", TEST_ENABLED 3123}; 3124static const SDLTest_TestCaseReference sqrtTestNan = { 3125 sqrt_nanCase, "sqrt_nanCase", 3126 "Checks NAN", TEST_ENABLED 3127}; 3128static const SDLTest_TestCaseReference sqrtTestDomain = { 3129 sqrt_outOfDomainCases, "sqrt_outOfDomainCases", 3130 "Checks for values out of the domain", TEST_ENABLED 3131}; 3132static const SDLTest_TestCaseReference sqrtTestBase = { 3133 sqrt_baseCases, "sqrt_baseCases", 3134 "Checks the base cases", TEST_ENABLED 3135}; 3136static const SDLTest_TestCaseReference sqrtTestRegular = { 3137 sqrt_regularCases, "sqrt_regularCases", 3138 "Checks a set of regular values", TEST_ENABLED 3139}; 3140 3141/* SDL_scalbn test cases */ 3142 3143static const SDLTest_TestCaseReference scalbnTestInf = { 3144 scalbn_infCases, "scalbn_infCases", 3145 "Checks positive and negative infinity arg", TEST_ENABLED 3146}; 3147static const SDLTest_TestCaseReference scalbnTestBaseZero = { 3148 scalbn_baseZeroCases, "scalbn_baseZeroCases", 3149 "Checks for positive and negative zero arg", TEST_ENABLED 3150}; 3151static const SDLTest_TestCaseReference scalbnTestExpZero = { 3152 scalbn_expZeroCase, "scalbn_expZeroCase", 3153 "Checks for zero exp", TEST_ENABLED 3154}; 3155static const SDLTest_TestCaseReference scalbnTestNan = { 3156 scalbn_nanCase, "scalbn_nanCase", 3157 "Checks NAN", TEST_ENABLED 3158}; 3159static const SDLTest_TestCaseReference scalbnTestRegular = { 3160 scalbn_regularCases, "scalbn_regularCases", 3161 "Checks a set of regular cases", TEST_ENABLED 3162}; 3163 3164/* SDL_cos test cases */ 3165 3166static const SDLTest_TestCaseReference cosTestInf = { 3167 cos_infCases, "cos_infCases", 3168 "Checks for positive and negative infinity", TEST_ENABLED 3169}; 3170static const SDLTest_TestCaseReference cosTestNan = { 3171 cos_nanCase, "cos_nanCase", 3172 "Checks NAN", TEST_ENABLED 3173}; 3174static const SDLTest_TestCaseReference cosTestRegular = { 3175 cos_regularCases, "cos_regularCases", 3176 "Checks a set of regular cases", TEST_ENABLED 3177}; 3178static const SDLTest_TestCaseReference cosTestPrecision = { 3179 cos_precisionTest, "cos_precisionTest", 3180 "Checks cosine precision", TEST_ENABLED 3181}; 3182static const SDLTest_TestCaseReference cosTestRange = { 3183 cos_rangeTest, "cos_rangeTest", 3184 "Checks a range of positive integer", TEST_ENABLED 3185}; 3186 3187/* SDL_sin test cases */ 3188 3189static const SDLTest_TestCaseReference sinTestInf = { 3190 sin_infCases, "sin_infCases", 3191 "Checks for positive and negative infinity", TEST_ENABLED 3192}; 3193static const SDLTest_TestCaseReference sinTestNan = { 3194 sin_nanCase, "sin_nanCase", 3195 "Checks NAN", TEST_ENABLED 3196}; 3197static const SDLTest_TestCaseReference sinTestRegular = { 3198 sin_regularCases, "sin_regularCases", 3199 "Checks a set of regular cases", TEST_ENABLED 3200}; 3201static const SDLTest_TestCaseReference sinTestPrecision = { 3202 sin_precisionTest, "sin_precisionTest", 3203 "Checks sine precision", TEST_ENABLED 3204}; 3205static const SDLTest_TestCaseReference sinTestRange = { 3206 sin_rangeTest, "sin_rangeTest", 3207 "Checks a range of positive integer", TEST_ENABLED 3208}; 3209 3210/* SDL_tan test cases */ 3211 3212static const SDLTest_TestCaseReference tanTestInf = { 3213 tan_infCases, "tan_infCases", 3214 "Checks for positive and negative infinity", TEST_ENABLED 3215}; 3216static const SDLTest_TestCaseReference tanTestNan = { 3217 tan_nanCase, "tan_nanCase", 3218 "Checks NAN", TEST_ENABLED 3219}; 3220static const SDLTest_TestCaseReference tanTestZero = { 3221 tan_zeroCases, "tan_zeroCases", 3222 "Checks a set of regular cases", TEST_ENABLED 3223}; 3224static const SDLTest_TestCaseReference tanTestPrecision = { 3225 tan_precisionTest, "tan_precisionTest", 3226 "Checks tangent precision", TEST_ENABLED 3227}; 3228 3229/* SDL_acos test cases */ 3230 3231static const SDLTest_TestCaseReference acosTestLimit = { 3232 acos_limitCases, "acos_limitCases", 3233 "Checks the edge of the domain (+/-1)", TEST_ENABLED 3234}; 3235static const SDLTest_TestCaseReference acosTestOutOfDomain = { 3236 acos_outOfDomainCases, "acos_outOfDomainCases", 3237 "Checks values outside the domain", TEST_ENABLED 3238}; 3239static const SDLTest_TestCaseReference acosTestNan = { 3240 acos_nanCase, "acos_nanCase", 3241 "Checks NAN", TEST_ENABLED 3242}; 3243static const SDLTest_TestCaseReference acosTestPrecision = { 3244 acos_precisionTest, "acos_precisionTest", 3245 "Checks acos precision", TEST_ENABLED 3246}; 3247 3248/* SDL_asin test cases */ 3249 3250static const SDLTest_TestCaseReference asinTestLimit = { 3251 asin_limitCases, "asin_limitCases", 3252 "Checks the edge of the domain (+/-1)", TEST_ENABLED 3253}; 3254static const SDLTest_TestCaseReference asinTestOutOfDomain = { 3255 asin_outOfDomainCases, "asin_outOfDomainCases", 3256 "Checks values outside the domain", TEST_ENABLED 3257}; 3258static const SDLTest_TestCaseReference asinTestNan = { 3259 asin_nanCase, "asin_nanCase", 3260 "Checks NAN", TEST_ENABLED 3261}; 3262static const SDLTest_TestCaseReference asinTestPrecision = { 3263 asin_precisionTest, "asin_precisionTest", 3264 "Checks asin precision", TEST_ENABLED 3265}; 3266 3267/* SDL_atan test cases */ 3268 3269static const SDLTest_TestCaseReference atanTestLimit = { 3270 atan_limitCases, "atan_limitCases", 3271 "Checks the edge of the domain (+/-Infinity)", TEST_ENABLED 3272}; 3273static const SDLTest_TestCaseReference atanTestZero = { 3274 atan_zeroCases, "atan_zeroCases", 3275 "Checks for positive and negative zero", TEST_ENABLED 3276}; 3277static const SDLTest_TestCaseReference atanTestNan = { 3278 atan_nanCase, "atan_nanCase", 3279 "Checks NAN", TEST_ENABLED 3280}; 3281static const SDLTest_TestCaseReference atanTestPrecision = { 3282 atan_precisionTest, "atan_precisionTest", 3283 "Checks atan precision", TEST_ENABLED 3284}; 3285 3286/* SDL_atan2 test cases */ 3287 3288static const SDLTest_TestCaseReference atan2TestZero1 = { 3289 atan2_bothZeroCases, "atan2_bothZeroCases", 3290 "Checks for both arguments being zero", TEST_ENABLED 3291}; 3292static const SDLTest_TestCaseReference atan2TestZero2 = { 3293 atan2_yZeroCases, "atan2_yZeroCases", 3294 "Checks for y=0", TEST_ENABLED 3295}; 3296static const SDLTest_TestCaseReference atan2TestZero3 = { 3297 atan2_xZeroCases, "atan2_xZeroCases", 3298 "Checks for x=0", TEST_ENABLED 3299}; 3300static const SDLTest_TestCaseReference atan2TestInf1 = { 3301 atan2_bothInfCases, "atan2_bothInfCases", 3302 "Checks for both arguments being infinity", TEST_ENABLED 3303}; 3304static const SDLTest_TestCaseReference atan2TestInf2 = { 3305 atan2_yInfCases, "atan2_yInfCases", 3306 "Checks for y=0", TEST_ENABLED 3307}; 3308static const SDLTest_TestCaseReference atan2TestInf3 = { 3309 atan2_xInfCases, "atan2_xInfCases", 3310 "Checks for x=0", TEST_ENABLED 3311}; 3312static const SDLTest_TestCaseReference atan2TestNan = { 3313 atan2_nanCases, "atan2_nanCases", 3314 "Checks NANs", TEST_ENABLED 3315}; 3316static const SDLTest_TestCaseReference atan2TestQuadrantTopRight = { 3317 atan2_topRightQuadrantTest, "atan2_topRightQuadrantTest", 3318 "Checks values in the top right quadrant", TEST_ENABLED 3319}; 3320static const SDLTest_TestCaseReference atan2TestQuadrantTopLeft = { 3321 atan2_topLeftQuadrantTest, "atan2_topLeftQuadrantTest", 3322 "Checks values in the top left quadrant", TEST_ENABLED 3323}; 3324static const SDLTest_TestCaseReference atan2TestQuadrantBottomRight = { 3325 atan2_bottomRightQuadrantTest, "atan2_bottomRightQuadrantTest", 3326 "Checks values in the bottom right quadrant", TEST_ENABLED 3327}; 3328static const SDLTest_TestCaseReference atan2TestQuadrantBottomLeft = { 3329 atan2_bottomLeftQuadrantTest, "atan2_bottomLeftQuadrantTest", 3330 "Checks values in the bottom left quadrant", TEST_ENABLED 3331}; 3332 3333static const SDLTest_TestCaseReference *mathTests[] = { 3334 &floorTestInf, &floorTestZero, &floorTestNan, 3335 &floorTestRound, &floorTestFraction, &floorTestRange, 3336 3337 &ceilTestInf, &ceilTestZero, &ceilTestNan, 3338 &ceilTestRound, &ceilTestFraction, &ceilTestRange, 3339 3340 &truncTestInf, &truncTestZero, &truncTestNan, 3341 &truncTestRound, &truncTestFraction, &truncTestRange, 3342 3343 &roundTestInf, &roundTestZero, &roundTestNan, 3344 &roundTestRound, &roundTestFraction, &roundTestRange, 3345 3346 &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange, 3347 3348 &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange, 3349 3350 &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero, 3351 &fmodTestNan, &fmodTestRegular, &fmodTestRange, 3352 3353 &expTestInf, &expTestZero, &expTestOverflow, 3354 &expTestBase, &expTestRegular, 3355 3356 &logTestLimit, &logTestNan, 3357 &logTestBase, &logTestRegular, 3358 3359 &log10TestLimit, &log10TestNan, 3360 &log10TestBase, &log10TestRegular, 3361 3362 &modfTestBase, 3363 3364 &powTestExpInf1, &powTestExpInf2, &powTestExpInf3, 3365 &powTestBaseInf1, &powTestBaseInf2, 3366 &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4, 3367 &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4, 3368 &powTestRegular, &powTestPowOf2, &powTestRange, 3369 3370 &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain, 3371 &sqrtTestBase, &sqrtTestRegular, 3372 3373 &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero, 3374 &scalbnTestNan, &scalbnTestRegular, 3375 3376 &cosTestInf, &cosTestNan, &cosTestRegular, 3377 &cosTestPrecision, &cosTestRange, 3378 3379 &sinTestInf, &sinTestNan, &sinTestRegular, 3380 &sinTestPrecision, &sinTestRange, 3381 3382 &tanTestInf, &tanTestNan, &tanTestZero, &tanTestPrecision, 3383 3384 &acosTestLimit, &acosTestOutOfDomain, &acosTestNan, &acosTestPrecision, 3385 3386 &asinTestLimit, &asinTestOutOfDomain, &asinTestNan, &asinTestPrecision, 3387 3388 &atanTestLimit, &atanTestZero, &atanTestNan, &atanTestPrecision, 3389 3390 &atan2TestZero1, &atan2TestZero2, &atan2TestZero3, 3391 &atan2TestInf1, &atan2TestInf2, &atan2TestInf3, 3392 &atan2TestNan, &atan2TestQuadrantTopRight, &atan2TestQuadrantTopLeft, 3393 &atan2TestQuadrantBottomRight, &atan2TestQuadrantBottomLeft, 3394 3395 NULL 3396}; 3397 3398SDLTest_TestSuiteReference mathTestSuite = { 3399 "Math", 3400 NULL, 3401 mathTests, 3402 NULL 3403}; 3404
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.