🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3354 lines
97 KiB

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