🛠️🐜 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.

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