testautomation_math.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501
  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. 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. /* SDL_cos tests functions */
  1490. /**
  1491. * \brief Checks positive and negative infinity.
  1492. */
  1493. static int
  1494. cos_infCases(void *args)
  1495. {
  1496. double result;
  1497. result = SDL_cos(INFINITY);
  1498. SDLTest_AssertCheck(isnan(result),
  1499. "Cos(%f), expected %f, got %f",
  1500. INFINITY, NAN, result);
  1501. result = SDL_cos(-INFINITY);
  1502. SDLTest_AssertCheck(isnan(result),
  1503. "Cos(%f), expected %f, got %f",
  1504. -INFINITY, NAN, result);
  1505. return TEST_COMPLETED;
  1506. }
  1507. /**
  1508. * \brief Checks for nan.
  1509. */
  1510. static int
  1511. cos_nanCase(void *args)
  1512. {
  1513. const double result = SDL_cos(NAN);
  1514. SDLTest_AssertCheck(isnan(result),
  1515. "Cos(%f), expected %f, got %f",
  1516. NAN, NAN, result);
  1517. return TEST_COMPLETED;
  1518. }
  1519. /**
  1520. * \brief Checks a set of regular values.
  1521. */
  1522. static int
  1523. cos_regularCases(void *args)
  1524. {
  1525. const d_to_d regular_cases[] = {
  1526. { -M_PI, -1.0 },
  1527. { -0.0, 1.0 },
  1528. { 0.0, 1.0 },
  1529. { M_PI, -1.0 }
  1530. };
  1531. return helper_dtod("Cos", SDL_cos, regular_cases, SDL_arraysize(regular_cases));
  1532. }
  1533. /**
  1534. * \brief Checks cosine precision for the first 10 decimals.
  1535. *
  1536. * This function depends on SDL_floor functioning.
  1537. */
  1538. static int
  1539. cos_precisionTest(void *args)
  1540. {
  1541. Uint32 i;
  1542. Uint32 iterations = 20;
  1543. double angle = 0.0;
  1544. double step = 2.0 * M_PI / iterations;
  1545. const double expected[] = {
  1546. 10000000000.0, 9510565162.0, 8090169943.0, 5877852522.0, 3090169943.0,
  1547. 0.0, -3090169943.0, -5877852522.0, -8090169943.0, -9510565162.0,
  1548. -10000000000.0, -9510565162.0, -8090169943.0, -5877852522.0, -3090169943.0,
  1549. 0.0, 3090169943.0, 5877852522.0, 8090169943.0, 9510565162.0
  1550. };
  1551. for (i = 0; i < iterations; i++, angle += step) {
  1552. double result = SDL_cos(angle) * 1.0E10;
  1553. SDLTest_AssertCheck(SDL_trunc(result) == expected[i],
  1554. "Cos(%f), expected %f, got %f",
  1555. angle, expected[i], result);
  1556. }
  1557. return TEST_COMPLETED;
  1558. }
  1559. /**
  1560. * \brief Checks a range of values between 0 and UINT32_MAX.
  1561. */
  1562. static int
  1563. cos_rangeTest(void *args)
  1564. {
  1565. Uint32 i;
  1566. double test_value = 0.0;
  1567. SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %u",
  1568. RANGE_TEST_ITERATIONS,
  1569. RANGE_TEST_STEP);
  1570. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1571. double result;
  1572. /* These are tested elsewhere */
  1573. if (isnan(test_value) || isinf(test_value)) {
  1574. continue;
  1575. }
  1576. /* Only log failures to save performances */
  1577. result = SDL_cos(test_value);
  1578. if (result < -1.0 || result > 1.0) {
  1579. SDLTest_AssertCheck(SDL_FALSE,
  1580. "Cos(%.1f), expected [%.1f,%.1f], got %.1f",
  1581. test_value, -1.0, 1.0, result);
  1582. return TEST_ABORTED;
  1583. }
  1584. }
  1585. return TEST_COMPLETED;
  1586. }
  1587. /* SDL_sin tests functions */
  1588. /**
  1589. * \brief Checks positive and negative infinity.
  1590. */
  1591. static int
  1592. sin_infCases(void *args)
  1593. {
  1594. double result;
  1595. result = SDL_sin(INFINITY);
  1596. SDLTest_AssertCheck(isnan(result),
  1597. "Sin(%f), expected %f, got %f",
  1598. INFINITY, NAN, result);
  1599. result = SDL_sin(-INFINITY);
  1600. SDLTest_AssertCheck(isnan(result),
  1601. "Sin(%f), expected %f, got %f",
  1602. -INFINITY, NAN, result);
  1603. return TEST_COMPLETED;
  1604. }
  1605. /**
  1606. * \brief Checks for nan.
  1607. */
  1608. static int
  1609. sin_nanCase(void *args)
  1610. {
  1611. const double result = SDL_sin(NAN);
  1612. SDLTest_AssertCheck(isnan(result),
  1613. "Sin(%f), expected %f, got %f",
  1614. NAN, NAN, result);
  1615. return TEST_COMPLETED;
  1616. }
  1617. /**
  1618. * \brief Checks a set of regular values.
  1619. */
  1620. static int
  1621. sin_regularCases(void *args)
  1622. {
  1623. const d_to_d regular_cases[] = {
  1624. { -M_PI / 2, -1.0 },
  1625. { -0.0, -0.0 },
  1626. { 0.0, 0.0 },
  1627. { M_PI / 2, 1.0 }
  1628. };
  1629. return helper_dtod("Sin", SDL_sin, regular_cases, SDL_arraysize(regular_cases));
  1630. }
  1631. /**
  1632. * \brief Checks sine precision for the first 10 decimals.
  1633. */
  1634. static int
  1635. sin_precisionTest(void *args)
  1636. {
  1637. Uint32 i;
  1638. Uint32 iterations = 20;
  1639. double angle = 0.0;
  1640. double step = 2.0 * M_PI / iterations;
  1641. const double expected[] = {
  1642. 0, 3090169943, 5877852522, 8090169943, 9510565162,
  1643. 10000000000, 9510565162, 8090169943, 5877852522, 3090169943,
  1644. 0, -3090169943, -5877852522, -8090169943, -9510565162,
  1645. -10000000000, -9510565162, -8090169943, -5877852522, -3090169943
  1646. };
  1647. for (i = 0; i < iterations; i++, angle += step) {
  1648. double result = SDL_sin(angle) * 1.0E10;
  1649. SDLTest_AssertCheck(SDL_trunc(result) == expected[i],
  1650. "Sin(%f), expected %f, got %f",
  1651. angle, expected[i], result);
  1652. }
  1653. return TEST_COMPLETED;
  1654. }
  1655. /**
  1656. * \brief Checks a range of values between 0 and UINT32_MAX.
  1657. */
  1658. static int
  1659. sin_rangeTest(void *args)
  1660. {
  1661. Uint32 i;
  1662. double test_value = 0.0;
  1663. SDLTest_AssertPass("Sin: Testing a range of %u values with steps of %u",
  1664. RANGE_TEST_ITERATIONS,
  1665. RANGE_TEST_STEP);
  1666. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1667. double result;
  1668. /* These are tested elsewhere */
  1669. if (isnan(test_value) || isinf(test_value)) {
  1670. continue;
  1671. }
  1672. /* Only log failures to save performances */
  1673. result = SDL_sin(test_value);
  1674. if (result < -1.0 || result > 1.0) {
  1675. SDLTest_AssertCheck(SDL_FALSE,
  1676. "Sin(%.1f), expected [%.1f,%.1f], got %.1f",
  1677. test_value, -1.0, 1.0, result);
  1678. return TEST_ABORTED;
  1679. }
  1680. }
  1681. return TEST_COMPLETED;
  1682. }
  1683. /* SDL_tan tests functions */
  1684. /**
  1685. * \brief Checks positive and negative infinity.
  1686. */
  1687. static int
  1688. tan_infCases(void *args)
  1689. {
  1690. double result;
  1691. result = SDL_tan(INFINITY);
  1692. SDLTest_AssertCheck(isnan(result),
  1693. "Tan(%f), expected %f, got %f",
  1694. INFINITY, NAN, result);
  1695. result = SDL_tan(-INFINITY);
  1696. SDLTest_AssertCheck(isnan(result),
  1697. "Tan(%f), expected %f, got %f",
  1698. -INFINITY, NAN, result);
  1699. return TEST_COMPLETED;
  1700. }
  1701. /**
  1702. * \brief Checks for nan.
  1703. */
  1704. static int
  1705. tan_nanCase(void *args)
  1706. {
  1707. const double result = SDL_tan(NAN);
  1708. SDLTest_AssertCheck(isnan(result),
  1709. "Tan(%f), expected %f, got %f",
  1710. NAN, NAN, result);
  1711. return TEST_COMPLETED;
  1712. }
  1713. /**
  1714. * \brief Checks positive and negative zero.
  1715. */
  1716. static int
  1717. tan_zeroCases(void *args)
  1718. {
  1719. const d_to_d regular_cases[] = {
  1720. { -0.0, -0.0 },
  1721. { 0.0, 0.0 }
  1722. };
  1723. return helper_dtod("Tan", SDL_tan, regular_cases, SDL_arraysize(regular_cases));
  1724. }
  1725. /**
  1726. * \brief Checks tangent precision for the first 10 decimals.
  1727. */
  1728. static int
  1729. tan_precisionTest(void *args)
  1730. {
  1731. Uint32 i;
  1732. Uint32 iterations = 10;
  1733. double angle = 0.0;
  1734. double step = 2.0 * M_PI / iterations;
  1735. const double expected[] = {
  1736. 0.0, 7265425280.0, 30776835371.0, -30776835371.0, -7265425280.0,
  1737. -0.0, 7265425280.0, 30776835371.0, -30776835371.0, -7265425280.0
  1738. };
  1739. for (i = 0; i < iterations; i++, angle += step) {
  1740. double result = SDL_tan(angle) * 1.0E10;
  1741. SDLTest_AssertCheck(SDL_trunc(result) == expected[i],
  1742. "Tan(%f), expected %f, got %f",
  1743. angle, expected[i], result);
  1744. }
  1745. return TEST_COMPLETED;
  1746. }
  1747. /* ================= Test References ================== */
  1748. /* SDL_floor test cases */
  1749. static const SDLTest_TestCaseReference floorTestInf = {
  1750. (SDLTest_TestCaseFp) floor_infCases, "floor_infCases",
  1751. "Check positive and negative infinity", TEST_ENABLED
  1752. };
  1753. static const SDLTest_TestCaseReference floorTestZero = {
  1754. (SDLTest_TestCaseFp) floor_zeroCases, "floor_zeroCases",
  1755. "Check positive and negative zero", TEST_ENABLED
  1756. };
  1757. static const SDLTest_TestCaseReference floorTestNan = {
  1758. (SDLTest_TestCaseFp) floor_nanCase, "floor_nanCase",
  1759. "Check the NaN special case", TEST_ENABLED
  1760. };
  1761. static const SDLTest_TestCaseReference floorTestRound = {
  1762. (SDLTest_TestCaseFp) floor_roundNumbersCases, "floor_roundNumberCases",
  1763. "Check a set of round numbers", TEST_ENABLED
  1764. };
  1765. static const SDLTest_TestCaseReference floorTestFraction = {
  1766. (SDLTest_TestCaseFp) floor_fractionCases, "floor_fractionCases",
  1767. "Check a set of fractions", TEST_ENABLED
  1768. };
  1769. static const SDLTest_TestCaseReference floorTestRange = {
  1770. (SDLTest_TestCaseFp) floor_rangeTest, "floor_rangeTest",
  1771. "Check a range of positive integer", TEST_ENABLED
  1772. };
  1773. /* SDL_ceil test cases */
  1774. static const SDLTest_TestCaseReference ceilTestInf = {
  1775. (SDLTest_TestCaseFp) ceil_infCases, "ceil_infCases",
  1776. "Check positive and negative infinity", TEST_ENABLED
  1777. };
  1778. static const SDLTest_TestCaseReference ceilTestZero = {
  1779. (SDLTest_TestCaseFp) ceil_zeroCases, "ceil_zeroCases",
  1780. "Check positive and negative zero", TEST_ENABLED
  1781. };
  1782. static const SDLTest_TestCaseReference ceilTestNan = {
  1783. (SDLTest_TestCaseFp) ceil_nanCase, "ceil_nanCase",
  1784. "Check the NaN special case", TEST_ENABLED
  1785. };
  1786. static const SDLTest_TestCaseReference ceilTestRound = {
  1787. (SDLTest_TestCaseFp) ceil_roundNumbersCases, "ceil_roundNumberCases",
  1788. "Check a set of round numbers", TEST_ENABLED
  1789. };
  1790. static const SDLTest_TestCaseReference ceilTestFraction = {
  1791. (SDLTest_TestCaseFp) ceil_fractionCases, "ceil_fractionCases",
  1792. "Check a set of fractions", TEST_ENABLED
  1793. };
  1794. static const SDLTest_TestCaseReference ceilTestRange = {
  1795. (SDLTest_TestCaseFp) ceil_rangeTest, "ceil_rangeTest",
  1796. "Check a range of positive integer", TEST_ENABLED
  1797. };
  1798. /* SDL_trunc test cases */
  1799. static const SDLTest_TestCaseReference truncTestInf = {
  1800. (SDLTest_TestCaseFp) trunc_infCases, "trunc_infCases",
  1801. "Check positive and negative infinity", TEST_ENABLED
  1802. };
  1803. static const SDLTest_TestCaseReference truncTestZero = {
  1804. (SDLTest_TestCaseFp) trunc_zeroCases, "trunc_zeroCases",
  1805. "Check positive and negative zero", TEST_ENABLED
  1806. };
  1807. static const SDLTest_TestCaseReference truncTestNan = {
  1808. (SDLTest_TestCaseFp) trunc_nanCase, "trunc_nanCase",
  1809. "Check the NaN special case", TEST_ENABLED
  1810. };
  1811. static const SDLTest_TestCaseReference truncTestRound = {
  1812. (SDLTest_TestCaseFp) trunc_roundNumbersCases, "trunc_roundNumberCases",
  1813. "Check a set of round numbers", TEST_ENABLED
  1814. };
  1815. static const SDLTest_TestCaseReference truncTestFraction = {
  1816. (SDLTest_TestCaseFp) trunc_fractionCases, "trunc_fractionCases",
  1817. "Check a set of fractions", TEST_ENABLED
  1818. };
  1819. static const SDLTest_TestCaseReference truncTestRange = {
  1820. (SDLTest_TestCaseFp) trunc_rangeTest, "trunc_rangeTest",
  1821. "Check a range of positive integer", TEST_ENABLED
  1822. };
  1823. /* SDL_round test cases */
  1824. static const SDLTest_TestCaseReference roundTestInf = {
  1825. (SDLTest_TestCaseFp) round_infCases, "round_infCases",
  1826. "Check positive and negative infinity", TEST_ENABLED
  1827. };
  1828. static const SDLTest_TestCaseReference roundTestZero = {
  1829. (SDLTest_TestCaseFp) round_zeroCases, "round_zeroCases",
  1830. "Check positive and negative zero", TEST_ENABLED
  1831. };
  1832. static const SDLTest_TestCaseReference roundTestNan = {
  1833. (SDLTest_TestCaseFp) round_nanCase, "round_nanCase",
  1834. "Check the NaN special case", TEST_ENABLED
  1835. };
  1836. static const SDLTest_TestCaseReference roundTestRound = {
  1837. (SDLTest_TestCaseFp) round_roundNumbersCases, "round_roundNumberCases",
  1838. "Check a set of round numbers", TEST_ENABLED
  1839. };
  1840. static const SDLTest_TestCaseReference roundTestFraction = {
  1841. (SDLTest_TestCaseFp) round_fractionCases, "round_fractionCases",
  1842. "Check a set of fractions", TEST_ENABLED
  1843. };
  1844. static const SDLTest_TestCaseReference roundTestRange = {
  1845. (SDLTest_TestCaseFp) round_rangeTest, "round_rangeTest",
  1846. "Check a range of positive integer", TEST_ENABLED
  1847. };
  1848. /* SDL_fabs test cases */
  1849. static const SDLTest_TestCaseReference fabsTestInf = {
  1850. (SDLTest_TestCaseFp) fabs_infCases, "fabs_infCases",
  1851. "Check positive and negative infinity", TEST_ENABLED
  1852. };
  1853. static const SDLTest_TestCaseReference fabsTestZero = {
  1854. (SDLTest_TestCaseFp) fabs_zeroCases, "fabs_zeroCases",
  1855. "Check positive and negative zero", TEST_ENABLED
  1856. };
  1857. static const SDLTest_TestCaseReference fabsTestNan = {
  1858. (SDLTest_TestCaseFp) fabs_nanCase, "fabs_nanCase",
  1859. "Check the NaN special case", TEST_ENABLED
  1860. };
  1861. static const SDLTest_TestCaseReference fabsTestRange = {
  1862. (SDLTest_TestCaseFp) fabs_rangeTest, "fabs_rangeTest",
  1863. "Check a range of positive integer", TEST_ENABLED
  1864. };
  1865. /* SDL_copysign test cases */
  1866. static const SDLTest_TestCaseReference copysignTestInf = {
  1867. (SDLTest_TestCaseFp) copysign_infCases, "copysign_infCases",
  1868. "Check positive and negative infinity", TEST_ENABLED
  1869. };
  1870. static const SDLTest_TestCaseReference copysignTestZero = {
  1871. (SDLTest_TestCaseFp) copysign_zeroCases, "copysign_zeroCases",
  1872. "Check positive and negative zero", TEST_ENABLED
  1873. };
  1874. static const SDLTest_TestCaseReference copysignTestNan = {
  1875. (SDLTest_TestCaseFp) copysign_nanCases, "copysign_nanCases",
  1876. "Check the NaN special cases", TEST_ENABLED
  1877. };
  1878. static const SDLTest_TestCaseReference copysignTestRange = {
  1879. (SDLTest_TestCaseFp) copysign_rangeTest, "copysign_rangeTest",
  1880. "Check a range of positive integer", TEST_ENABLED
  1881. };
  1882. /* SDL_fmod test cases */
  1883. static const SDLTest_TestCaseReference fmodTestDivOfInf = {
  1884. (SDLTest_TestCaseFp) fmod_divOfInfCases, "fmod_divOfInfCases",
  1885. "Check division of positive and negative infinity", TEST_ENABLED
  1886. };
  1887. static const SDLTest_TestCaseReference fmodTestDivByInf = {
  1888. (SDLTest_TestCaseFp) fmod_divByInfCases, "fmod_divByInfCases",
  1889. "Check division by positive and negative infinity", TEST_ENABLED
  1890. };
  1891. static const SDLTest_TestCaseReference fmodTestDivOfZero = {
  1892. (SDLTest_TestCaseFp) fmod_divOfZeroCases, "fmod_divOfZeroCases",
  1893. "Check division of positive and negative zero", TEST_ENABLED
  1894. };
  1895. static const SDLTest_TestCaseReference fmodTestDivByZero = {
  1896. (SDLTest_TestCaseFp) fmod_divByZeroCases, "fmod_divByZeroCases",
  1897. "Check division by positive and negative zero", TEST_ENABLED
  1898. };
  1899. static const SDLTest_TestCaseReference fmodTestNan = {
  1900. (SDLTest_TestCaseFp) fmod_nanCases, "fmod_nanCases",
  1901. "Check the NaN special cases", TEST_ENABLED
  1902. };
  1903. static const SDLTest_TestCaseReference fmodTestRegular = {
  1904. (SDLTest_TestCaseFp) fmod_regularCases, "fmod_regularCases",
  1905. "Check a set of regular values", TEST_ENABLED
  1906. };
  1907. static const SDLTest_TestCaseReference fmodTestRange = {
  1908. (SDLTest_TestCaseFp) fmod_rangeTest, "fmod_rangeTest",
  1909. "Check a range of positive integer", TEST_ENABLED
  1910. };
  1911. /* SDL_exp test cases */
  1912. static const SDLTest_TestCaseReference expTestInf = {
  1913. (SDLTest_TestCaseFp) exp_infCases, "exp_infCases",
  1914. "Check positive and negative infinity", TEST_ENABLED
  1915. };
  1916. static const SDLTest_TestCaseReference expTestZero = {
  1917. (SDLTest_TestCaseFp) exp_zeroCases, "exp_zeroCases",
  1918. "Check for positive and negative zero", TEST_ENABLED
  1919. };
  1920. static const SDLTest_TestCaseReference expTestOverflow = {
  1921. (SDLTest_TestCaseFp) exp_overflowCase, "exp_overflowCase",
  1922. "Check for overflow", TEST_ENABLED
  1923. };
  1924. static const SDLTest_TestCaseReference expTestBase = {
  1925. (SDLTest_TestCaseFp) exp_baseCase, "exp_baseCase",
  1926. "Check the base case of 1.0", TEST_ENABLED
  1927. };
  1928. static const SDLTest_TestCaseReference expTestRegular = {
  1929. (SDLTest_TestCaseFp) exp_regularCases, "exp_regularCases",
  1930. "Check a set of regular values", TEST_ENABLED
  1931. };
  1932. /* SDL_log test cases */
  1933. static const SDLTest_TestCaseReference logTestLimit = {
  1934. (SDLTest_TestCaseFp) log_limitCases, "log_limitCases",
  1935. "Check for limits", TEST_ENABLED
  1936. };
  1937. static const SDLTest_TestCaseReference logTestNan = {
  1938. (SDLTest_TestCaseFp) log_nanCases, "log_nanCases",
  1939. "Check for the nan cases", TEST_ENABLED
  1940. };
  1941. static const SDLTest_TestCaseReference logTestBase = {
  1942. (SDLTest_TestCaseFp) log_baseCases, "log_baseCases",
  1943. "Check for base cases", TEST_ENABLED
  1944. };
  1945. static const SDLTest_TestCaseReference logTestRegular = {
  1946. (SDLTest_TestCaseFp) log_regularCases, "log_regularCases",
  1947. "Check a set of regular values", TEST_ENABLED
  1948. };
  1949. /* SDL_log10 test cases */
  1950. static const SDLTest_TestCaseReference log10TestLimit = {
  1951. (SDLTest_TestCaseFp) log10_limitCases, "log10_limitCases",
  1952. "Check for limits", TEST_ENABLED
  1953. };
  1954. static const SDLTest_TestCaseReference log10TestNan = {
  1955. (SDLTest_TestCaseFp) log10_nanCases, "log10_nanCases",
  1956. "Check for the nan cases", TEST_ENABLED
  1957. };
  1958. static const SDLTest_TestCaseReference log10TestBase = {
  1959. (SDLTest_TestCaseFp) log10_baseCases, "log10_baseCases",
  1960. "Check for base cases", TEST_ENABLED
  1961. };
  1962. static const SDLTest_TestCaseReference log10TestRegular = {
  1963. (SDLTest_TestCaseFp) log10_regularCases, "log10_regularCases",
  1964. "Check a set of regular values", TEST_ENABLED
  1965. };
  1966. /* SDL_pow test cases */
  1967. static const SDLTest_TestCaseReference powTestExpInf1 = {
  1968. (SDLTest_TestCaseFp) pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
  1969. "Check for pow(-1, +/-inf)", TEST_ENABLED
  1970. };
  1971. static const SDLTest_TestCaseReference powTestExpInf2 = {
  1972. (SDLTest_TestCaseFp) pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
  1973. "Check for pow(+/-0, -inf)", TEST_ENABLED
  1974. };
  1975. static const SDLTest_TestCaseReference powTestExpInf3 = {
  1976. (SDLTest_TestCaseFp) pow_expInfCases, "pow_expInfCases",
  1977. "Check for pow(x, +/-inf)", TEST_ENABLED
  1978. };
  1979. static const SDLTest_TestCaseReference powTestBaseInf1 = {
  1980. (SDLTest_TestCaseFp) pow_basePInfCases, "pow_basePInfCases",
  1981. "Check for pow(inf, x)", TEST_ENABLED
  1982. };
  1983. static const SDLTest_TestCaseReference powTestBaseInf2 = {
  1984. (SDLTest_TestCaseFp) pow_baseNInfCases, "pow_baseNInfCases",
  1985. "Check for pow(-inf, x)", TEST_ENABLED
  1986. };
  1987. static const SDLTest_TestCaseReference powTestNan1 = {
  1988. (SDLTest_TestCaseFp) pow_badOperationCase, "pow_badOperationCase",
  1989. "Check for negative finite base and non-integer finite exponent", TEST_ENABLED
  1990. };
  1991. static const SDLTest_TestCaseReference powTestNan2 = {
  1992. (SDLTest_TestCaseFp) pow_base1ExpNanCase, "pow_base1ExpNanCase",
  1993. "Check for pow(1.0, nan)", TEST_ENABLED
  1994. };
  1995. static const SDLTest_TestCaseReference powTestNan3 = {
  1996. (SDLTest_TestCaseFp) pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
  1997. "Check for pow(nan, +/-0)", TEST_ENABLED
  1998. };
  1999. static const SDLTest_TestCaseReference powTestNan4 = {
  2000. (SDLTest_TestCaseFp) pow_nanArgsCases, "pow_nanArgsCases",
  2001. "Check for pow(x, y) with either x or y being nan", TEST_ENABLED
  2002. };
  2003. static const SDLTest_TestCaseReference powTestZero1 = {
  2004. (SDLTest_TestCaseFp) pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
  2005. "Check for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
  2006. };
  2007. static const SDLTest_TestCaseReference powTestZero2 = {
  2008. (SDLTest_TestCaseFp) pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
  2009. "Check for pow(0.0, y), with y an odd integer.", TEST_ENABLED
  2010. };
  2011. static const SDLTest_TestCaseReference powTestZero3 = {
  2012. (SDLTest_TestCaseFp) pow_baseNZeroCases, "pow_baseNZeroCases",
  2013. "Check for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2014. };
  2015. static const SDLTest_TestCaseReference powTestZero4 = {
  2016. (SDLTest_TestCaseFp) pow_basePZeroCases, "pow_basePZeroCases",
  2017. "Check for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2018. };
  2019. static const SDLTest_TestCaseReference powTestRegular = {
  2020. (SDLTest_TestCaseFp) pow_regularCases, "pow_regularCases",
  2021. "Check a set of regular values", TEST_ENABLED
  2022. };
  2023. static const SDLTest_TestCaseReference powTestPowOf2 = {
  2024. (SDLTest_TestCaseFp) pow_powerOfTwo, "pow_powerOfTwo",
  2025. "Check the powers of two from 1 to 8", TEST_ENABLED
  2026. };
  2027. static const SDLTest_TestCaseReference powTestRange = {
  2028. (SDLTest_TestCaseFp) pow_rangeTest, "pow_rangeTest",
  2029. "Check a range of positive integer to the power of 0", TEST_ENABLED
  2030. };
  2031. /* SDL_sqrt test cases */
  2032. static const SDLTest_TestCaseReference sqrtTestInf = {
  2033. (SDLTest_TestCaseFp) sqrt_infCase, "sqrt_infCase",
  2034. "Check positive infinity", TEST_ENABLED
  2035. };
  2036. static const SDLTest_TestCaseReference sqrtTestNan = {
  2037. (SDLTest_TestCaseFp) sqrt_nanCase, "sqrt_nanCase",
  2038. "Check the NaN special case", TEST_ENABLED
  2039. };
  2040. static const SDLTest_TestCaseReference sqrtTestDomain = {
  2041. (SDLTest_TestCaseFp) sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
  2042. "Check for out of domain values", TEST_ENABLED
  2043. };
  2044. static const SDLTest_TestCaseReference sqrtTestBase = {
  2045. (SDLTest_TestCaseFp) sqrt_baseCases, "sqrt_baseCases",
  2046. "Check the base cases", TEST_ENABLED
  2047. };
  2048. static const SDLTest_TestCaseReference sqrtTestRegular = {
  2049. (SDLTest_TestCaseFp) sqrt_regularCases, "sqrt_regularCases",
  2050. "Check a set of regular values", TEST_ENABLED
  2051. };
  2052. /* SDL_scalbn test cases */
  2053. static const SDLTest_TestCaseReference scalbnTestInf = {
  2054. (SDLTest_TestCaseFp) scalbn_infCases, "scalbn_infCases",
  2055. "Check positive and negative infinity arg", TEST_ENABLED
  2056. };
  2057. static const SDLTest_TestCaseReference scalbnTestBaseZero = {
  2058. (SDLTest_TestCaseFp) scalbn_baseZeroCases, "scalbn_baseZeroCases",
  2059. "Check for positive and negative zero arg", TEST_ENABLED
  2060. };
  2061. static const SDLTest_TestCaseReference scalbnTestExpZero = {
  2062. (SDLTest_TestCaseFp) scalbn_expZeroCase, "scalbn_expZeroCase",
  2063. "Check for zero exp", TEST_ENABLED
  2064. };
  2065. static const SDLTest_TestCaseReference scalbnTestNan = {
  2066. (SDLTest_TestCaseFp) scalbn_nanCase, "scalbn_nanCase",
  2067. "Check the NaN special case", TEST_ENABLED
  2068. };
  2069. static const SDLTest_TestCaseReference scalbnTestRegular = {
  2070. (SDLTest_TestCaseFp) scalbn_regularCases, "scalbn_regularCases",
  2071. "Check a set of regular cases", TEST_ENABLED
  2072. };
  2073. /* SDL_cos test cases */
  2074. static const SDLTest_TestCaseReference cosTestInf = {
  2075. (SDLTest_TestCaseFp) cos_infCases, "cos_infCases",
  2076. "Check for positive and negative infinity", TEST_ENABLED
  2077. };
  2078. static const SDLTest_TestCaseReference cosTestNan = {
  2079. (SDLTest_TestCaseFp) cos_nanCase, "cos_nanCase",
  2080. "Check the NaN special case", TEST_ENABLED
  2081. };
  2082. static const SDLTest_TestCaseReference cosTestRegular = {
  2083. (SDLTest_TestCaseFp) cos_regularCases, "cos_regularCases",
  2084. "Check a set of regular cases", TEST_ENABLED
  2085. };
  2086. static const SDLTest_TestCaseReference cosTestPrecision = {
  2087. (SDLTest_TestCaseFp) cos_precisionTest, "cos_precisionTest",
  2088. "Check cosine precision to the tenth decimal", TEST_ENABLED
  2089. };
  2090. static const SDLTest_TestCaseReference cosTestRange = {
  2091. (SDLTest_TestCaseFp) cos_rangeTest, "cos_rangeTest",
  2092. "Check a range of positive integer", TEST_ENABLED
  2093. };
  2094. /* SDL_sin test cases */
  2095. static const SDLTest_TestCaseReference sinTestInf = {
  2096. (SDLTest_TestCaseFp) sin_infCases, "sin_infCases",
  2097. "Check for positive and negative infinity", TEST_ENABLED
  2098. };
  2099. static const SDLTest_TestCaseReference sinTestNan = {
  2100. (SDLTest_TestCaseFp) sin_nanCase, "sin_nanCase",
  2101. "Check the NaN special case", TEST_ENABLED
  2102. };
  2103. static const SDLTest_TestCaseReference sinTestRegular = {
  2104. (SDLTest_TestCaseFp) sin_regularCases, "sin_regularCases",
  2105. "Check a set of regular cases", TEST_ENABLED
  2106. };
  2107. static const SDLTest_TestCaseReference sinTestPrecision = {
  2108. (SDLTest_TestCaseFp) sin_precisionTest, "sin_precisionTest",
  2109. "Check sine precision to the tenth decimal", TEST_ENABLED
  2110. };
  2111. static const SDLTest_TestCaseReference sinTestRange = {
  2112. (SDLTest_TestCaseFp) sin_rangeTest, "sin_rangeTest",
  2113. "Check a range of positive integer", TEST_ENABLED
  2114. };
  2115. /* SDL_tan test cases */
  2116. static const SDLTest_TestCaseReference tanTestInf = {
  2117. (SDLTest_TestCaseFp) tan_infCases, "tan_infCases",
  2118. "Check for positive and negative infinity", TEST_ENABLED
  2119. };
  2120. static const SDLTest_TestCaseReference tanTestNan = {
  2121. (SDLTest_TestCaseFp) tan_nanCase, "tan_nanCase",
  2122. "Check the NaN special case", TEST_ENABLED
  2123. };
  2124. static const SDLTest_TestCaseReference tanTestZero = {
  2125. (SDLTest_TestCaseFp) tan_zeroCases, "tan_zeroCases",
  2126. "Check a set of regular cases", TEST_ENABLED
  2127. };
  2128. static const SDLTest_TestCaseReference tanTestPrecision = {
  2129. (SDLTest_TestCaseFp) tan_precisionTest, "tan_precisionTest",
  2130. "Check tane precision to the tenth decimal", TEST_ENABLED
  2131. };
  2132. static const SDLTest_TestCaseReference *mathTests[] = {
  2133. &floorTestInf, &floorTestZero, &floorTestNan,
  2134. &floorTestRound, &floorTestFraction, &floorTestRange,
  2135. &ceilTestInf, &ceilTestZero, &ceilTestNan,
  2136. &ceilTestRound, &ceilTestFraction, &ceilTestRange,
  2137. &truncTestInf, &truncTestZero, &truncTestNan,
  2138. &truncTestRound, &truncTestFraction, &truncTestRange,
  2139. &roundTestInf, &roundTestZero, &roundTestNan,
  2140. &roundTestRound, &roundTestFraction, &roundTestRange,
  2141. &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
  2142. &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
  2143. &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
  2144. &fmodTestNan, &fmodTestRegular, &fmodTestRange,
  2145. &expTestInf, &expTestZero, &expTestOverflow,
  2146. &expTestBase, &expTestRegular,
  2147. &logTestLimit, &logTestNan,
  2148. &logTestBase, &logTestRegular,
  2149. &log10TestLimit, &log10TestNan,
  2150. &log10TestBase, &log10TestRegular,
  2151. &powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
  2152. &powTestBaseInf1, &powTestBaseInf2,
  2153. &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
  2154. &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
  2155. &powTestRegular, &powTestPowOf2, &powTestRange,
  2156. &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
  2157. &sqrtTestBase, &sqrtTestRegular,
  2158. &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
  2159. &scalbnTestNan, &scalbnTestRegular,
  2160. &cosTestInf, &cosTestNan, &cosTestRegular,
  2161. &cosTestPrecision, &cosTestRange,
  2162. &sinTestInf, &sinTestNan, &sinTestRegular,
  2163. &sinTestPrecision, &sinTestRange,
  2164. &tanTestInf, &tanTestNan, &tanTestZero, &tanTestPrecision,
  2165. NULL
  2166. };
  2167. SDLTest_TestSuiteReference mathTestSuite = { "Math", NULL, mathTests, NULL };