testautomation_math.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  1. /**
  2. * Math test suite
  3. */
  4. #include <math.h>
  5. #include <float.h>
  6. #include "SDL.h"
  7. #include "SDL_test.h"
  8. /* Range tests parameters */
  9. #define RANGE_TEST_ITERATIONS 10000000
  10. #define RANGE_TEST_STEP SDL_MAX_UINT32 / RANGE_TEST_ITERATIONS
  11. /* Define the Euler constant */
  12. #ifndef M_E
  13. #define EULER 2.7182818284590450907955982984276488423347473144531250
  14. #else
  15. #define EULER M_E
  16. #endif
  17. /* ================= Test Structs ================== */
  18. /**
  19. * Stores a single input and the expected result
  20. */
  21. typedef struct
  22. {
  23. double input;
  24. double expected;
  25. } d_to_d;
  26. /**
  27. * Stores a pair of inputs and the expected result
  28. */
  29. typedef struct
  30. {
  31. double x_input, y_input;
  32. double expected;
  33. } dd_to_d;
  34. /*
  35. NB: You cannot create an array of these structures containing INFINITY or NAN.
  36. On platforms such as OS/2, they are defined as 'extern const double' making them
  37. not compile-time constant.
  38. */
  39. /* ================= Test Helpers ================== */
  40. typedef double(SDLCALL *d_to_d_func)(double);
  41. typedef double(SDLCALL *dd_to_d_func)(double, double);
  42. /**
  43. * \brief Runs all the cases on a given function with a signature double -> double
  44. *
  45. * \param func_name, the name of the tested function.
  46. * \param func, the function to call.
  47. * \param cases, an array of all the cases.
  48. * \param cases_size, the size of the cases array.
  49. */
  50. static int
  51. helper_dtod(const char *func_name, d_to_d_func func,
  52. const d_to_d *cases, const size_t cases_size)
  53. {
  54. Uint32 i;
  55. for (i = 0; i < cases_size; i++) {
  56. const double result = func(cases[i].input);
  57. SDLTest_AssertCheck(result == cases[i].expected,
  58. "%s(%f), expected %f, got %f",
  59. func_name,
  60. cases[i].input,
  61. cases[i].expected, result);
  62. }
  63. return TEST_COMPLETED;
  64. }
  65. /**
  66. * \brief Runs all the cases on a given function with a signature (double, double) -> double
  67. *
  68. * \param func_name, the name of the tested function.
  69. * \param func, the function to call.
  70. * \param cases, an array of all the cases.
  71. * \param cases_size, the size of the cases array.
  72. */
  73. static int
  74. helper_ddtod(const char *func_name, dd_to_d_func func,
  75. const dd_to_d *cases, const size_t cases_size)
  76. {
  77. Uint32 i;
  78. for (i = 0; i < cases_size; i++) {
  79. const double result = func(cases[i].x_input, cases[i].y_input);
  80. SDLTest_AssertCheck(result == cases[i].expected,
  81. "%s(%f,%f), expected %f, got %f",
  82. func_name,
  83. cases[i].x_input, cases[i].y_input,
  84. cases[i].expected, result);
  85. }
  86. return TEST_COMPLETED;
  87. }
  88. /**
  89. * \brief Runs a range of values on a given function with a signature double -> double
  90. *
  91. * This function is only meant to test functions that returns the input value if it is
  92. * integral: f(x) -> x for x in N.
  93. *
  94. * \param func_name, the name of the tested function.
  95. * \param func, the function to call.
  96. */
  97. static int
  98. helper_range(const char *func_name, d_to_d_func func)
  99. {
  100. Uint32 i;
  101. double test_value = 0.0;
  102. SDLTest_AssertPass("%s: Testing a range of %u values with steps of %u",
  103. func_name,
  104. RANGE_TEST_ITERATIONS,
  105. RANGE_TEST_STEP);
  106. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  107. double result;
  108. /* These are tested elsewhere */
  109. if (isnan(test_value) || isinf(test_value)) {
  110. continue;
  111. }
  112. result = func(test_value);
  113. if (result != test_value) { /* Only log failures to save performances */
  114. SDLTest_AssertCheck(SDL_FALSE,
  115. "%s(%.1f), expected %.1f, got %.1f",
  116. func_name, test_value,
  117. test_value, result);
  118. return TEST_ABORTED;
  119. }
  120. }
  121. return TEST_COMPLETED;
  122. }
  123. /* ================= Test Case Implementation ================== */
  124. /* SDL_floor tests functions */
  125. /**
  126. * \brief Checks positive and negative infinity.
  127. */
  128. static int
  129. floor_infCases(void *args)
  130. {
  131. double result;
  132. result = SDL_floor(INFINITY);
  133. SDLTest_AssertCheck(INFINITY == result,
  134. "Floor(%f), expected %f, got %f",
  135. INFINITY, INFINITY, result);
  136. result = SDL_floor(-INFINITY);
  137. SDLTest_AssertCheck(-INFINITY == result,
  138. "Floor(%f), expected %f, got %f",
  139. -INFINITY, -INFINITY, result);
  140. return TEST_COMPLETED;
  141. }
  142. /**
  143. * \brief Checks positive and negative zero.
  144. */
  145. static int
  146. floor_zeroCases(void *args)
  147. {
  148. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  149. return helper_dtod("Floor", SDL_floor, zero_cases, SDL_arraysize(zero_cases));
  150. }
  151. /**
  152. * \brief Checks the NaN case.
  153. */
  154. static int
  155. floor_nanCase(void *args)
  156. {
  157. const double result = SDL_floor(NAN);
  158. SDLTest_AssertCheck(isnan(result),
  159. "Floor(nan), expected nan, got %f",
  160. result);
  161. return TEST_COMPLETED;
  162. }
  163. /**
  164. * \brief Checks round values (x.0) for themselves
  165. */
  166. static int
  167. floor_roundNumbersCases(void *args)
  168. {
  169. const d_to_d round_cases[] = {
  170. { 1.0, 1.0 },
  171. { -1.0, -1.0 },
  172. { 15.0, 15.0 },
  173. { -15.0, -15.0 },
  174. { 125.0, 125.0 },
  175. { -125.0, -125.0 },
  176. { 1024.0, 1024.0 },
  177. { -1024.0, -1024.0 }
  178. };
  179. return helper_dtod("Floor", SDL_floor, round_cases, SDL_arraysize(round_cases));
  180. }
  181. /**
  182. * \brief Checks a set of fractions
  183. */
  184. static int
  185. floor_fractionCases(void *args)
  186. {
  187. const d_to_d frac_cases[] = {
  188. { 1.0 / 2.0, 0.0 },
  189. { -1.0 / 2.0, -1.0 },
  190. { 4.0 / 3.0, 1.0 },
  191. { -4.0 / 3.0, -2.0 },
  192. { 76.0 / 7.0, 10.0 },
  193. { -76.0 / 7.0, -11.0 },
  194. { 535.0 / 8.0, 66.0 },
  195. { -535.0 / 8.0, -67.0 },
  196. { 19357.0 / 53.0, 365.0 },
  197. { -19357.0 / 53.0, -366.0 }
  198. };
  199. return helper_dtod("Floor", SDL_floor, frac_cases, SDL_arraysize(frac_cases));
  200. }
  201. /**
  202. * \brief Checks a range of values between 0 and UINT32_MAX
  203. */
  204. static int
  205. floor_rangeTest(void *args)
  206. {
  207. return helper_range("Floor", SDL_floor);
  208. }
  209. /* SDL_ceil tests functions */
  210. /**
  211. * \brief Checks positive and negative infinity.
  212. */
  213. static int
  214. ceil_infCases(void *args)
  215. {
  216. double result;
  217. result = SDL_ceil(INFINITY);
  218. SDLTest_AssertCheck(INFINITY == result,
  219. "Ceil(%f), expected %f, got %f",
  220. INFINITY, INFINITY, result);
  221. result = SDL_ceil(-INFINITY);
  222. SDLTest_AssertCheck(-INFINITY == result,
  223. "Ceil(%f), expected %f, got %f",
  224. -INFINITY, -INFINITY, result);
  225. return TEST_COMPLETED;
  226. }
  227. /**
  228. * \brief Checks positive and negative zero.
  229. */
  230. static int
  231. ceil_zeroCases(void *args)
  232. {
  233. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  234. return helper_dtod("Ceil", SDL_ceil, zero_cases, SDL_arraysize(zero_cases));
  235. }
  236. /**
  237. * \brief Checks the NaN case.
  238. */
  239. static int
  240. ceil_nanCase(void *args)
  241. {
  242. const double result = SDL_ceil(NAN);
  243. SDLTest_AssertCheck(isnan(result),
  244. "Ceil(nan), expected nan, got %f",
  245. result);
  246. return TEST_COMPLETED;
  247. }
  248. /**
  249. * \brief Checks round values (x.0) for themselves
  250. */
  251. static int
  252. ceil_roundNumbersCases(void *args)
  253. {
  254. const d_to_d round_cases[] = {
  255. { 1.0, 1.0 },
  256. { -1.0, -1.0 },
  257. { 15.0, 15.0 },
  258. { -15.0, -15.0 },
  259. { 125.0, 125.0 },
  260. { -125.0, -125.0 },
  261. { 1024.0, 1024.0 },
  262. { -1024.0, -1024.0 }
  263. };
  264. return helper_dtod("Ceil", SDL_ceil, round_cases, SDL_arraysize(round_cases));
  265. }
  266. /**
  267. * \brief Checks a set of fractions
  268. */
  269. static int
  270. ceil_fractionCases(void *args)
  271. {
  272. const d_to_d frac_cases[] = {
  273. { 1.0 / 2.0, 1.0 },
  274. { -1.0 / 2.0, -0.0 },
  275. { 4.0 / 3.0, 2.0 },
  276. { -4.0 / 3.0, -1.0 },
  277. { 76.0 / 7.0, 11.0 },
  278. { -76.0 / 7.0, -10.0 },
  279. { 535.0 / 8.0, 67.0 },
  280. { -535.0 / 8.0, -66.0 },
  281. { 19357.0 / 53.0, 366.0 },
  282. { -19357.0 / 53.0, -365.0 }
  283. };
  284. return helper_dtod("Ceil", SDL_ceil, frac_cases, SDL_arraysize(frac_cases));
  285. }
  286. /**
  287. * \brief Checks a range of values between 0 and UINT32_MAX
  288. */
  289. static int
  290. ceil_rangeTest(void *args)
  291. {
  292. return helper_range("Ceil", SDL_ceil);
  293. }
  294. /* SDL_trunc tests functions */
  295. /**
  296. * \brief Checks positive and negative infinity.
  297. */
  298. static int
  299. trunc_infCases(void *args)
  300. {
  301. double result;
  302. result = SDL_trunc(INFINITY);
  303. SDLTest_AssertCheck(INFINITY == result,
  304. "Trunc(%f), expected %f, got %f",
  305. INFINITY, INFINITY, result);
  306. result = SDL_trunc(-INFINITY);
  307. SDLTest_AssertCheck(-INFINITY == result,
  308. "Trunc(%f), expected %f, got %f",
  309. -INFINITY, -INFINITY, result);
  310. return TEST_COMPLETED;
  311. }
  312. /**
  313. * \brief Checks positive and negative zero.
  314. */
  315. static int
  316. trunc_zeroCases(void *args)
  317. {
  318. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  319. return helper_dtod("Trunc", SDL_trunc, zero_cases, SDL_arraysize(zero_cases));
  320. }
  321. /**
  322. * \brief Checks the NaN case.
  323. */
  324. static int
  325. trunc_nanCase(void *args)
  326. {
  327. const double result = SDL_trunc(NAN);
  328. SDLTest_AssertCheck(isnan(result),
  329. "Trunc(nan), expected nan, got %f",
  330. result);
  331. return TEST_COMPLETED;
  332. }
  333. /**
  334. * \brief Checks round values (x.0) for themselves
  335. */
  336. static int
  337. trunc_roundNumbersCases(void *args)
  338. {
  339. const d_to_d round_cases[] = {
  340. { 1.0, 1.0 },
  341. { -1.0, -1.0 },
  342. { 15.0, 15.0 },
  343. { -15.0, -15.0 },
  344. { 125.0, 125.0 },
  345. { -125.0, -125.0 },
  346. { 1024.0, 1024.0 },
  347. { -1024.0, -1024.0 }
  348. };
  349. return helper_dtod("Trunc", SDL_trunc, round_cases, SDL_arraysize(round_cases));
  350. }
  351. /**
  352. * \brief Checks a set of fractions
  353. */
  354. static int
  355. trunc_fractionCases(void *args)
  356. {
  357. const d_to_d frac_cases[] = {
  358. { 1.0 / 2.0, 0.0 },
  359. { -1.0 / 2.0, -0.0 },
  360. { 4.0 / 3.0, 1.0 },
  361. { -4.0 / 3.0, -1.0 },
  362. { 76.0 / 7.0, 10.0 },
  363. { -76.0 / 7.0, -10.0 },
  364. { 535.0 / 8.0, 66.0 },
  365. { -535.0 / 8.0, -66.0 },
  366. { 19357.0 / 53.0, 365.0 },
  367. { -19357.0 / 53.0, -365.0 }
  368. };
  369. return helper_dtod("Trunc", SDL_trunc, frac_cases, SDL_arraysize(frac_cases));
  370. }
  371. /**
  372. * \brief Checks a range of values between 0 and UINT32_MAX
  373. */
  374. static int
  375. trunc_rangeTest(void *args)
  376. {
  377. return helper_range("Trunc", SDL_trunc);
  378. }
  379. /* SDL_round tests functions */
  380. /**
  381. * \brief Checks positive and negative infinity.
  382. */
  383. static int
  384. round_infCases(void *args)
  385. {
  386. double result;
  387. result = SDL_round(INFINITY);
  388. SDLTest_AssertCheck(INFINITY == result,
  389. "Round(%f), expected %f, got %f",
  390. INFINITY, INFINITY, result);
  391. result = SDL_round(-INFINITY);
  392. SDLTest_AssertCheck(-INFINITY == result,
  393. "Round(%f), expected %f, got %f",
  394. -INFINITY, -INFINITY, result);
  395. return TEST_COMPLETED;
  396. }
  397. /**
  398. * \brief Checks positive and negative zero.
  399. */
  400. static int
  401. round_zeroCases(void *args)
  402. {
  403. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  404. return helper_dtod("Round", SDL_round, zero_cases, SDL_arraysize(zero_cases));
  405. }
  406. /**
  407. * \brief Checks the NaN case.
  408. */
  409. static int
  410. round_nanCase(void *args)
  411. {
  412. const double result = SDL_round(NAN);
  413. SDLTest_AssertCheck(isnan(result),
  414. "Round(nan), expected nan, got %f",
  415. result);
  416. return TEST_COMPLETED;
  417. }
  418. /**
  419. * \brief Checks round values (x.0) for themselves
  420. */
  421. static int
  422. round_roundNumbersCases(void *args)
  423. {
  424. const d_to_d round_cases[] = {
  425. { 1.0, 1.0 },
  426. { -1.0, -1.0 },
  427. { 15.0, 15.0 },
  428. { -15.0, -15.0 },
  429. { 125.0, 125.0 },
  430. { -125.0, -125.0 },
  431. { 1024.0, 1024.0 },
  432. { -1024.0, -1024.0 }
  433. };
  434. return helper_dtod("Round", SDL_round, round_cases, SDL_arraysize(round_cases));
  435. }
  436. /**
  437. * \brief Checks a set of fractions
  438. */
  439. static int
  440. round_fractionCases(void *args)
  441. {
  442. const d_to_d frac_cases[] = {
  443. { 1.0 / 2.0, 1.0 },
  444. { -1.0 / 2.0, -1.0 },
  445. { 4.0 / 3.0, 1.0 },
  446. { -4.0 / 3.0, -1.0 },
  447. { 76.0 / 7.0, 11.0 },
  448. { -76.0 / 7.0, -11.0 },
  449. { 535.0 / 8.0, 67.0 },
  450. { -535.0 / 8.0, -67.0 },
  451. { 19357.0 / 53.0, 365.0 },
  452. { -19357.0 / 53.0, -365.0 }
  453. };
  454. return helper_dtod("Round", SDL_round, frac_cases, SDL_arraysize(frac_cases));
  455. }
  456. /**
  457. * \brief Checks a range of values between 0 and UINT32_MAX
  458. */
  459. static int
  460. round_rangeTest(void *args)
  461. {
  462. return helper_range("Round", SDL_round);
  463. }
  464. /* SDL_fabs tests functions */
  465. /**
  466. * \brief Checks positive and negative infinity.
  467. */
  468. static int
  469. fabs_infCases(void *args)
  470. {
  471. double result;
  472. result = SDL_fabs(INFINITY);
  473. SDLTest_AssertCheck(INFINITY == result,
  474. "Fabs(%f), expected %f, got %f",
  475. INFINITY, INFINITY, result);
  476. result = SDL_fabs(-INFINITY);
  477. SDLTest_AssertCheck(INFINITY == result,
  478. "Fabs(%f), expected %f, got %f",
  479. -INFINITY, INFINITY, result);
  480. return TEST_COMPLETED;
  481. }
  482. /**
  483. * \brief Checks positive and negative zero
  484. */
  485. static int
  486. fabs_zeroCases(void *args)
  487. {
  488. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, 0.0 } };
  489. return helper_dtod("Fabs", SDL_fabs, zero_cases, SDL_arraysize(zero_cases));
  490. }
  491. /**
  492. * \brief Checks the NaN case.
  493. */
  494. static int
  495. fabs_nanCase(void *args)
  496. {
  497. const double result = SDL_fabs(NAN);
  498. SDLTest_AssertCheck(isnan(result),
  499. "Fabs(nan), expected nan, got %f",
  500. result);
  501. return TEST_COMPLETED;
  502. }
  503. /**
  504. * \brief Checks a range of values between 0 and UINT32_MAX
  505. */
  506. static int
  507. fabs_rangeTest(void *args)
  508. {
  509. return helper_range("Fabs", SDL_fabs);
  510. }
  511. /* SDL_copysign tests functions */
  512. /**
  513. * \brief Checks positive and negative inifnity.
  514. */
  515. static int
  516. copysign_infCases(void *args)
  517. {
  518. double result;
  519. result = SDL_copysign(INFINITY, -1.0);
  520. SDLTest_AssertCheck(-INFINITY == result,
  521. "Copysign(%f,%.1f), expected %f, got %f",
  522. INFINITY, -1.0, -INFINITY, result);
  523. result = SDL_copysign(INFINITY, 1.0);
  524. SDLTest_AssertCheck(INFINITY == result,
  525. "Copysign(%f,%.1f), expected %f, got %f",
  526. INFINITY, 1.0, INFINITY, result);
  527. result = SDL_copysign(-INFINITY, -1.0);
  528. SDLTest_AssertCheck(-INFINITY == result,
  529. "Copysign(%f,%.1f), expected %f, got %f",
  530. -INFINITY, -1.0, -INFINITY, result);
  531. result = SDL_copysign(-INFINITY, 1.0);
  532. SDLTest_AssertCheck(INFINITY == result,
  533. "Copysign(%f,%.1f), expected %f, got %f",
  534. -INFINITY, 1.0, INFINITY, result);
  535. return TEST_COMPLETED;
  536. }
  537. /**
  538. * \brief Checks positive and negative zero.
  539. */
  540. static int
  541. copysign_zeroCases(void *args)
  542. {
  543. const dd_to_d zero_cases[] = {
  544. { 0.0, 1.0, 0.0 },
  545. { 0.0, -1.0, -0.0 },
  546. { -0.0, 1.0, 0.0 },
  547. { -0.0, -1.0, -0.0 }
  548. };
  549. return helper_ddtod("Copysign", SDL_copysign, zero_cases, SDL_arraysize(zero_cases));
  550. }
  551. /**
  552. * \brief Checks the NaN cases.
  553. */
  554. static int
  555. copysign_nanCases(void *args)
  556. {
  557. double result;
  558. result = SDL_copysign(NAN, 1.0);
  559. SDLTest_AssertCheck(isnan(result),
  560. "Copysign(nan,1.0), expected nan, got %f",
  561. result);
  562. result = SDL_copysign(NAN, -1.0);
  563. SDLTest_AssertCheck(isnan(result),
  564. "Copysign(nan,-1.0), expected nan, got %f",
  565. result);
  566. return TEST_COMPLETED;
  567. }
  568. /**
  569. * \brief Checks a range of values between 0 and UINT32_MAX
  570. */
  571. static int
  572. copysign_rangeTest(void *args)
  573. {
  574. Uint32 i;
  575. double test_value = 0.0;
  576. SDLTest_AssertPass("Copysign: Testing a range of %u values with steps of %u",
  577. RANGE_TEST_ITERATIONS,
  578. RANGE_TEST_STEP);
  579. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  580. double result;
  581. /* These are tested elsewhere */
  582. if (isnan(test_value) || isinf(test_value)) {
  583. continue;
  584. }
  585. /* Only log failures to save performances */
  586. result = SDL_copysign(test_value, 1.0);
  587. if (result != test_value) {
  588. SDLTest_AssertCheck(SDL_FALSE,
  589. "Copysign(%.1f,%.1f), expected %.1f, got %.1f",
  590. test_value, 1.0, test_value, result);
  591. return TEST_ABORTED;
  592. }
  593. result = SDL_copysign(test_value, -1.0);
  594. if (result != -test_value) {
  595. SDLTest_AssertCheck(SDL_FALSE,
  596. "Copysign(%.1f,%.1f), expected %.1f, got %.1f",
  597. test_value, -1.0, -test_value, result);
  598. return TEST_ABORTED;
  599. }
  600. }
  601. return TEST_COMPLETED;
  602. }
  603. /* SDL_fmod tests functions */
  604. /**
  605. * \brief Checks division of positive and negative inifnity.
  606. */
  607. static int
  608. fmod_divOfInfCases(void *args)
  609. {
  610. double result;
  611. result = SDL_fmod(INFINITY, -1.0);
  612. SDLTest_AssertCheck(isnan(result),
  613. "Fmod(%f,%.1f), expected %f, got %f",
  614. INFINITY, -1.0, NAN, result);
  615. result = SDL_fmod(INFINITY, 1.0);
  616. SDLTest_AssertCheck(isnan(result),
  617. "Fmod(%f,%.1f), expected %f, got %f",
  618. INFINITY, 1.0, NAN, result);
  619. result = SDL_fmod(-INFINITY, -1.0);
  620. SDLTest_AssertCheck(isnan(result),
  621. "Fmod(%f,%.1f), expected %f, got %f",
  622. -INFINITY, -1.0, NAN, result);
  623. result = SDL_fmod(-INFINITY, 1.0);
  624. SDLTest_AssertCheck(isnan(result),
  625. "Fmod(%f,%.1f), expected %f, got %f",
  626. -INFINITY, 1.0, NAN, result);
  627. return TEST_COMPLETED;
  628. }
  629. /**
  630. * \brief Checks division by positive and negative inifnity.
  631. */
  632. static int
  633. fmod_divByInfCases(void *args)
  634. {
  635. double result;
  636. result = SDL_fmod(1.0, INFINITY);
  637. SDLTest_AssertCheck(1.0 == result,
  638. "Fmod(%.1f,%f), expected %f, got %f",
  639. 1.0, INFINITY, 1.0, result);
  640. result = SDL_fmod(-1.0, INFINITY);
  641. SDLTest_AssertCheck(-1.0 == result,
  642. "Fmod(%.1f,%f), expected %f, got %f",
  643. -1.0, INFINITY, -1.0, result);
  644. result = SDL_fmod(1.0, -INFINITY);
  645. SDLTest_AssertCheck(1.0 == result,
  646. "Fmod(%.1f,%f), expected %f, got %f",
  647. 1.0, -INFINITY, 1.0, result);
  648. result = SDL_fmod(-1.0, -INFINITY);
  649. SDLTest_AssertCheck(-1.0 == result,
  650. "Fmod(%.1f,%f), expected %f, got %f",
  651. -1.0, -INFINITY, -1.0, result);
  652. return TEST_COMPLETED;
  653. }
  654. /**
  655. * \brief Checks division of positive and negative zero.
  656. */
  657. static int
  658. fmod_divOfZeroCases(void *args)
  659. {
  660. const dd_to_d zero_cases[] = {
  661. { 0.0, 1.0, 0.0 },
  662. { 0.0, -1.0, 0.0 },
  663. { -0.0, 1.0, -0.0 },
  664. { -0.0, -1.0, -0.0 }
  665. };
  666. return helper_ddtod("Fmod", SDL_fmod, zero_cases, SDL_arraysize(zero_cases));
  667. }
  668. /**
  669. * \brief Checks division by positive and negative zero.
  670. */
  671. static int
  672. fmod_divByZeroCases(void *args)
  673. {
  674. double result;
  675. result = SDL_fmod(1.0, 0.0);
  676. SDLTest_AssertCheck(isnan(result),
  677. "Fmod(1.0,0.0), expected nan, got %f",
  678. result);
  679. result = SDL_fmod(-1.0, 0.0);
  680. SDLTest_AssertCheck(isnan(result),
  681. "Fmod(-1.0,0.0), expected nan, got %f",
  682. result);
  683. result = SDL_fmod(1.0, -0.0);
  684. SDLTest_AssertCheck(isnan(result),
  685. "Fmod(1.0,-0.0), expected nan, got %f",
  686. result);
  687. result = SDL_fmod(-1.0, -0.0);
  688. SDLTest_AssertCheck(isnan(result),
  689. "Fmod(-1.0,-0.0), expected nan, got %f",
  690. result);
  691. return TEST_COMPLETED;
  692. }
  693. /**
  694. * \brief Checks the NaN cases.
  695. */
  696. static int
  697. fmod_nanCases(void *args)
  698. {
  699. double result;
  700. result = SDL_fmod(NAN, 1.0);
  701. SDLTest_AssertCheck(isnan(result),
  702. "Fmod(nan,1.0), expected nan, got %f",
  703. result);
  704. result = SDL_fmod(NAN, -1.0);
  705. SDLTest_AssertCheck(isnan(result),
  706. "Fmod(nan,-1.0), expected nan, got %f",
  707. result);
  708. result = SDL_fmod(1.0, NAN);
  709. SDLTest_AssertCheck(isnan(result),
  710. "Fmod(1.0,nan), expected nan, got %f",
  711. result);
  712. result = SDL_fmod(-1.0, NAN);
  713. SDLTest_AssertCheck(isnan(result),
  714. "Fmod(-1.0,nan), expected nan, got %f",
  715. result);
  716. return TEST_COMPLETED;
  717. }
  718. /**
  719. * \brief Checks a set of regular values.
  720. */
  721. static int
  722. fmod_regularCases(void *args)
  723. {
  724. const dd_to_d regular_cases[] = {
  725. { 3.5, 2.0, 1.5 },
  726. { -6.25, 3.0, -0.25 },
  727. { 7.5, 2.5, 0.0 },
  728. { 2.0 / 3.0, -1.0 / 3.0, 0.0 }
  729. };
  730. return helper_ddtod("Fmod", SDL_fmod, regular_cases, SDL_arraysize(regular_cases));
  731. }
  732. /**
  733. * \brief Checks a range of values between 0 and UINT32_MAX
  734. */
  735. static int
  736. fmod_rangeTest(void *args)
  737. {
  738. Uint32 i;
  739. double test_value = 0.0;
  740. SDLTest_AssertPass("Fmod: Testing a range of %u values with steps of %u",
  741. RANGE_TEST_ITERATIONS,
  742. RANGE_TEST_STEP);
  743. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  744. double result;
  745. /* These are tested elsewhere */
  746. if (isnan(test_value) || isinf(test_value)) {
  747. continue;
  748. }
  749. /* Only log failures to save performances */
  750. result = SDL_fmod(test_value, 1.0);
  751. if (0.0 != result) {
  752. SDLTest_AssertCheck(SDL_FALSE,
  753. "Fmod(%.1f,%.1f), expected %.1f, got %.1f",
  754. test_value, 1.0, 0.0, result);
  755. return TEST_ABORTED;
  756. }
  757. }
  758. return TEST_COMPLETED;
  759. }
  760. /* SDL_exp tests functions */
  761. /**
  762. * \brief Checks positive and negative infinity.
  763. */
  764. static int
  765. exp_infCases(void *args)
  766. {
  767. double result;
  768. result = SDL_exp(INFINITY);
  769. SDLTest_AssertCheck(INFINITY == result,
  770. "Exp(%f), expected %f, got %f",
  771. INFINITY, INFINITY, result);
  772. result = SDL_exp(-INFINITY);
  773. SDLTest_AssertCheck(0.0 == result,
  774. "Exp(%f), expected %f, got %f",
  775. -INFINITY, 0.0, result);
  776. return TEST_COMPLETED;
  777. }
  778. /**
  779. * \brief Checks positive and negative zero.
  780. */
  781. static int
  782. exp_zeroCases(void *args)
  783. {
  784. const d_to_d zero_cases[] = {
  785. { 0.0, 1.0 },
  786. { -0.0, 1.0 }
  787. };
  788. return helper_dtod("Exp", SDL_exp, zero_cases, SDL_arraysize(zero_cases));
  789. }
  790. /**
  791. * \brief Checks for overflow.
  792. *
  793. * This test is skipped for double types larger than 64 bits.
  794. */
  795. static int
  796. exp_overflowCase(void *args)
  797. {
  798. double result;
  799. if (sizeof(double) > 8) {
  800. return TEST_SKIPPED;
  801. }
  802. result = SDL_exp(710.0);
  803. SDLTest_AssertCheck(isinf(result),
  804. "Exp(%f), expected %f, got %f",
  805. 710.0, INFINITY, result);
  806. return TEST_COMPLETED;
  807. }
  808. /**
  809. * \brief Checks the base case of 1.0.
  810. */
  811. static int
  812. exp_baseCase(void *args)
  813. {
  814. const double result = SDL_exp(1.0);
  815. SDLTest_AssertCheck(EULER == result,
  816. "Exp(%f), expected %f, got %f",
  817. 1.0, EULER, result);
  818. return TEST_COMPLETED;
  819. }
  820. /**
  821. * \brief Checks a set of regular cases.
  822. */
  823. static int
  824. exp_regularCases(void *args)
  825. {
  826. /* Hexadecimal floating constants are not supported on C89 compilers */
  827. const d_to_d regular_cases[] = {
  828. { -101.0, 1.36853947117385291381565719268793547578002532127613087E-44 },
  829. { -15.73, 0.00000014741707833928422931856502906683425990763681 },
  830. { -1.0, 0.36787944117144233402427744294982403516769409179688 },
  831. { -0.5, 0.60653065971263342426311737654032185673713684082031 },
  832. { 0.5, 1.64872127070012819416433558217249810695648193359375 },
  833. { 2.25, 9.48773583635852624240669683786109089851379394531250 },
  834. { 34.125, 661148770968660.375 },
  835. { 112.89, 10653788283588960962604279261058893737879589093376.0 },
  836. { 539.483, 1970107755334319939701129934673541628417235942656909222826926175622435588279443011110464355295725187195188154768877850257012251677751742837992843520967922303961718983154427294786640886286983037548604937796221048661733679844353544028160.0 },
  837. };
  838. return helper_dtod("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases));
  839. }
  840. /* SDL_log tests functions */
  841. /**
  842. * \brief Checks limits (zeros and positive infinity).
  843. */
  844. static int
  845. log_limitCases(void *args)
  846. {
  847. double result;
  848. result = SDL_log(INFINITY);
  849. SDLTest_AssertCheck(INFINITY == result,
  850. "Log(%f), expected %f, got %f",
  851. INFINITY, INFINITY, result);
  852. result = SDL_log(0.0);
  853. SDLTest_AssertCheck(-INFINITY == result,
  854. "Log(%f), expected %f, got %f",
  855. 0.0, -INFINITY, result);
  856. result = SDL_log(-0.0);
  857. SDLTest_AssertCheck(-INFINITY == result,
  858. "Log(%f), expected %f, got %f",
  859. -0.0, -INFINITY, result);
  860. return TEST_COMPLETED;
  861. }
  862. /**
  863. * \brief Checks some base cases.
  864. */
  865. static int
  866. log_baseCases(void *args)
  867. {
  868. double result;
  869. result = SDL_log(1.0);
  870. SDLTest_AssertCheck(0.0 == result,
  871. "Log(%f), expected %f, got %f",
  872. 1.0, 0.0, result);
  873. result = SDL_log(EULER);
  874. SDLTest_AssertCheck(1.0 == result,
  875. "Log(%f), expected %f, got %f",
  876. EULER, 1.0, result);
  877. return TEST_COMPLETED;
  878. }
  879. /**
  880. * \brief Checks the nan cases.
  881. */
  882. static int
  883. log_nanCases(void *args)
  884. {
  885. double result;
  886. result = SDL_log(NAN);
  887. SDLTest_AssertCheck(isnan(result),
  888. "Log(%f), expected %f, got %f",
  889. NAN, NAN, result);
  890. result = SDL_log(-1234.5678);
  891. SDLTest_AssertCheck(isnan(result),
  892. "Log(%f), expected %f, got %f",
  893. -1234.5678, NAN, result);
  894. return TEST_COMPLETED;
  895. }
  896. /**
  897. * \brief Checks a set of regular cases.
  898. */
  899. static int
  900. log_regularCases(void *args)
  901. {
  902. const d_to_d regular_cases[] = {
  903. { 5.0, 1.60943791243410028179994242236716672778129577636718750 },
  904. { 10.0, 2.302585092994045901093613792909309267997741699218750 },
  905. { 56.32, 4.031049711849786554296315443934872746467590332031250 },
  906. { 789.123, 6.670922202231861497523368598194792866706848144531250 },
  907. { 2734.876324, 7.91384149408957959792587644187733530998229980468750 }
  908. };
  909. return helper_dtod("Log", SDL_log, regular_cases, SDL_arraysize(regular_cases));
  910. }
  911. /* SDL_log10 tests functions */
  912. /**
  913. * \brief Checks limits (zeros and positive infinity).
  914. */
  915. static int
  916. log10_limitCases(void *args)
  917. {
  918. double result;
  919. result = SDL_log10(INFINITY);
  920. SDLTest_AssertCheck(INFINITY == result,
  921. "Log10(%f), expected %f, got %f",
  922. INFINITY, INFINITY, result);
  923. result = SDL_log10(0.0);
  924. SDLTest_AssertCheck(-INFINITY == result,
  925. "Log10(%f), expected %f, got %f",
  926. 0.0, -INFINITY, result);
  927. result = SDL_log10(-0.0);
  928. SDLTest_AssertCheck(-INFINITY == result,
  929. "Log10(%f), expected %f, got %f",
  930. -0.0, -INFINITY, result);
  931. return TEST_COMPLETED;
  932. }
  933. /**
  934. * \brief Checks some base cases.
  935. */
  936. static int
  937. log10_baseCases(void *args)
  938. {
  939. const d_to_d base_cases[] = {
  940. { 1.0, 0.0 },
  941. { 10.0, 1.0 },
  942. { 100.0, 2.0 },
  943. { 1000.0, 3.0 },
  944. { 10000.0, 4.0 },
  945. { 100000.0, 5.0 },
  946. { 1000000.0, 6.0 },
  947. { 10000000.0, 7.0 },
  948. { 100000000.0, 8.0 },
  949. { 1000000000.0, 9.0 },
  950. };
  951. return helper_dtod("Log10", SDL_log10, base_cases, SDL_arraysize(base_cases));
  952. }
  953. /**
  954. * \brief Checks the nan cases.
  955. */
  956. static int
  957. log10_nanCases(void *args)
  958. {
  959. double result;
  960. result = SDL_log10(NAN);
  961. SDLTest_AssertCheck(isnan(result),
  962. "Log10(%f), expected %f, got %f",
  963. NAN, NAN, result);
  964. result = SDL_log10(-1234.5678);
  965. SDLTest_AssertCheck(isnan(result),
  966. "Log10(%f), expected %f, got %f",
  967. -1234.5678, NAN, result);
  968. return TEST_COMPLETED;
  969. }
  970. /**
  971. * \brief Checks a set of regular cases.
  972. */
  973. static int
  974. log10_regularCases(void *args)
  975. {
  976. const d_to_d regular_cases[] = {
  977. { 5.0, 0.698970004336018857493684208748163655400276184082031250 },
  978. { 12.5, 1.09691001300805646145875016372883692383766174316406250 },
  979. { 56.32, 1.750662646134055755453573510749265551567077636718750 },
  980. { 789.123, 2.8971447016351858927407647570362314581871032714843750 },
  981. { 2734.876324, 3.436937691540090433761633903486654162406921386718750 }
  982. };
  983. return helper_dtod("Log10", SDL_log10, regular_cases, SDL_arraysize(regular_cases));
  984. }
  985. /* SDL_pow tests functions */
  986. /* Tests with positive and negative infinities as exponents */
  987. /**
  988. * \brief Checks the cases where the base is negative one and the exponent is infinity.
  989. */
  990. static int
  991. pow_baseNOneExpInfCases(void *args)
  992. {
  993. double result;
  994. result = SDL_pow(-1.0, INFINITY);
  995. SDLTest_AssertCheck(1.0 == result,
  996. "Pow(%f,%f), expected %f, got %f",
  997. -1.0, INFINITY, 1.0, result);
  998. result = SDL_pow(-1.0, -INFINITY);
  999. SDLTest_AssertCheck(1.0 == result,
  1000. "Pow(%f,%f), expected %f, got %f",
  1001. -1.0, -INFINITY, 1.0, result);
  1002. return TEST_COMPLETED;
  1003. }
  1004. /**
  1005. * \brief Checks the case where the base is zero and the exponent is negative infinity.
  1006. */
  1007. static int
  1008. pow_baseZeroExpNInfCases(void *args)
  1009. {
  1010. double result;
  1011. result = SDL_pow(0.0, -INFINITY);
  1012. SDLTest_AssertCheck(INFINITY == result,
  1013. "Pow(%f,%f), expected %f, got %f",
  1014. 0.0, -INFINITY, INFINITY, result);
  1015. result = SDL_pow(-0.0, -INFINITY);
  1016. SDLTest_AssertCheck(INFINITY == result,
  1017. "Pow(%f,%f), expected %f, got %f",
  1018. -0.0, -INFINITY, INFINITY, result);
  1019. return TEST_COMPLETED;
  1020. }
  1021. /**
  1022. * \brief Checks the remaining cases where the exponent is infinity.
  1023. */
  1024. static int
  1025. pow_expInfCases(void *args)
  1026. {
  1027. double result;
  1028. result = SDL_pow(0.5, INFINITY);
  1029. SDLTest_AssertCheck(0.0 == result,
  1030. "Pow(%f,%f), expected %f, got %f",
  1031. 0.5, INFINITY, 0.0, result);
  1032. result = SDL_pow(1.5, INFINITY);
  1033. SDLTest_AssertCheck(INFINITY == result,
  1034. "Pow(%f,%f), expected %f, got %f",
  1035. 1.5, INFINITY, INFINITY, result);
  1036. result = SDL_pow(0.5, -INFINITY);
  1037. SDLTest_AssertCheck(INFINITY == result,
  1038. "Pow(%f,%f), expected %f, got %f",
  1039. 0.5, INFINITY, INFINITY, result);
  1040. result = SDL_pow(1.5, -INFINITY);
  1041. SDLTest_AssertCheck(0.0 == result,
  1042. "Pow(%f,%f), expected %f, got %f",
  1043. 1.5, -INFINITY, 0.0, result);
  1044. return TEST_COMPLETED;
  1045. }
  1046. /* Tests with positive and negative infinities as base */
  1047. /**
  1048. * \brief Checks the cases with positive infinity as base.
  1049. */
  1050. static int
  1051. pow_basePInfCases(void *args)
  1052. {
  1053. double result;
  1054. result = SDL_pow(INFINITY, -3.0);
  1055. SDLTest_AssertCheck(0.0 == result,
  1056. "Pow(%f,%f), expected %f, got %f",
  1057. INFINITY, -3.0, 0.0, result);
  1058. result = SDL_pow(INFINITY, 2.0);
  1059. SDLTest_AssertCheck(INFINITY == result,
  1060. "Pow(%f,%f), expected %f, got %f",
  1061. INFINITY, 2.0, INFINITY, result);
  1062. result = SDL_pow(INFINITY, -2.12345);
  1063. SDLTest_AssertCheck(0.0 == result,
  1064. "Pow(%f,%f), expected %f, got %f",
  1065. INFINITY, -2.12345, 0.0, result);
  1066. result = SDL_pow(INFINITY, 3.1345);
  1067. SDLTest_AssertCheck(INFINITY == result,
  1068. "Pow(%f,%f), expected %f, got %f",
  1069. INFINITY, 3.12345, INFINITY, result);
  1070. return TEST_COMPLETED;
  1071. }
  1072. /**
  1073. * \brief Checks the cases with negative infinity as base.
  1074. */
  1075. static int
  1076. pow_baseNInfCases(void *args)
  1077. {
  1078. double result;
  1079. result = SDL_pow(-INFINITY, -3.0);
  1080. SDLTest_AssertCheck(-0.0 == result,
  1081. "Pow(%f,%f), expected %f, got %f",
  1082. -INFINITY, -3.0, -0.0, result);
  1083. result = SDL_pow(-INFINITY, -2.0);
  1084. SDLTest_AssertCheck(0.0 == result,
  1085. "Pow(%f,%f), expected %f, got %f",
  1086. -INFINITY, -2.0, 0.0, result);
  1087. result = SDL_pow(-INFINITY, -5.5);
  1088. SDLTest_AssertCheck(0.0 == result,
  1089. "Pow(%f,%f), expected %f, got %f",
  1090. -INFINITY, -5.5, 0.0, result);
  1091. result = SDL_pow(-INFINITY, 3.0);
  1092. SDLTest_AssertCheck(-INFINITY == result,
  1093. "Pow(%f,%f), expected %f, got %f",
  1094. -INFINITY, 3.0, -INFINITY, result);
  1095. result = SDL_pow(-INFINITY, 2.0);
  1096. SDLTest_AssertCheck(INFINITY == result,
  1097. "Pow(%f,%f), expected %f, got %f",
  1098. -INFINITY, 2.0, INFINITY, result);
  1099. result = SDL_pow(-INFINITY, 5.5);
  1100. SDLTest_AssertCheck(INFINITY == result,
  1101. "Pow(%f,%f), expected %f, got %f",
  1102. -INFINITY, 5.5, INFINITY, result);
  1103. return TEST_COMPLETED;
  1104. }
  1105. /* Tests related to nan */
  1106. /**
  1107. * \brief Checks the case where the base is finite and negative and exponent is finite and non-integer.
  1108. */
  1109. static int
  1110. pow_badOperationCase(void *args)
  1111. {
  1112. const double result = SDL_pow(-2.0, 4.2);
  1113. SDLTest_AssertCheck(isnan(result),
  1114. "Pow(%f,%f), expected %f, got %f",
  1115. -2.0, 4.2, NAN, result);
  1116. return TEST_COMPLETED;
  1117. }
  1118. /**
  1119. * \brief Checks the case where the exponent is nan but the base is 1.
  1120. */
  1121. static int
  1122. pow_base1ExpNanCase(void *args)
  1123. {
  1124. const double result = SDL_pow(1.0, NAN);
  1125. SDLTest_AssertCheck(1.0 == result,
  1126. "Pow(%f,%f), expected %f, got %f",
  1127. 1.0, NAN, 1.0, result);
  1128. return TEST_COMPLETED;
  1129. }
  1130. /**
  1131. * \brief Checks the cases where the base is nan but the exponent is 0.
  1132. */
  1133. static int
  1134. pow_baseNanExp0Cases(void *args)
  1135. {
  1136. double result;
  1137. result = SDL_pow(NAN, 0.0);
  1138. SDLTest_AssertCheck(1.0 == result,
  1139. "Pow(%f,%f), expected %f, got %f",
  1140. NAN, 0.0, 1.0, result);
  1141. return TEST_COMPLETED;
  1142. result = SDL_pow(NAN, -0.0);
  1143. SDLTest_AssertCheck(1.0 == result,
  1144. "Pow(%f,%f), expected %f, got %f",
  1145. NAN, -0.0, 1.0, result);
  1146. return TEST_COMPLETED;
  1147. }
  1148. /**
  1149. * \brief Checks the cases where either argument is nan.
  1150. */
  1151. static int
  1152. pow_nanArgsCases(void *args)
  1153. {
  1154. double result;
  1155. result = SDL_pow(7.8, NAN);
  1156. SDLTest_AssertCheck(isnan(result),
  1157. "Pow(%f,%f), expected %f, got %f",
  1158. 7.8, NAN, NAN, result);
  1159. result = SDL_pow(NAN, 10.0);
  1160. SDLTest_AssertCheck(isnan(result),
  1161. "Pow(%f,%f), expected %f, got %f",
  1162. NAN, 10.0, NAN, result);
  1163. result = SDL_pow(NAN, NAN);
  1164. SDLTest_AssertCheck(isnan(result),
  1165. "Pow(%f,%f), expected %f, got %f",
  1166. NAN, NAN, NAN, result);
  1167. return TEST_COMPLETED;
  1168. }
  1169. /* Tests with positive and negative zeros as base */
  1170. /**
  1171. * \brief Checks cases with negative zero as base and an odd exponent.
  1172. */
  1173. static int
  1174. pow_baseNZeroExpOddCases(void *args)
  1175. {
  1176. double result;
  1177. result = SDL_pow(-0.0, -3.0);
  1178. SDLTest_AssertCheck(-INFINITY == result,
  1179. "Pow(%f,%f), expected %f, got %f",
  1180. -0.0, -3.0, -INFINITY, result);
  1181. result = SDL_pow(-0.0, 3.0);
  1182. SDLTest_AssertCheck(-0.0 == result,
  1183. "Pow(%f,%f), expected %f, got %f",
  1184. -0.0, 3.0, -0.0, result);
  1185. return TEST_COMPLETED;
  1186. }
  1187. /**
  1188. * \brief Checks cases with positive zero as base and an odd exponent.
  1189. */
  1190. static int
  1191. pow_basePZeroExpOddCases(void *args)
  1192. {
  1193. double result;
  1194. result = SDL_pow(0.0, -5.0);
  1195. SDLTest_AssertCheck(INFINITY == result,
  1196. "Pow(%f,%f), expected %f, got %f",
  1197. 0.0, -5.0, INFINITY, result);
  1198. result = SDL_pow(0.0, 5.0);
  1199. SDLTest_AssertCheck(0.0 == result,
  1200. "Pow(%f,%f), expected %f, got %f",
  1201. 0.0, 5.0, 0.0, result);
  1202. return TEST_COMPLETED;
  1203. }
  1204. /**
  1205. * \brief Checks cases with negative zero as base and the exponent is finite and even or non-integer.
  1206. */
  1207. static int
  1208. pow_baseNZeroCases(void *args)
  1209. {
  1210. double result;
  1211. result = SDL_pow(-0.0, -3.5);
  1212. SDLTest_AssertCheck(INFINITY == result,
  1213. "Pow(%f,%f), expected %f, got %f",
  1214. -0.0, -3.5, INFINITY, result);
  1215. result = SDL_pow(-0.0, -4.0);
  1216. SDLTest_AssertCheck(INFINITY == result,
  1217. "Pow(%f,%f), expected %f, got %f",
  1218. -0.0, -4.0, INFINITY, result);
  1219. result = SDL_pow(-0.0, 3.5);
  1220. SDLTest_AssertCheck(0.0 == result,
  1221. "Pow(%f,%f), expected %f, got %f",
  1222. -0.0, 3.5, 0.0, result);
  1223. result = SDL_pow(-0.0, 4.0);
  1224. SDLTest_AssertCheck(0.0 == result,
  1225. "Pow(%f,%f), expected %f, got %f",
  1226. -0.0, 4.0, 0.0, result);
  1227. return TEST_COMPLETED;
  1228. }
  1229. /**
  1230. * \brief Checks cases with positive zero as base and the exponent is finite and even or non-integer.
  1231. */
  1232. static int
  1233. pow_basePZeroCases(void *args)
  1234. {
  1235. double result;
  1236. result = SDL_pow(0.0, -3.5);
  1237. SDLTest_AssertCheck(INFINITY == result,
  1238. "Pow(%f,%f), expected %f, got %f",
  1239. 0.0, -3.5, INFINITY, result);
  1240. result = SDL_pow(0.0, -4.0);
  1241. SDLTest_AssertCheck(INFINITY == result,
  1242. "Pow(%f,%f), expected %f, got %f",
  1243. 0.0, -4.0, INFINITY, result);
  1244. result = SDL_pow(0.0, 3.5);
  1245. SDLTest_AssertCheck(0.0 == result,
  1246. "Pow(%f,%f), expected %f, got %f",
  1247. 0.0, 3.5, 0.0, result);
  1248. result = SDL_pow(0.0, 4.0);
  1249. SDLTest_AssertCheck(0.0 == result,
  1250. "Pow(%f,%f), expected %f, got %f",
  1251. 0.0, 4.0, 0.0, result);
  1252. return TEST_COMPLETED;
  1253. }
  1254. /* Remaining tests */
  1255. /**
  1256. * \brief Checks a set of regular values.
  1257. */
  1258. static int
  1259. pow_regularCases(void *args)
  1260. {
  1261. const dd_to_d regular_cases[] = {
  1262. { -391.25, -2.0, 0.00000653267870448815438463212659780943170062528224661946296691894531250 },
  1263. { -72.3, 12.0, 20401381050275984310272.0 },
  1264. { -5.0, 3.0, -125.0 },
  1265. { 3.0, 2.5, 15.58845726811989607085706666111946105957031250 },
  1266. { 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 },
  1267. { 478.972, 12.125, 315326359630449587856007411793920.0 }
  1268. };
  1269. return helper_ddtod("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases));
  1270. }
  1271. /**
  1272. * \brief Checks the powers of two from 1 to 8.
  1273. */
  1274. static int
  1275. pow_powerOfTwo(void *args)
  1276. {
  1277. const dd_to_d power_of_two_cases[] = {
  1278. { 2.0, 1, 2.0 },
  1279. { 2.0, 2, 4.0 },
  1280. { 2.0, 3, 8.0 },
  1281. { 2.0, 4, 16.0 },
  1282. { 2.0, 5, 32.0 },
  1283. { 2.0, 6, 64.0 },
  1284. { 2.0, 7, 128.0 },
  1285. { 2.0, 8, 256.0 },
  1286. };
  1287. return helper_ddtod("Pow", SDL_pow, power_of_two_cases, SDL_arraysize(power_of_two_cases));
  1288. }
  1289. /**
  1290. * \brief Checks a range of values between 0 and UINT32_MAX to the power of 0.
  1291. */
  1292. static int
  1293. pow_rangeTest(void *args)
  1294. {
  1295. Uint32 i;
  1296. double test_value = 0.0;
  1297. SDLTest_AssertPass("Pow: Testing a range of %u values with steps of %u",
  1298. RANGE_TEST_ITERATIONS,
  1299. RANGE_TEST_STEP);
  1300. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1301. double result;
  1302. /* These are tested elsewhere */
  1303. if (isnan(test_value) || isinf(test_value)) {
  1304. continue;
  1305. }
  1306. /* Only log failures to save performances */
  1307. result = SDL_pow(test_value, 0.0);
  1308. if (result != 1.0) {
  1309. SDLTest_AssertCheck(SDL_FALSE,
  1310. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1311. test_value, 1.0, 1.0, result);
  1312. return TEST_ABORTED;
  1313. }
  1314. result = SDL_pow(test_value, -0.0);
  1315. if (result != 1.0) {
  1316. SDLTest_AssertCheck(SDL_FALSE,
  1317. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1318. test_value, -0.0, 1.0, result);
  1319. return TEST_ABORTED;
  1320. }
  1321. }
  1322. return TEST_COMPLETED;
  1323. }
  1324. /* SDL_sqrt tests functions */
  1325. /**
  1326. * \brief Checks for positive infinity.
  1327. */
  1328. static int
  1329. sqrt_infCase(void *args)
  1330. {
  1331. const double result = SDL_sqrt(INFINITY);
  1332. SDLTest_AssertCheck(INFINITY == result,
  1333. "Sqrt(%f), expected %f, got %f",
  1334. INFINITY, INFINITY, result);
  1335. return TEST_COMPLETED;
  1336. }
  1337. /**
  1338. * \brief Checks for the nan case.
  1339. */
  1340. static int
  1341. sqrt_nanCase(void *args)
  1342. {
  1343. const double result = SDL_sqrt(NAN);
  1344. SDLTest_AssertCheck(isnan(result),
  1345. "Sqrt(%f), expected %f, got %f",
  1346. NAN, NAN, result);
  1347. return TEST_COMPLETED;
  1348. }
  1349. /**
  1350. * \brief Checks for out of domain values (<0).
  1351. */
  1352. static int
  1353. sqrt_outOfDomainCases(void *args)
  1354. {
  1355. double result;
  1356. result = SDL_sqrt(-1.0);
  1357. SDLTest_AssertCheck(isnan(result),
  1358. "Sqrt(%f), expected %f, got %f",
  1359. -1.0, NAN, result);
  1360. result = SDL_sqrt(-12345.6789);
  1361. SDLTest_AssertCheck(isnan(result),
  1362. "Sqrt(%f), expected %f, got %f",
  1363. -12345.6789, NAN, result);
  1364. result = SDL_sqrt(-INFINITY);
  1365. SDLTest_AssertCheck(isnan(result),
  1366. "Sqrt(%f), expected %f, got %f",
  1367. -INFINITY, NAN, result);
  1368. return TEST_COMPLETED;
  1369. }
  1370. /**
  1371. * \brief Checks a set of base cases.
  1372. */
  1373. static int
  1374. sqrt_baseCases(void *args)
  1375. {
  1376. const d_to_d base_cases[] = {
  1377. { -0.0, -0.0 },
  1378. { 0.0, 0.0 },
  1379. { 1.0, 1.0 }
  1380. };
  1381. return helper_dtod("Sqrt", SDL_sqrt, base_cases, SDL_arraysize(base_cases));
  1382. }
  1383. /**
  1384. * \brief Checks a set of regular cases.
  1385. */
  1386. static int
  1387. sqrt_regularCases(void *args)
  1388. {
  1389. const d_to_d regular_cases[] = {
  1390. { 4.0, 2.0 },
  1391. { 9.0, 3.0 },
  1392. { 27.2, 5.21536192416211896727418206864967942237854003906250 },
  1393. { 240.250, 15.5 },
  1394. { 1337.0, 36.565010597564445049556525191292166709899902343750 },
  1395. { 2887.12782400000014604302123188972473144531250, 53.732 },
  1396. { 65600.0156250, 256.125 }
  1397. };
  1398. return helper_dtod("Sqrt", SDL_sqrt, regular_cases, SDL_arraysize(regular_cases));
  1399. }
  1400. /* SDL_scalbn tests functions */
  1401. /**
  1402. * \brief Checks for positive and negative infinity arg.
  1403. */
  1404. static int
  1405. scalbn_infCases(void *args)
  1406. {
  1407. double result;
  1408. result = SDL_scalbn(INFINITY, 1);
  1409. SDLTest_AssertCheck(INFINITY == result,
  1410. "Scalbn(%f,%d), expected %f, got %f",
  1411. INFINITY, 1, INFINITY, result);
  1412. result = SDL_scalbn(-INFINITY, 1);
  1413. SDLTest_AssertCheck(-INFINITY == result,
  1414. "Scalbn(%f,%d), expected %f, got %f",
  1415. -INFINITY, 1, -INFINITY, result);
  1416. return TEST_COMPLETED;
  1417. }
  1418. /**
  1419. * \brief Checks for positive and negative zero arg.
  1420. */
  1421. static int
  1422. scalbn_baseZeroCases(void *args)
  1423. {
  1424. double result;
  1425. result = SDL_scalbn(0.0, 1);
  1426. SDLTest_AssertCheck(0.0 == result,
  1427. "Scalbn(%f,%d), expected %f, got %f",
  1428. 0.0, 1, 0.0, result);
  1429. result = SDL_scalbn(-0.0, 1);
  1430. SDLTest_AssertCheck(-0.0 == result,
  1431. "Scalbn(%f,%d), expected %f, got %f",
  1432. -0.0, 1, -0.0, result);
  1433. return TEST_COMPLETED;
  1434. }
  1435. /**
  1436. * \brief Checks for zero exp.
  1437. */
  1438. static int
  1439. scalbn_expZeroCase(void *args)
  1440. {
  1441. const double result = SDL_scalbn(42.0, 0);
  1442. SDLTest_AssertCheck(42.0 == result,
  1443. "Scalbn(%f,%d), expected %f, got %f",
  1444. 42.0, 0, 42.0, result);
  1445. return TEST_COMPLETED;
  1446. }
  1447. /**
  1448. * \brief Checks for NAN arg.
  1449. */
  1450. static int
  1451. scalbn_nanCase(void *args)
  1452. {
  1453. const double result = SDL_scalbn(NAN, 2);
  1454. SDLTest_AssertCheck(isnan(result),
  1455. "Scalbn(%f,%d), expected %f, got %f",
  1456. NAN, 2, NAN, result);
  1457. return TEST_COMPLETED;
  1458. }
  1459. /**
  1460. * \brief Checks a set of regular values.
  1461. *
  1462. * This test depends on SDL_pow functionning.
  1463. */
  1464. static int
  1465. scalbn_regularCases(void *args)
  1466. {
  1467. double result, expected;
  1468. result = SDL_scalbn(2.0, 2);
  1469. expected = 2.0 * SDL_pow(FLT_RADIX, 2);
  1470. SDLTest_AssertCheck(result == expected,
  1471. "Scalbn(%f,%d), expected %f, got %f",
  1472. 2.0, 2, expected, result);
  1473. result = SDL_scalbn(1.0, 13);
  1474. expected = 1.0 * SDL_pow(FLT_RADIX, 13);
  1475. SDLTest_AssertCheck(result == expected,
  1476. "Scalbn(%f,%d), expected %f, got %f",
  1477. 1.0, 13, expected, result);
  1478. result = SDL_scalbn(2.0, -5);
  1479. expected = 2.0 * SDL_pow(FLT_RADIX, -5);
  1480. SDLTest_AssertCheck(result == expected,
  1481. "Scalbn(%f,%d), expected %f, got %f",
  1482. 2.0, -5, expected, result);
  1483. result = SDL_scalbn(-1.0, -13);
  1484. expected = -1.0 * SDL_pow(FLT_RADIX, -13);
  1485. SDLTest_AssertCheck(result == expected,
  1486. "Scalbn(%f,%d), expected %f, got %f",
  1487. -1.0, -13, expected, result);
  1488. return TEST_COMPLETED;
  1489. }
  1490. /* SDL_cos tests functions */
  1491. /**
  1492. * \brief Checks positive and negative infinity.
  1493. */
  1494. static int
  1495. cos_infCases(void *args)
  1496. {
  1497. double result;
  1498. result = SDL_cos(INFINITY);
  1499. SDLTest_AssertCheck(isnan(result),
  1500. "Cos(%f), expected %f, got %f",
  1501. INFINITY, NAN, result);
  1502. result = SDL_cos(-INFINITY);
  1503. SDLTest_AssertCheck(isnan(result),
  1504. "Cos(%f), expected %f, got %f",
  1505. -INFINITY, NAN, result);
  1506. return TEST_COMPLETED;
  1507. }
  1508. /**
  1509. * \brief Checks for nan.
  1510. */
  1511. static int
  1512. cos_nanCase(void *args)
  1513. {
  1514. const double result = SDL_cos(NAN);
  1515. SDLTest_AssertCheck(isnan(result),
  1516. "Cos(%f), expected %f, got %f",
  1517. NAN, NAN, result);
  1518. return TEST_COMPLETED;
  1519. }
  1520. /**
  1521. * \brief Checks a set of regular values.
  1522. */
  1523. static int
  1524. cos_regularCases(void *args)
  1525. {
  1526. const d_to_d regular_cases[] = {
  1527. { -M_PI, -1.0 },
  1528. { -0.0, 1.0 },
  1529. { 0.0, 1.0 },
  1530. { M_PI, -1.0 }
  1531. };
  1532. return helper_dtod("Cos", SDL_cos, regular_cases, SDL_arraysize(regular_cases));
  1533. }
  1534. /**
  1535. * \brief Checks cosine precision for the first 10 decimals.
  1536. *
  1537. * This function depends on SDL_floor functioning.
  1538. */
  1539. static int
  1540. cos_precisionTest(void *args)
  1541. {
  1542. Uint32 i;
  1543. Uint32 iterations = 20;
  1544. double angle = 0.0;
  1545. double step = 2.0 * M_PI / iterations;
  1546. const double expected[] = {
  1547. 10000000000.0, 9510565162.0, 8090169943.0, 5877852522.0, 3090169943.0,
  1548. 0.0, -3090169943.0, -5877852522.0, -8090169943.0, -9510565162.0,
  1549. -10000000000.0, -9510565162.0, -8090169943.0, -5877852522.0, -3090169943.0,
  1550. 0.0, 3090169943.0, 5877852522.0, 8090169943.0, 9510565162.0
  1551. };
  1552. for (i = 0; i < iterations; i++, angle += step) {
  1553. double result = SDL_cos(angle) * 1.0E10;
  1554. SDLTest_AssertCheck(SDL_trunc(result) == expected[i],
  1555. "Cos(%f), expected %f, got %f",
  1556. angle, expected[i], result);
  1557. }
  1558. return TEST_COMPLETED;
  1559. }
  1560. /**
  1561. * \brief Checks a range of values between 0 and UINT32_MAX.
  1562. */
  1563. static int
  1564. cos_rangeTest(void *args)
  1565. {
  1566. Uint32 i;
  1567. double test_value = 0.0;
  1568. SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %u",
  1569. RANGE_TEST_ITERATIONS,
  1570. RANGE_TEST_STEP);
  1571. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1572. double result;
  1573. /* These are tested elsewhere */
  1574. if (isnan(test_value) || isinf(test_value)) {
  1575. continue;
  1576. }
  1577. /* Only log failures to save performances */
  1578. result = SDL_cos(test_value);
  1579. if (result < -1.0 || result > 1.0) {
  1580. SDLTest_AssertCheck(SDL_FALSE,
  1581. "Cos(%.1f), expected [%.1f,%.1f], got %.1f",
  1582. test_value, -1.0, 1.0, result);
  1583. return TEST_ABORTED;
  1584. }
  1585. }
  1586. return TEST_COMPLETED;
  1587. }
  1588. /* ================= Test References ================== */
  1589. /* SDL_floor test cases */
  1590. static const SDLTest_TestCaseReference floorTestInf = {
  1591. (SDLTest_TestCaseFp) floor_infCases, "floor_infCases",
  1592. "Check positive and negative infinity", TEST_ENABLED
  1593. };
  1594. static const SDLTest_TestCaseReference floorTestZero = {
  1595. (SDLTest_TestCaseFp) floor_zeroCases, "floor_zeroCases",
  1596. "Check positive and negative zero", TEST_ENABLED
  1597. };
  1598. static const SDLTest_TestCaseReference floorTestNan = {
  1599. (SDLTest_TestCaseFp) floor_nanCase, "floor_nanCase",
  1600. "Check the NaN special case", TEST_ENABLED
  1601. };
  1602. static const SDLTest_TestCaseReference floorTestRound = {
  1603. (SDLTest_TestCaseFp) floor_roundNumbersCases, "floor_roundNumberCases",
  1604. "Check a set of round numbers", TEST_ENABLED
  1605. };
  1606. static const SDLTest_TestCaseReference floorTestFraction = {
  1607. (SDLTest_TestCaseFp) floor_fractionCases, "floor_fractionCases",
  1608. "Check a set of fractions", TEST_ENABLED
  1609. };
  1610. static const SDLTest_TestCaseReference floorTestRange = {
  1611. (SDLTest_TestCaseFp) floor_rangeTest, "floor_rangeTest",
  1612. "Check a range of positive integer", TEST_ENABLED
  1613. };
  1614. /* SDL_ceil test cases */
  1615. static const SDLTest_TestCaseReference ceilTestInf = {
  1616. (SDLTest_TestCaseFp) ceil_infCases, "ceil_infCases",
  1617. "Check positive and negative infinity", TEST_ENABLED
  1618. };
  1619. static const SDLTest_TestCaseReference ceilTestZero = {
  1620. (SDLTest_TestCaseFp) ceil_zeroCases, "ceil_zeroCases",
  1621. "Check positive and negative zero", TEST_ENABLED
  1622. };
  1623. static const SDLTest_TestCaseReference ceilTestNan = {
  1624. (SDLTest_TestCaseFp) ceil_nanCase, "ceil_nanCase",
  1625. "Check the NaN special case", TEST_ENABLED
  1626. };
  1627. static const SDLTest_TestCaseReference ceilTestRound = {
  1628. (SDLTest_TestCaseFp) ceil_roundNumbersCases, "ceil_roundNumberCases",
  1629. "Check a set of round numbers", TEST_ENABLED
  1630. };
  1631. static const SDLTest_TestCaseReference ceilTestFraction = {
  1632. (SDLTest_TestCaseFp) ceil_fractionCases, "ceil_fractionCases",
  1633. "Check a set of fractions", TEST_ENABLED
  1634. };
  1635. static const SDLTest_TestCaseReference ceilTestRange = {
  1636. (SDLTest_TestCaseFp) ceil_rangeTest, "ceil_rangeTest",
  1637. "Check a range of positive integer", TEST_ENABLED
  1638. };
  1639. /* SDL_trunc test cases */
  1640. static const SDLTest_TestCaseReference truncTestInf = {
  1641. (SDLTest_TestCaseFp) trunc_infCases, "trunc_infCases",
  1642. "Check positive and negative infinity", TEST_ENABLED
  1643. };
  1644. static const SDLTest_TestCaseReference truncTestZero = {
  1645. (SDLTest_TestCaseFp) trunc_zeroCases, "trunc_zeroCases",
  1646. "Check positive and negative zero", TEST_ENABLED
  1647. };
  1648. static const SDLTest_TestCaseReference truncTestNan = {
  1649. (SDLTest_TestCaseFp) trunc_nanCase, "trunc_nanCase",
  1650. "Check the NaN special case", TEST_ENABLED
  1651. };
  1652. static const SDLTest_TestCaseReference truncTestRound = {
  1653. (SDLTest_TestCaseFp) trunc_roundNumbersCases, "trunc_roundNumberCases",
  1654. "Check a set of round numbers", TEST_ENABLED
  1655. };
  1656. static const SDLTest_TestCaseReference truncTestFraction = {
  1657. (SDLTest_TestCaseFp) trunc_fractionCases, "trunc_fractionCases",
  1658. "Check a set of fractions", TEST_ENABLED
  1659. };
  1660. static const SDLTest_TestCaseReference truncTestRange = {
  1661. (SDLTest_TestCaseFp) trunc_rangeTest, "trunc_rangeTest",
  1662. "Check a range of positive integer", TEST_ENABLED
  1663. };
  1664. /* SDL_round test cases */
  1665. static const SDLTest_TestCaseReference roundTestInf = {
  1666. (SDLTest_TestCaseFp) round_infCases, "round_infCases",
  1667. "Check positive and negative infinity", TEST_ENABLED
  1668. };
  1669. static const SDLTest_TestCaseReference roundTestZero = {
  1670. (SDLTest_TestCaseFp) round_zeroCases, "round_zeroCases",
  1671. "Check positive and negative zero", TEST_ENABLED
  1672. };
  1673. static const SDLTest_TestCaseReference roundTestNan = {
  1674. (SDLTest_TestCaseFp) round_nanCase, "round_nanCase",
  1675. "Check the NaN special case", TEST_ENABLED
  1676. };
  1677. static const SDLTest_TestCaseReference roundTestRound = {
  1678. (SDLTest_TestCaseFp) round_roundNumbersCases, "round_roundNumberCases",
  1679. "Check a set of round numbers", TEST_ENABLED
  1680. };
  1681. static const SDLTest_TestCaseReference roundTestFraction = {
  1682. (SDLTest_TestCaseFp) round_fractionCases, "round_fractionCases",
  1683. "Check a set of fractions", TEST_ENABLED
  1684. };
  1685. static const SDLTest_TestCaseReference roundTestRange = {
  1686. (SDLTest_TestCaseFp) round_rangeTest, "round_rangeTest",
  1687. "Check a range of positive integer", TEST_ENABLED
  1688. };
  1689. /* SDL_fabs test cases */
  1690. static const SDLTest_TestCaseReference fabsTestInf = {
  1691. (SDLTest_TestCaseFp) fabs_infCases, "fabs_infCases",
  1692. "Check positive and negative infinity", TEST_ENABLED
  1693. };
  1694. static const SDLTest_TestCaseReference fabsTestZero = {
  1695. (SDLTest_TestCaseFp) fabs_zeroCases, "fabs_zeroCases",
  1696. "Check positive and negative zero", TEST_ENABLED
  1697. };
  1698. static const SDLTest_TestCaseReference fabsTestNan = {
  1699. (SDLTest_TestCaseFp) fabs_nanCase, "fabs_nanCase",
  1700. "Check the NaN special case", TEST_ENABLED
  1701. };
  1702. static const SDLTest_TestCaseReference fabsTestRange = {
  1703. (SDLTest_TestCaseFp) fabs_rangeTest, "fabs_rangeTest",
  1704. "Check a range of positive integer", TEST_ENABLED
  1705. };
  1706. /* SDL_copysign test cases */
  1707. static const SDLTest_TestCaseReference copysignTestInf = {
  1708. (SDLTest_TestCaseFp) copysign_infCases, "copysign_infCases",
  1709. "Check positive and negative infinity", TEST_ENABLED
  1710. };
  1711. static const SDLTest_TestCaseReference copysignTestZero = {
  1712. (SDLTest_TestCaseFp) copysign_zeroCases, "copysign_zeroCases",
  1713. "Check positive and negative zero", TEST_ENABLED
  1714. };
  1715. static const SDLTest_TestCaseReference copysignTestNan = {
  1716. (SDLTest_TestCaseFp) copysign_nanCases, "copysign_nanCases",
  1717. "Check the NaN special cases", TEST_ENABLED
  1718. };
  1719. static const SDLTest_TestCaseReference copysignTestRange = {
  1720. (SDLTest_TestCaseFp) copysign_rangeTest, "copysign_rangeTest",
  1721. "Check a range of positive integer", TEST_ENABLED
  1722. };
  1723. /* SDL_fmod test cases */
  1724. static const SDLTest_TestCaseReference fmodTestDivOfInf = {
  1725. (SDLTest_TestCaseFp) fmod_divOfInfCases, "fmod_divOfInfCases",
  1726. "Check division of positive and negative infinity", TEST_ENABLED
  1727. };
  1728. static const SDLTest_TestCaseReference fmodTestDivByInf = {
  1729. (SDLTest_TestCaseFp) fmod_divByInfCases, "fmod_divByInfCases",
  1730. "Check division by positive and negative infinity", TEST_ENABLED
  1731. };
  1732. static const SDLTest_TestCaseReference fmodTestDivOfZero = {
  1733. (SDLTest_TestCaseFp) fmod_divOfZeroCases, "fmod_divOfZeroCases",
  1734. "Check division of positive and negative zero", TEST_ENABLED
  1735. };
  1736. static const SDLTest_TestCaseReference fmodTestDivByZero = {
  1737. (SDLTest_TestCaseFp) fmod_divByZeroCases, "fmod_divByZeroCases",
  1738. "Check division by positive and negative zero", TEST_ENABLED
  1739. };
  1740. static const SDLTest_TestCaseReference fmodTestNan = {
  1741. (SDLTest_TestCaseFp) fmod_nanCases, "fmod_nanCases",
  1742. "Check the NaN special cases", TEST_ENABLED
  1743. };
  1744. static const SDLTest_TestCaseReference fmodTestRegular = {
  1745. (SDLTest_TestCaseFp) fmod_regularCases, "fmod_regularCases",
  1746. "Check a set of regular values", TEST_ENABLED
  1747. };
  1748. static const SDLTest_TestCaseReference fmodTestRange = {
  1749. (SDLTest_TestCaseFp) fmod_rangeTest, "fmod_rangeTest",
  1750. "Check a range of positive integer", TEST_ENABLED
  1751. };
  1752. /* SDL_exp test cases */
  1753. static const SDLTest_TestCaseReference expTestInf = {
  1754. (SDLTest_TestCaseFp) exp_infCases, "exp_infCases",
  1755. "Check positive and negative infinity", TEST_ENABLED
  1756. };
  1757. static const SDLTest_TestCaseReference expTestZero = {
  1758. (SDLTest_TestCaseFp) exp_zeroCases, "exp_zeroCases",
  1759. "Check for positive and negative zero", TEST_ENABLED
  1760. };
  1761. static const SDLTest_TestCaseReference expTestOverflow = {
  1762. (SDLTest_TestCaseFp) exp_overflowCase, "exp_overflowCase",
  1763. "Check for overflow", TEST_ENABLED
  1764. };
  1765. static const SDLTest_TestCaseReference expTestBase = {
  1766. (SDLTest_TestCaseFp) exp_baseCase, "exp_baseCase",
  1767. "Check the base case of 1.0", TEST_ENABLED
  1768. };
  1769. static const SDLTest_TestCaseReference expTestRegular = {
  1770. (SDLTest_TestCaseFp) exp_regularCases, "exp_regularCases",
  1771. "Check a set of regular values", TEST_ENABLED
  1772. };
  1773. /* SDL_log test cases */
  1774. static const SDLTest_TestCaseReference logTestLimit = {
  1775. (SDLTest_TestCaseFp) log_limitCases, "log_limitCases",
  1776. "Check for limits", TEST_ENABLED
  1777. };
  1778. static const SDLTest_TestCaseReference logTestNan = {
  1779. (SDLTest_TestCaseFp) log_nanCases, "log_nanCases",
  1780. "Check for the nan cases", TEST_ENABLED
  1781. };
  1782. static const SDLTest_TestCaseReference logTestBase = {
  1783. (SDLTest_TestCaseFp) log_baseCases, "log_baseCases",
  1784. "Check for base cases", TEST_ENABLED
  1785. };
  1786. static const SDLTest_TestCaseReference logTestRegular = {
  1787. (SDLTest_TestCaseFp) log_regularCases, "log_regularCases",
  1788. "Check a set of regular values", TEST_ENABLED
  1789. };
  1790. /* SDL_log10 test cases */
  1791. static const SDLTest_TestCaseReference log10TestLimit = {
  1792. (SDLTest_TestCaseFp) log10_limitCases, "log10_limitCases",
  1793. "Check for limits", TEST_ENABLED
  1794. };
  1795. static const SDLTest_TestCaseReference log10TestNan = {
  1796. (SDLTest_TestCaseFp) log10_nanCases, "log10_nanCases",
  1797. "Check for the nan cases", TEST_ENABLED
  1798. };
  1799. static const SDLTest_TestCaseReference log10TestBase = {
  1800. (SDLTest_TestCaseFp) log10_baseCases, "log10_baseCases",
  1801. "Check for base cases", TEST_ENABLED
  1802. };
  1803. static const SDLTest_TestCaseReference log10TestRegular = {
  1804. (SDLTest_TestCaseFp) log10_regularCases, "log10_regularCases",
  1805. "Check a set of regular values", TEST_ENABLED
  1806. };
  1807. /* SDL_pow test cases */
  1808. static const SDLTest_TestCaseReference powTestExpInf1 = {
  1809. (SDLTest_TestCaseFp) pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
  1810. "Check for pow(-1, +/-inf)", TEST_ENABLED
  1811. };
  1812. static const SDLTest_TestCaseReference powTestExpInf2 = {
  1813. (SDLTest_TestCaseFp) pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
  1814. "Check for pow(+/-0, -inf)", TEST_ENABLED
  1815. };
  1816. static const SDLTest_TestCaseReference powTestExpInf3 = {
  1817. (SDLTest_TestCaseFp) pow_expInfCases, "pow_expInfCases",
  1818. "Check for pow(x, +/-inf)", TEST_ENABLED
  1819. };
  1820. static const SDLTest_TestCaseReference powTestBaseInf1 = {
  1821. (SDLTest_TestCaseFp) pow_basePInfCases, "pow_basePInfCases",
  1822. "Check for pow(inf, x)", TEST_ENABLED
  1823. };
  1824. static const SDLTest_TestCaseReference powTestBaseInf2 = {
  1825. (SDLTest_TestCaseFp) pow_baseNInfCases, "pow_baseNInfCases",
  1826. "Check for pow(-inf, x)", TEST_ENABLED
  1827. };
  1828. static const SDLTest_TestCaseReference powTestNan1 = {
  1829. (SDLTest_TestCaseFp) pow_badOperationCase, "pow_badOperationCase",
  1830. "Check for negative finite base and non-integer finite exponent", TEST_ENABLED
  1831. };
  1832. static const SDLTest_TestCaseReference powTestNan2 = {
  1833. (SDLTest_TestCaseFp) pow_base1ExpNanCase, "pow_base1ExpNanCase",
  1834. "Check for pow(1.0, nan)", TEST_ENABLED
  1835. };
  1836. static const SDLTest_TestCaseReference powTestNan3 = {
  1837. (SDLTest_TestCaseFp) pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
  1838. "Check for pow(nan, +/-0)", TEST_ENABLED
  1839. };
  1840. static const SDLTest_TestCaseReference powTestNan4 = {
  1841. (SDLTest_TestCaseFp) pow_nanArgsCases, "pow_nanArgsCases",
  1842. "Check for pow(x, y) with either x or y being nan", TEST_ENABLED
  1843. };
  1844. static const SDLTest_TestCaseReference powTestZero1 = {
  1845. (SDLTest_TestCaseFp) pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
  1846. "Check for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
  1847. };
  1848. static const SDLTest_TestCaseReference powTestZero2 = {
  1849. (SDLTest_TestCaseFp) pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
  1850. "Check for pow(0.0, y), with y an odd integer.", TEST_ENABLED
  1851. };
  1852. static const SDLTest_TestCaseReference powTestZero3 = {
  1853. (SDLTest_TestCaseFp) pow_baseNZeroCases, "pow_baseNZeroCases",
  1854. "Check for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  1855. };
  1856. static const SDLTest_TestCaseReference powTestZero4 = {
  1857. (SDLTest_TestCaseFp) pow_basePZeroCases, "pow_basePZeroCases",
  1858. "Check for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  1859. };
  1860. static const SDLTest_TestCaseReference powTestRegular = {
  1861. (SDLTest_TestCaseFp) pow_regularCases, "pow_regularCases",
  1862. "Check a set of regular values", TEST_ENABLED
  1863. };
  1864. static const SDLTest_TestCaseReference powTestPowOf2 = {
  1865. (SDLTest_TestCaseFp) pow_powerOfTwo, "pow_powerOfTwo",
  1866. "Check the powers of two from 1 to 8", TEST_ENABLED
  1867. };
  1868. static const SDLTest_TestCaseReference powTestRange = {
  1869. (SDLTest_TestCaseFp) pow_rangeTest, "pow_rangeTest",
  1870. "Check a range of positive integer to the power of 0", TEST_ENABLED
  1871. };
  1872. /* SDL_sqrt test cases */
  1873. static const SDLTest_TestCaseReference sqrtTestInf = {
  1874. (SDLTest_TestCaseFp) sqrt_infCase, "sqrt_infCase",
  1875. "Check positive infinity", TEST_ENABLED
  1876. };
  1877. static const SDLTest_TestCaseReference sqrtTestNan = {
  1878. (SDLTest_TestCaseFp) sqrt_nanCase, "sqrt_nanCase",
  1879. "Check the NaN special case", TEST_ENABLED
  1880. };
  1881. static const SDLTest_TestCaseReference sqrtTestDomain = {
  1882. (SDLTest_TestCaseFp) sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
  1883. "Check for out of domain values", TEST_ENABLED
  1884. };
  1885. static const SDLTest_TestCaseReference sqrtTestBase = {
  1886. (SDLTest_TestCaseFp) sqrt_baseCases, "sqrt_baseCases",
  1887. "Check the base cases", TEST_ENABLED
  1888. };
  1889. static const SDLTest_TestCaseReference sqrtTestRegular = {
  1890. (SDLTest_TestCaseFp) sqrt_regularCases, "sqrt_regularCases",
  1891. "Check a set of regular values", TEST_ENABLED
  1892. };
  1893. /* SDL_scalbn test cases */
  1894. static const SDLTest_TestCaseReference scalbnTestInf = {
  1895. (SDLTest_TestCaseFp) scalbn_infCases, "scalbn_infCases",
  1896. "Check positive and negative infinity arg", TEST_ENABLED
  1897. };
  1898. static const SDLTest_TestCaseReference scalbnTestBaseZero = {
  1899. (SDLTest_TestCaseFp) scalbn_baseZeroCases, "scalbn_baseZeroCases",
  1900. "Check for positive and negative zero arg", TEST_ENABLED
  1901. };
  1902. static const SDLTest_TestCaseReference scalbnTestExpZero = {
  1903. (SDLTest_TestCaseFp) scalbn_expZeroCase, "scalbn_expZeroCase",
  1904. "Check for zero exp", TEST_ENABLED
  1905. };
  1906. static const SDLTest_TestCaseReference scalbnTestNan = {
  1907. (SDLTest_TestCaseFp) scalbn_nanCase, "scalbn_nanCase",
  1908. "Check the NaN special case", TEST_ENABLED
  1909. };
  1910. static const SDLTest_TestCaseReference scalbnTestRegular = {
  1911. (SDLTest_TestCaseFp) scalbn_regularCases, "scalbn_regularCases",
  1912. "Check a set of regular cases", TEST_ENABLED
  1913. };
  1914. /* SDL_cos test cases */
  1915. static const SDLTest_TestCaseReference cosTestInf = {
  1916. (SDLTest_TestCaseFp) cos_infCases, "cos_infCases",
  1917. "Check for positive and negative infinity", TEST_ENABLED
  1918. };
  1919. static const SDLTest_TestCaseReference cosTestNan = {
  1920. (SDLTest_TestCaseFp) cos_nanCase, "cos_nanCase",
  1921. "Check the NaN special case", TEST_ENABLED
  1922. };
  1923. static const SDLTest_TestCaseReference cosTestRegular = {
  1924. (SDLTest_TestCaseFp) cos_regularCases, "cos_regularCases",
  1925. "Check a set of regular cases", TEST_ENABLED
  1926. };
  1927. static const SDLTest_TestCaseReference cosTestPrecision = {
  1928. (SDLTest_TestCaseFp) cos_precisionTest, "cos_precisionTest",
  1929. "Check cosine precision to the tenth decimal", TEST_ENABLED
  1930. };
  1931. static const SDLTest_TestCaseReference cosTestRange = {
  1932. (SDLTest_TestCaseFp) cos_rangeTest, "cos_rangeTest",
  1933. "Check a range of positive integer", TEST_ENABLED
  1934. };
  1935. static const SDLTest_TestCaseReference *mathTests[] = {
  1936. &floorTestInf, &floorTestZero, &floorTestNan,
  1937. &floorTestRound, &floorTestFraction, &floorTestRange,
  1938. &ceilTestInf, &ceilTestZero, &ceilTestNan,
  1939. &ceilTestRound, &ceilTestFraction, &ceilTestRange,
  1940. &truncTestInf, &truncTestZero, &truncTestNan,
  1941. &truncTestRound, &truncTestFraction, &truncTestRange,
  1942. &roundTestInf, &roundTestZero, &roundTestNan,
  1943. &roundTestRound, &roundTestFraction, &roundTestRange,
  1944. &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
  1945. &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
  1946. &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
  1947. &fmodTestNan, &fmodTestRegular, &fmodTestRange,
  1948. &expTestInf, &expTestZero, &expTestOverflow,
  1949. &expTestBase, &expTestRegular,
  1950. &logTestLimit, &logTestNan,
  1951. &logTestBase, &logTestRegular,
  1952. &log10TestLimit, &log10TestNan,
  1953. &log10TestBase, &log10TestRegular,
  1954. &powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
  1955. &powTestBaseInf1, &powTestBaseInf2,
  1956. &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
  1957. &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
  1958. &powTestRegular, &powTestPowOf2, &powTestRange,
  1959. &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
  1960. &sqrtTestBase, &sqrtTestRegular,
  1961. &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
  1962. &scalbnTestNan, &scalbnTestRegular,
  1963. &cosTestInf, &cosTestNan, &cosTestRegular,
  1964. &cosTestPrecision, &cosTestRange,
  1965. NULL
  1966. };
  1967. SDLTest_TestSuiteReference mathTestSuite = { "Math", NULL, mathTests, NULL };