testautomation_math.c 61 KB

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