testautomation_math.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273
  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. static int
  1538. cos_precisionTest(void *args)
  1539. {
  1540. Uint32 i;
  1541. Uint32 iterations = 20;
  1542. double angle = 0.0;
  1543. double step = 2.0 * M_PI / iterations;
  1544. const Sint64 expected[] = {
  1545. 10000000000, 9510565162, 8090169943, 5877852522, 3090169943,
  1546. 0, -3090169943, -5877852522, -8090169943, -9510565162,
  1547. -10000000000, -9510565162, -8090169943, -5877852522, -3090169943,
  1548. 0, 3090169943, 5877852522, 8090169943, 9510565162
  1549. };
  1550. for (i = 0; i < iterations; i++, angle += step) {
  1551. Sint64 result = (Sint64) (SDL_cos(angle) * 10000000000);
  1552. SDLTest_AssertCheck(result == expected[i],
  1553. "Cos(%f), expected %lld, got %lld",
  1554. angle, expected[i], result);
  1555. }
  1556. return TEST_COMPLETED;
  1557. }
  1558. /**
  1559. * \brief Checks a range of values between 0 and UINT32_MAX.
  1560. */
  1561. static int
  1562. cos_rangeTest(void *args)
  1563. {
  1564. Uint32 i;
  1565. double test_value = 0.0;
  1566. SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %u",
  1567. RANGE_TEST_ITERATIONS,
  1568. RANGE_TEST_STEP);
  1569. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1570. double result;
  1571. /* These are tested elsewhere */
  1572. if (isnan(test_value) || isinf(test_value)) {
  1573. continue;
  1574. }
  1575. /* Only log failures to save performances */
  1576. result = SDL_cos(test_value);
  1577. if (result < -1.0 || result > 1.0) {
  1578. SDLTest_AssertCheck(SDL_FALSE,
  1579. "Cos(%.1f), expected [%.1f,%.1f], got %.1f",
  1580. test_value, -1.0, 1.0, result);
  1581. return TEST_ABORTED;
  1582. }
  1583. }
  1584. return TEST_COMPLETED;
  1585. }
  1586. /* ================= Test References ================== */
  1587. /* SDL_floor test cases */
  1588. static const SDLTest_TestCaseReference floorTestInf = {
  1589. (SDLTest_TestCaseFp) floor_infCases, "floor_infCases",
  1590. "Check positive and negative infinity", TEST_ENABLED
  1591. };
  1592. static const SDLTest_TestCaseReference floorTestZero = {
  1593. (SDLTest_TestCaseFp) floor_zeroCases, "floor_zeroCases",
  1594. "Check positive and negative zero", TEST_ENABLED
  1595. };
  1596. static const SDLTest_TestCaseReference floorTestNan = {
  1597. (SDLTest_TestCaseFp) floor_nanCase, "floor_nanCase",
  1598. "Check the NaN special case", TEST_ENABLED
  1599. };
  1600. static const SDLTest_TestCaseReference floorTestRound = {
  1601. (SDLTest_TestCaseFp) floor_roundNumbersCases, "floor_roundNumberCases",
  1602. "Check a set of round numbers", TEST_ENABLED
  1603. };
  1604. static const SDLTest_TestCaseReference floorTestFraction = {
  1605. (SDLTest_TestCaseFp) floor_fractionCases, "floor_fractionCases",
  1606. "Check a set of fractions", TEST_ENABLED
  1607. };
  1608. static const SDLTest_TestCaseReference floorTestRange = {
  1609. (SDLTest_TestCaseFp) floor_rangeTest, "floor_rangeTest",
  1610. "Check a range of positive integer", TEST_ENABLED
  1611. };
  1612. /* SDL_ceil test cases */
  1613. static const SDLTest_TestCaseReference ceilTestInf = {
  1614. (SDLTest_TestCaseFp) ceil_infCases, "ceil_infCases",
  1615. "Check positive and negative infinity", TEST_ENABLED
  1616. };
  1617. static const SDLTest_TestCaseReference ceilTestZero = {
  1618. (SDLTest_TestCaseFp) ceil_zeroCases, "ceil_zeroCases",
  1619. "Check positive and negative zero", TEST_ENABLED
  1620. };
  1621. static const SDLTest_TestCaseReference ceilTestNan = {
  1622. (SDLTest_TestCaseFp) ceil_nanCase, "ceil_nanCase",
  1623. "Check the NaN special case", TEST_ENABLED
  1624. };
  1625. static const SDLTest_TestCaseReference ceilTestRound = {
  1626. (SDLTest_TestCaseFp) ceil_roundNumbersCases, "ceil_roundNumberCases",
  1627. "Check a set of round numbers", TEST_ENABLED
  1628. };
  1629. static const SDLTest_TestCaseReference ceilTestFraction = {
  1630. (SDLTest_TestCaseFp) ceil_fractionCases, "ceil_fractionCases",
  1631. "Check a set of fractions", TEST_ENABLED
  1632. };
  1633. static const SDLTest_TestCaseReference ceilTestRange = {
  1634. (SDLTest_TestCaseFp) ceil_rangeTest, "ceil_rangeTest",
  1635. "Check a range of positive integer", TEST_ENABLED
  1636. };
  1637. /* SDL_trunc test cases */
  1638. static const SDLTest_TestCaseReference truncTestInf = {
  1639. (SDLTest_TestCaseFp) trunc_infCases, "trunc_infCases",
  1640. "Check positive and negative infinity", TEST_ENABLED
  1641. };
  1642. static const SDLTest_TestCaseReference truncTestZero = {
  1643. (SDLTest_TestCaseFp) trunc_zeroCases, "trunc_zeroCases",
  1644. "Check positive and negative zero", TEST_ENABLED
  1645. };
  1646. static const SDLTest_TestCaseReference truncTestNan = {
  1647. (SDLTest_TestCaseFp) trunc_nanCase, "trunc_nanCase",
  1648. "Check the NaN special case", TEST_ENABLED
  1649. };
  1650. static const SDLTest_TestCaseReference truncTestRound = {
  1651. (SDLTest_TestCaseFp) trunc_roundNumbersCases, "trunc_roundNumberCases",
  1652. "Check a set of round numbers", TEST_ENABLED
  1653. };
  1654. static const SDLTest_TestCaseReference truncTestFraction = {
  1655. (SDLTest_TestCaseFp) trunc_fractionCases, "trunc_fractionCases",
  1656. "Check a set of fractions", TEST_ENABLED
  1657. };
  1658. static const SDLTest_TestCaseReference truncTestRange = {
  1659. (SDLTest_TestCaseFp) trunc_rangeTest, "trunc_rangeTest",
  1660. "Check a range of positive integer", TEST_ENABLED
  1661. };
  1662. /* SDL_round test cases */
  1663. static const SDLTest_TestCaseReference roundTestInf = {
  1664. (SDLTest_TestCaseFp) round_infCases, "round_infCases",
  1665. "Check positive and negative infinity", TEST_ENABLED
  1666. };
  1667. static const SDLTest_TestCaseReference roundTestZero = {
  1668. (SDLTest_TestCaseFp) round_zeroCases, "round_zeroCases",
  1669. "Check positive and negative zero", TEST_ENABLED
  1670. };
  1671. static const SDLTest_TestCaseReference roundTestNan = {
  1672. (SDLTest_TestCaseFp) round_nanCase, "round_nanCase",
  1673. "Check the NaN special case", TEST_ENABLED
  1674. };
  1675. static const SDLTest_TestCaseReference roundTestRound = {
  1676. (SDLTest_TestCaseFp) round_roundNumbersCases, "round_roundNumberCases",
  1677. "Check a set of round numbers", TEST_ENABLED
  1678. };
  1679. static const SDLTest_TestCaseReference roundTestFraction = {
  1680. (SDLTest_TestCaseFp) round_fractionCases, "round_fractionCases",
  1681. "Check a set of fractions", TEST_ENABLED
  1682. };
  1683. static const SDLTest_TestCaseReference roundTestRange = {
  1684. (SDLTest_TestCaseFp) round_rangeTest, "round_rangeTest",
  1685. "Check a range of positive integer", TEST_ENABLED
  1686. };
  1687. /* SDL_fabs test cases */
  1688. static const SDLTest_TestCaseReference fabsTestInf = {
  1689. (SDLTest_TestCaseFp) fabs_infCases, "fabs_infCases",
  1690. "Check positive and negative infinity", TEST_ENABLED
  1691. };
  1692. static const SDLTest_TestCaseReference fabsTestZero = {
  1693. (SDLTest_TestCaseFp) fabs_zeroCases, "fabs_zeroCases",
  1694. "Check positive and negative zero", TEST_ENABLED
  1695. };
  1696. static const SDLTest_TestCaseReference fabsTestNan = {
  1697. (SDLTest_TestCaseFp) fabs_nanCase, "fabs_nanCase",
  1698. "Check the NaN special case", TEST_ENABLED
  1699. };
  1700. static const SDLTest_TestCaseReference fabsTestRange = {
  1701. (SDLTest_TestCaseFp) fabs_rangeTest, "fabs_rangeTest",
  1702. "Check a range of positive integer", TEST_ENABLED
  1703. };
  1704. /* SDL_copysign test cases */
  1705. static const SDLTest_TestCaseReference copysignTestInf = {
  1706. (SDLTest_TestCaseFp) copysign_infCases, "copysign_infCases",
  1707. "Check positive and negative infinity", TEST_ENABLED
  1708. };
  1709. static const SDLTest_TestCaseReference copysignTestZero = {
  1710. (SDLTest_TestCaseFp) copysign_zeroCases, "copysign_zeroCases",
  1711. "Check positive and negative zero", TEST_ENABLED
  1712. };
  1713. static const SDLTest_TestCaseReference copysignTestNan = {
  1714. (SDLTest_TestCaseFp) copysign_nanCases, "copysign_nanCases",
  1715. "Check the NaN special cases", TEST_ENABLED
  1716. };
  1717. static const SDLTest_TestCaseReference copysignTestRange = {
  1718. (SDLTest_TestCaseFp) copysign_rangeTest, "copysign_rangeTest",
  1719. "Check a range of positive integer", TEST_ENABLED
  1720. };
  1721. /* SDL_fmod test cases */
  1722. static const SDLTest_TestCaseReference fmodTestDivOfInf = {
  1723. (SDLTest_TestCaseFp) fmod_divOfInfCases, "fmod_divOfInfCases",
  1724. "Check division of positive and negative infinity", TEST_ENABLED
  1725. };
  1726. static const SDLTest_TestCaseReference fmodTestDivByInf = {
  1727. (SDLTest_TestCaseFp) fmod_divByInfCases, "fmod_divByInfCases",
  1728. "Check division by positive and negative infinity", TEST_ENABLED
  1729. };
  1730. static const SDLTest_TestCaseReference fmodTestDivOfZero = {
  1731. (SDLTest_TestCaseFp) fmod_divOfZeroCases, "fmod_divOfZeroCases",
  1732. "Check division of positive and negative zero", TEST_ENABLED
  1733. };
  1734. static const SDLTest_TestCaseReference fmodTestDivByZero = {
  1735. (SDLTest_TestCaseFp) fmod_divByZeroCases, "fmod_divByZeroCases",
  1736. "Check division by positive and negative zero", TEST_ENABLED
  1737. };
  1738. static const SDLTest_TestCaseReference fmodTestNan = {
  1739. (SDLTest_TestCaseFp) fmod_nanCases, "fmod_nanCases",
  1740. "Check the NaN special cases", TEST_ENABLED
  1741. };
  1742. static const SDLTest_TestCaseReference fmodTestRegular = {
  1743. (SDLTest_TestCaseFp) fmod_regularCases, "fmod_regularCases",
  1744. "Check a set of regular values", TEST_ENABLED
  1745. };
  1746. static const SDLTest_TestCaseReference fmodTestRange = {
  1747. (SDLTest_TestCaseFp) fmod_rangeTest, "fmod_rangeTest",
  1748. "Check a range of positive integer", TEST_ENABLED
  1749. };
  1750. /* SDL_exp test cases */
  1751. static const SDLTest_TestCaseReference expTestInf = {
  1752. (SDLTest_TestCaseFp) exp_infCases, "exp_infCases",
  1753. "Check positive and negative infinity", TEST_ENABLED
  1754. };
  1755. static const SDLTest_TestCaseReference expTestZero = {
  1756. (SDLTest_TestCaseFp) exp_zeroCases, "exp_zeroCases",
  1757. "Check for positive and negative zero", TEST_ENABLED
  1758. };
  1759. static const SDLTest_TestCaseReference expTestOverflow = {
  1760. (SDLTest_TestCaseFp) exp_overflowCase, "exp_overflowCase",
  1761. "Check for overflow", TEST_ENABLED
  1762. };
  1763. static const SDLTest_TestCaseReference expTestBase = {
  1764. (SDLTest_TestCaseFp) exp_baseCase, "exp_baseCase",
  1765. "Check the base case of 1.0", TEST_ENABLED
  1766. };
  1767. static const SDLTest_TestCaseReference expTestRegular = {
  1768. (SDLTest_TestCaseFp) exp_regularCases, "exp_regularCases",
  1769. "Check a set of regular values", TEST_ENABLED
  1770. };
  1771. /* SDL_log test cases */
  1772. static const SDLTest_TestCaseReference logTestLimit = {
  1773. (SDLTest_TestCaseFp) log_limitCases, "log_limitCases",
  1774. "Check for limits", TEST_ENABLED
  1775. };
  1776. static const SDLTest_TestCaseReference logTestNan = {
  1777. (SDLTest_TestCaseFp) log_nanCases, "log_nanCases",
  1778. "Check for the nan cases", TEST_ENABLED
  1779. };
  1780. static const SDLTest_TestCaseReference logTestBase = {
  1781. (SDLTest_TestCaseFp) log_baseCases, "log_baseCases",
  1782. "Check for base cases", TEST_ENABLED
  1783. };
  1784. static const SDLTest_TestCaseReference logTestRegular = {
  1785. (SDLTest_TestCaseFp) log_regularCases, "log_regularCases",
  1786. "Check a set of regular values", TEST_ENABLED
  1787. };
  1788. /* SDL_log10 test cases */
  1789. static const SDLTest_TestCaseReference log10TestLimit = {
  1790. (SDLTest_TestCaseFp) log10_limitCases, "log10_limitCases",
  1791. "Check for limits", TEST_ENABLED
  1792. };
  1793. static const SDLTest_TestCaseReference log10TestNan = {
  1794. (SDLTest_TestCaseFp) log10_nanCases, "log10_nanCases",
  1795. "Check for the nan cases", TEST_ENABLED
  1796. };
  1797. static const SDLTest_TestCaseReference log10TestBase = {
  1798. (SDLTest_TestCaseFp) log10_baseCases, "log10_baseCases",
  1799. "Check for base cases", TEST_ENABLED
  1800. };
  1801. static const SDLTest_TestCaseReference log10TestRegular = {
  1802. (SDLTest_TestCaseFp) log10_regularCases, "log10_regularCases",
  1803. "Check a set of regular values", TEST_ENABLED
  1804. };
  1805. /* SDL_pow test cases */
  1806. static const SDLTest_TestCaseReference powTestExpInf1 = {
  1807. (SDLTest_TestCaseFp) pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
  1808. "Check for pow(-1, +/-inf)", TEST_ENABLED
  1809. };
  1810. static const SDLTest_TestCaseReference powTestExpInf2 = {
  1811. (SDLTest_TestCaseFp) pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
  1812. "Check for pow(+/-0, -inf)", TEST_ENABLED
  1813. };
  1814. static const SDLTest_TestCaseReference powTestExpInf3 = {
  1815. (SDLTest_TestCaseFp) pow_expInfCases, "pow_expInfCases",
  1816. "Check for pow(x, +/-inf)", TEST_ENABLED
  1817. };
  1818. static const SDLTest_TestCaseReference powTestBaseInf1 = {
  1819. (SDLTest_TestCaseFp) pow_basePInfCases, "pow_basePInfCases",
  1820. "Check for pow(inf, x)", TEST_ENABLED
  1821. };
  1822. static const SDLTest_TestCaseReference powTestBaseInf2 = {
  1823. (SDLTest_TestCaseFp) pow_baseNInfCases, "pow_baseNInfCases",
  1824. "Check for pow(-inf, x)", TEST_ENABLED
  1825. };
  1826. static const SDLTest_TestCaseReference powTestNan1 = {
  1827. (SDLTest_TestCaseFp) pow_badOperationCase, "pow_badOperationCase",
  1828. "Check for negative finite base and non-integer finite exponent", TEST_ENABLED
  1829. };
  1830. static const SDLTest_TestCaseReference powTestNan2 = {
  1831. (SDLTest_TestCaseFp) pow_base1ExpNanCase, "pow_base1ExpNanCase",
  1832. "Check for pow(1.0, nan)", TEST_ENABLED
  1833. };
  1834. static const SDLTest_TestCaseReference powTestNan3 = {
  1835. (SDLTest_TestCaseFp) pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
  1836. "Check for pow(nan, +/-0)", TEST_ENABLED
  1837. };
  1838. static const SDLTest_TestCaseReference powTestNan4 = {
  1839. (SDLTest_TestCaseFp) pow_nanArgsCases, "pow_nanArgsCases",
  1840. "Check for pow(x, y) with either x or y being nan", TEST_ENABLED
  1841. };
  1842. static const SDLTest_TestCaseReference powTestZero1 = {
  1843. (SDLTest_TestCaseFp) pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
  1844. "Check for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
  1845. };
  1846. static const SDLTest_TestCaseReference powTestZero2 = {
  1847. (SDLTest_TestCaseFp) pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
  1848. "Check for pow(0.0, y), with y an odd integer.", TEST_ENABLED
  1849. };
  1850. static const SDLTest_TestCaseReference powTestZero3 = {
  1851. (SDLTest_TestCaseFp) pow_baseNZeroCases, "pow_baseNZeroCases",
  1852. "Check for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  1853. };
  1854. static const SDLTest_TestCaseReference powTestZero4 = {
  1855. (SDLTest_TestCaseFp) pow_basePZeroCases, "pow_basePZeroCases",
  1856. "Check for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  1857. };
  1858. static const SDLTest_TestCaseReference powTestRegular = {
  1859. (SDLTest_TestCaseFp) pow_regularCases, "pow_regularCases",
  1860. "Check a set of regular values", TEST_ENABLED
  1861. };
  1862. static const SDLTest_TestCaseReference powTestPowOf2 = {
  1863. (SDLTest_TestCaseFp) pow_powerOfTwo, "pow_powerOfTwo",
  1864. "Check the powers of two from 1 to 8", TEST_ENABLED
  1865. };
  1866. static const SDLTest_TestCaseReference powTestRange = {
  1867. (SDLTest_TestCaseFp) pow_rangeTest, "pow_rangeTest",
  1868. "Check a range of positive integer to the power of 0", TEST_ENABLED
  1869. };
  1870. /* SDL_sqrt test cases */
  1871. static const SDLTest_TestCaseReference sqrtTestInf = {
  1872. (SDLTest_TestCaseFp) sqrt_infCase, "sqrt_infCase",
  1873. "Check positive infinity", TEST_ENABLED
  1874. };
  1875. static const SDLTest_TestCaseReference sqrtTestNan = {
  1876. (SDLTest_TestCaseFp) sqrt_nanCase, "sqrt_nanCase",
  1877. "Check the NaN special case", TEST_ENABLED
  1878. };
  1879. static const SDLTest_TestCaseReference sqrtTestDomain = {
  1880. (SDLTest_TestCaseFp) sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
  1881. "Check for out of domain values", TEST_ENABLED
  1882. };
  1883. static const SDLTest_TestCaseReference sqrtTestBase = {
  1884. (SDLTest_TestCaseFp) sqrt_baseCases, "sqrt_baseCases",
  1885. "Check the base cases", TEST_ENABLED
  1886. };
  1887. static const SDLTest_TestCaseReference sqrtTestRegular = {
  1888. (SDLTest_TestCaseFp) sqrt_regularCases, "sqrt_regularCases",
  1889. "Check a set of regular values", TEST_ENABLED
  1890. };
  1891. /* SDL_scalbn test cases */
  1892. static const SDLTest_TestCaseReference scalbnTestInf = {
  1893. (SDLTest_TestCaseFp) scalbn_infCases, "scalbn_infCases",
  1894. "Check positive and negative infinity arg", TEST_ENABLED
  1895. };
  1896. static const SDLTest_TestCaseReference scalbnTestBaseZero = {
  1897. (SDLTest_TestCaseFp) scalbn_baseZeroCases, "scalbn_baseZeroCases",
  1898. "Check for positive and negative zero arg", TEST_ENABLED
  1899. };
  1900. static const SDLTest_TestCaseReference scalbnTestExpZero = {
  1901. (SDLTest_TestCaseFp) scalbn_expZeroCase, "scalbn_expZeroCase",
  1902. "Check for zero exp", TEST_ENABLED
  1903. };
  1904. static const SDLTest_TestCaseReference scalbnTestNan = {
  1905. (SDLTest_TestCaseFp) scalbn_nanCase, "scalbn_nanCase",
  1906. "Check the NaN special case", TEST_ENABLED
  1907. };
  1908. static const SDLTest_TestCaseReference scalbnTestRegular = {
  1909. (SDLTest_TestCaseFp) scalbn_regularCases, "scalbn_regularCases",
  1910. "Check a set of regular cases", TEST_ENABLED
  1911. };
  1912. /* SDL_cos test cases */
  1913. static const SDLTest_TestCaseReference cosTestInf = {
  1914. (SDLTest_TestCaseFp) cos_infCases, "cos_infCases",
  1915. "Check for positive and negative infinity", TEST_ENABLED
  1916. };
  1917. static const SDLTest_TestCaseReference cosTestNan = {
  1918. (SDLTest_TestCaseFp) cos_nanCase, "cos_nanCase",
  1919. "Check the NaN special case", TEST_ENABLED
  1920. };
  1921. static const SDLTest_TestCaseReference cosTestRegular = {
  1922. (SDLTest_TestCaseFp) cos_regularCases, "cos_regularCases",
  1923. "Check a set of regular cases", TEST_ENABLED
  1924. };
  1925. static const SDLTest_TestCaseReference cosTestPrecision = {
  1926. (SDLTest_TestCaseFp) cos_precisionTest, "cos_precisionTest",
  1927. "Check cosine precision to the tenth decimal", TEST_ENABLED
  1928. };
  1929. static const SDLTest_TestCaseReference cosTestRange = {
  1930. (SDLTest_TestCaseFp) cos_rangeTest, "cos_rangeTest",
  1931. "Check a range of positive integer", TEST_ENABLED
  1932. };
  1933. static const SDLTest_TestCaseReference *mathTests[] = {
  1934. &floorTestInf, &floorTestZero, &floorTestNan,
  1935. &floorTestRound, &floorTestFraction, &floorTestRange,
  1936. &ceilTestInf, &ceilTestZero, &ceilTestNan,
  1937. &ceilTestRound, &ceilTestFraction, &ceilTestRange,
  1938. &truncTestInf, &truncTestZero, &truncTestNan,
  1939. &truncTestRound, &truncTestFraction, &truncTestRange,
  1940. &roundTestInf, &roundTestZero, &roundTestNan,
  1941. &roundTestRound, &roundTestFraction, &roundTestRange,
  1942. &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
  1943. &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
  1944. &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
  1945. &fmodTestNan, &fmodTestRegular, &fmodTestRange,
  1946. &expTestInf, &expTestZero, &expTestOverflow,
  1947. &expTestBase, &expTestRegular,
  1948. &logTestLimit, &logTestNan,
  1949. &logTestBase, &logTestRegular,
  1950. &log10TestLimit, &log10TestNan,
  1951. &log10TestBase, &log10TestRegular,
  1952. &powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
  1953. &powTestBaseInf1, &powTestBaseInf2,
  1954. &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
  1955. &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
  1956. &powTestRegular, &powTestPowOf2, &powTestRange,
  1957. &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
  1958. &sqrtTestBase, &sqrtTestRegular,
  1959. &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
  1960. &scalbnTestNan, &scalbnTestRegular,
  1961. &cosTestInf, &cosTestNan, &cosTestRegular,
  1962. &cosTestPrecision, &cosTestRange,
  1963. NULL
  1964. };
  1965. SDLTest_TestSuiteReference mathTestSuite = { "Math", NULL, mathTests, NULL };