testautomation_math.c 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762
  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,
  67. * checks the first ten digits of the result (truncated).
  68. *
  69. * This function is used to test functions with inaccurate results such as trigonometric
  70. * functions where angles such as PI/2 can't be accurately represented.
  71. *
  72. * \note Tests may fail if SDL_trunc is not functional.
  73. *
  74. * \param func_name, the name of the tested function.
  75. * \param func, the function to call.
  76. * \param cases, an array of all the cases.
  77. * \param cases_size, the size of the cases array.
  78. */
  79. static int
  80. helper_dtod_approx(const char *func_name, d_to_d_func func,
  81. const d_to_d *cases, const size_t cases_size)
  82. {
  83. Uint32 i;
  84. for (i = 0; i < cases_size; i++) {
  85. const double result = func(cases[i].input) * 1.0E10;
  86. SDLTest_AssertCheck(SDL_trunc(result) == cases[i].expected,
  87. "%s(%f), expected %f, got %f",
  88. func_name,
  89. cases[i].input,
  90. cases[i].expected, result);
  91. }
  92. return TEST_COMPLETED;
  93. }
  94. /**
  95. * \brief Runs all the cases on a given function with a signature (double, double) -> double
  96. *
  97. * \param func_name, the name of the tested function.
  98. * \param func, the function to call.
  99. * \param cases, an array of all the cases.
  100. * \param cases_size, the size of the cases array.
  101. */
  102. static int
  103. helper_ddtod(const char *func_name, dd_to_d_func func,
  104. const dd_to_d *cases, const size_t cases_size)
  105. {
  106. Uint32 i;
  107. for (i = 0; i < cases_size; i++) {
  108. const double result = func(cases[i].x_input, cases[i].y_input);
  109. SDLTest_AssertCheck(result == cases[i].expected,
  110. "%s(%f,%f), expected %f, got %f",
  111. func_name,
  112. cases[i].x_input, cases[i].y_input,
  113. cases[i].expected, result);
  114. }
  115. return TEST_COMPLETED;
  116. }
  117. /**
  118. * \brief Runs a range of values on a given function with a signature double -> double
  119. *
  120. * This function is only meant to test functions that returns the input value if it is
  121. * integral: f(x) -> x for x in N.
  122. *
  123. * \param func_name, the name of the tested function.
  124. * \param func, the function to call.
  125. */
  126. static int
  127. helper_range(const char *func_name, d_to_d_func func)
  128. {
  129. Uint32 i;
  130. double test_value = 0.0;
  131. SDLTest_AssertPass("%s: Testing a range of %u values with steps of %u",
  132. func_name,
  133. RANGE_TEST_ITERATIONS,
  134. RANGE_TEST_STEP);
  135. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  136. double result;
  137. /* These are tested elsewhere */
  138. if (isnan(test_value) || isinf(test_value)) {
  139. continue;
  140. }
  141. result = func(test_value);
  142. if (result != test_value) { /* Only log failures to save performances */
  143. SDLTest_AssertCheck(SDL_FALSE,
  144. "%s(%.1f), expected %.1f, got %.1f",
  145. func_name, test_value,
  146. test_value, result);
  147. return TEST_ABORTED;
  148. }
  149. }
  150. return TEST_COMPLETED;
  151. }
  152. /* ================= Test Case Implementation ================== */
  153. /* SDL_floor tests functions */
  154. /**
  155. * \brief Checks positive and negative infinity.
  156. */
  157. static int
  158. floor_infCases(void *args)
  159. {
  160. double result;
  161. result = SDL_floor(INFINITY);
  162. SDLTest_AssertCheck(INFINITY == result,
  163. "Floor(%f), expected %f, got %f",
  164. INFINITY, INFINITY, result);
  165. result = SDL_floor(-INFINITY);
  166. SDLTest_AssertCheck(-INFINITY == result,
  167. "Floor(%f), expected %f, got %f",
  168. -INFINITY, -INFINITY, result);
  169. return TEST_COMPLETED;
  170. }
  171. /**
  172. * \brief Checks positive and negative zero.
  173. */
  174. static int
  175. floor_zeroCases(void *args)
  176. {
  177. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  178. return helper_dtod("Floor", SDL_floor, zero_cases, SDL_arraysize(zero_cases));
  179. }
  180. /**
  181. * \brief Checks the NaN case.
  182. */
  183. static int
  184. floor_nanCase(void *args)
  185. {
  186. const double result = SDL_floor(NAN);
  187. SDLTest_AssertCheck(isnan(result),
  188. "Floor(nan), expected nan, got %f",
  189. result);
  190. return TEST_COMPLETED;
  191. }
  192. /**
  193. * \brief Checks round values (x.0) for themselves
  194. */
  195. static int
  196. floor_roundNumbersCases(void *args)
  197. {
  198. const d_to_d round_cases[] = {
  199. { 1.0, 1.0 },
  200. { -1.0, -1.0 },
  201. { 15.0, 15.0 },
  202. { -15.0, -15.0 },
  203. { 125.0, 125.0 },
  204. { -125.0, -125.0 },
  205. { 1024.0, 1024.0 },
  206. { -1024.0, -1024.0 }
  207. };
  208. return helper_dtod("Floor", SDL_floor, round_cases, SDL_arraysize(round_cases));
  209. }
  210. /**
  211. * \brief Checks a set of fractions
  212. */
  213. static int
  214. floor_fractionCases(void *args)
  215. {
  216. const d_to_d frac_cases[] = {
  217. { 1.0 / 2.0, 0.0 },
  218. { -1.0 / 2.0, -1.0 },
  219. { 4.0 / 3.0, 1.0 },
  220. { -4.0 / 3.0, -2.0 },
  221. { 76.0 / 7.0, 10.0 },
  222. { -76.0 / 7.0, -11.0 },
  223. { 535.0 / 8.0, 66.0 },
  224. { -535.0 / 8.0, -67.0 },
  225. { 19357.0 / 53.0, 365.0 },
  226. { -19357.0 / 53.0, -366.0 }
  227. };
  228. return helper_dtod("Floor", SDL_floor, frac_cases, SDL_arraysize(frac_cases));
  229. }
  230. /**
  231. * \brief Checks a range of values between 0 and UINT32_MAX
  232. */
  233. static int
  234. floor_rangeTest(void *args)
  235. {
  236. return helper_range("Floor", SDL_floor);
  237. }
  238. /* SDL_ceil tests functions */
  239. /**
  240. * \brief Checks positive and negative infinity.
  241. */
  242. static int
  243. ceil_infCases(void *args)
  244. {
  245. double result;
  246. result = SDL_ceil(INFINITY);
  247. SDLTest_AssertCheck(INFINITY == result,
  248. "Ceil(%f), expected %f, got %f",
  249. INFINITY, INFINITY, result);
  250. result = SDL_ceil(-INFINITY);
  251. SDLTest_AssertCheck(-INFINITY == result,
  252. "Ceil(%f), expected %f, got %f",
  253. -INFINITY, -INFINITY, result);
  254. return TEST_COMPLETED;
  255. }
  256. /**
  257. * \brief Checks positive and negative zero.
  258. */
  259. static int
  260. ceil_zeroCases(void *args)
  261. {
  262. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  263. return helper_dtod("Ceil", SDL_ceil, zero_cases, SDL_arraysize(zero_cases));
  264. }
  265. /**
  266. * \brief Checks the NaN case.
  267. */
  268. static int
  269. ceil_nanCase(void *args)
  270. {
  271. const double result = SDL_ceil(NAN);
  272. SDLTest_AssertCheck(isnan(result),
  273. "Ceil(nan), expected nan, got %f",
  274. result);
  275. return TEST_COMPLETED;
  276. }
  277. /**
  278. * \brief Checks round values (x.0) for themselves
  279. */
  280. static int
  281. ceil_roundNumbersCases(void *args)
  282. {
  283. const d_to_d round_cases[] = {
  284. { 1.0, 1.0 },
  285. { -1.0, -1.0 },
  286. { 15.0, 15.0 },
  287. { -15.0, -15.0 },
  288. { 125.0, 125.0 },
  289. { -125.0, -125.0 },
  290. { 1024.0, 1024.0 },
  291. { -1024.0, -1024.0 }
  292. };
  293. return helper_dtod("Ceil", SDL_ceil, round_cases, SDL_arraysize(round_cases));
  294. }
  295. /**
  296. * \brief Checks a set of fractions
  297. */
  298. static int
  299. ceil_fractionCases(void *args)
  300. {
  301. const d_to_d frac_cases[] = {
  302. { 1.0 / 2.0, 1.0 },
  303. { -1.0 / 2.0, -0.0 },
  304. { 4.0 / 3.0, 2.0 },
  305. { -4.0 / 3.0, -1.0 },
  306. { 76.0 / 7.0, 11.0 },
  307. { -76.0 / 7.0, -10.0 },
  308. { 535.0 / 8.0, 67.0 },
  309. { -535.0 / 8.0, -66.0 },
  310. { 19357.0 / 53.0, 366.0 },
  311. { -19357.0 / 53.0, -365.0 }
  312. };
  313. return helper_dtod("Ceil", SDL_ceil, frac_cases, SDL_arraysize(frac_cases));
  314. }
  315. /**
  316. * \brief Checks a range of values between 0 and UINT32_MAX
  317. */
  318. static int
  319. ceil_rangeTest(void *args)
  320. {
  321. return helper_range("Ceil", SDL_ceil);
  322. }
  323. /* SDL_trunc tests functions */
  324. /**
  325. * \brief Checks positive and negative infinity.
  326. */
  327. static int
  328. trunc_infCases(void *args)
  329. {
  330. double result;
  331. result = SDL_trunc(INFINITY);
  332. SDLTest_AssertCheck(INFINITY == result,
  333. "Trunc(%f), expected %f, got %f",
  334. INFINITY, INFINITY, result);
  335. result = SDL_trunc(-INFINITY);
  336. SDLTest_AssertCheck(-INFINITY == result,
  337. "Trunc(%f), expected %f, got %f",
  338. -INFINITY, -INFINITY, result);
  339. return TEST_COMPLETED;
  340. }
  341. /**
  342. * \brief Checks positive and negative zero.
  343. */
  344. static int
  345. trunc_zeroCases(void *args)
  346. {
  347. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  348. return helper_dtod("Trunc", SDL_trunc, zero_cases, SDL_arraysize(zero_cases));
  349. }
  350. /**
  351. * \brief Checks the NaN case.
  352. */
  353. static int
  354. trunc_nanCase(void *args)
  355. {
  356. const double result = SDL_trunc(NAN);
  357. SDLTest_AssertCheck(isnan(result),
  358. "Trunc(nan), expected nan, got %f",
  359. result);
  360. return TEST_COMPLETED;
  361. }
  362. /**
  363. * \brief Checks round values (x.0) for themselves
  364. */
  365. static int
  366. trunc_roundNumbersCases(void *args)
  367. {
  368. const d_to_d round_cases[] = {
  369. { 1.0, 1.0 },
  370. { -1.0, -1.0 },
  371. { 15.0, 15.0 },
  372. { -15.0, -15.0 },
  373. { 125.0, 125.0 },
  374. { -125.0, -125.0 },
  375. { 1024.0, 1024.0 },
  376. { -1024.0, -1024.0 }
  377. };
  378. return helper_dtod("Trunc", SDL_trunc, round_cases, SDL_arraysize(round_cases));
  379. }
  380. /**
  381. * \brief Checks a set of fractions
  382. */
  383. static int
  384. trunc_fractionCases(void *args)
  385. {
  386. const d_to_d frac_cases[] = {
  387. { 1.0 / 2.0, 0.0 },
  388. { -1.0 / 2.0, -0.0 },
  389. { 4.0 / 3.0, 1.0 },
  390. { -4.0 / 3.0, -1.0 },
  391. { 76.0 / 7.0, 10.0 },
  392. { -76.0 / 7.0, -10.0 },
  393. { 535.0 / 8.0, 66.0 },
  394. { -535.0 / 8.0, -66.0 },
  395. { 19357.0 / 53.0, 365.0 },
  396. { -19357.0 / 53.0, -365.0 }
  397. };
  398. return helper_dtod("Trunc", SDL_trunc, frac_cases, SDL_arraysize(frac_cases));
  399. }
  400. /**
  401. * \brief Checks a range of values between 0 and UINT32_MAX
  402. */
  403. static int
  404. trunc_rangeTest(void *args)
  405. {
  406. return helper_range("Trunc", SDL_trunc);
  407. }
  408. /* SDL_round tests functions */
  409. /**
  410. * \brief Checks positive and negative infinity.
  411. */
  412. static int
  413. round_infCases(void *args)
  414. {
  415. double result;
  416. result = SDL_round(INFINITY);
  417. SDLTest_AssertCheck(INFINITY == result,
  418. "Round(%f), expected %f, got %f",
  419. INFINITY, INFINITY, result);
  420. result = SDL_round(-INFINITY);
  421. SDLTest_AssertCheck(-INFINITY == result,
  422. "Round(%f), expected %f, got %f",
  423. -INFINITY, -INFINITY, result);
  424. return TEST_COMPLETED;
  425. }
  426. /**
  427. * \brief Checks positive and negative zero.
  428. */
  429. static int
  430. round_zeroCases(void *args)
  431. {
  432. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, -0.0 } };
  433. return helper_dtod("Round", SDL_round, zero_cases, SDL_arraysize(zero_cases));
  434. }
  435. /**
  436. * \brief Checks the NaN case.
  437. */
  438. static int
  439. round_nanCase(void *args)
  440. {
  441. const double result = SDL_round(NAN);
  442. SDLTest_AssertCheck(isnan(result),
  443. "Round(nan), expected nan, got %f",
  444. result);
  445. return TEST_COMPLETED;
  446. }
  447. /**
  448. * \brief Checks round values (x.0) for themselves
  449. */
  450. static int
  451. round_roundNumbersCases(void *args)
  452. {
  453. const d_to_d round_cases[] = {
  454. { 1.0, 1.0 },
  455. { -1.0, -1.0 },
  456. { 15.0, 15.0 },
  457. { -15.0, -15.0 },
  458. { 125.0, 125.0 },
  459. { -125.0, -125.0 },
  460. { 1024.0, 1024.0 },
  461. { -1024.0, -1024.0 }
  462. };
  463. return helper_dtod("Round", SDL_round, round_cases, SDL_arraysize(round_cases));
  464. }
  465. /**
  466. * \brief Checks a set of fractions
  467. */
  468. static int
  469. round_fractionCases(void *args)
  470. {
  471. const d_to_d frac_cases[] = {
  472. { 1.0 / 2.0, 1.0 },
  473. { -1.0 / 2.0, -1.0 },
  474. { 4.0 / 3.0, 1.0 },
  475. { -4.0 / 3.0, -1.0 },
  476. { 76.0 / 7.0, 11.0 },
  477. { -76.0 / 7.0, -11.0 },
  478. { 535.0 / 8.0, 67.0 },
  479. { -535.0 / 8.0, -67.0 },
  480. { 19357.0 / 53.0, 365.0 },
  481. { -19357.0 / 53.0, -365.0 }
  482. };
  483. return helper_dtod("Round", SDL_round, frac_cases, SDL_arraysize(frac_cases));
  484. }
  485. /**
  486. * \brief Checks a range of values between 0 and UINT32_MAX
  487. */
  488. static int
  489. round_rangeTest(void *args)
  490. {
  491. return helper_range("Round", SDL_round);
  492. }
  493. /* SDL_fabs tests functions */
  494. /**
  495. * \brief Checks positive and negative infinity.
  496. */
  497. static int
  498. fabs_infCases(void *args)
  499. {
  500. double result;
  501. result = SDL_fabs(INFINITY);
  502. SDLTest_AssertCheck(INFINITY == result,
  503. "Fabs(%f), expected %f, got %f",
  504. INFINITY, INFINITY, result);
  505. result = SDL_fabs(-INFINITY);
  506. SDLTest_AssertCheck(INFINITY == result,
  507. "Fabs(%f), expected %f, got %f",
  508. -INFINITY, INFINITY, result);
  509. return TEST_COMPLETED;
  510. }
  511. /**
  512. * \brief Checks positive and negative zero
  513. */
  514. static int
  515. fabs_zeroCases(void *args)
  516. {
  517. const d_to_d zero_cases[] = { { 0.0, 0.0 }, { -0.0, 0.0 } };
  518. return helper_dtod("Fabs", SDL_fabs, zero_cases, SDL_arraysize(zero_cases));
  519. }
  520. /**
  521. * \brief Checks the NaN case.
  522. */
  523. static int
  524. fabs_nanCase(void *args)
  525. {
  526. const double result = SDL_fabs(NAN);
  527. SDLTest_AssertCheck(isnan(result),
  528. "Fabs(nan), expected nan, got %f",
  529. result);
  530. return TEST_COMPLETED;
  531. }
  532. /**
  533. * \brief Checks a range of values between 0 and UINT32_MAX
  534. */
  535. static int
  536. fabs_rangeTest(void *args)
  537. {
  538. return helper_range("Fabs", SDL_fabs);
  539. }
  540. /* SDL_copysign tests functions */
  541. /**
  542. * \brief Checks positive and negative inifnity.
  543. */
  544. static int
  545. copysign_infCases(void *args)
  546. {
  547. double result;
  548. result = SDL_copysign(INFINITY, -1.0);
  549. SDLTest_AssertCheck(-INFINITY == result,
  550. "Copysign(%f,%.1f), expected %f, got %f",
  551. INFINITY, -1.0, -INFINITY, result);
  552. result = SDL_copysign(INFINITY, 1.0);
  553. SDLTest_AssertCheck(INFINITY == result,
  554. "Copysign(%f,%.1f), expected %f, got %f",
  555. INFINITY, 1.0, INFINITY, result);
  556. result = SDL_copysign(-INFINITY, -1.0);
  557. SDLTest_AssertCheck(-INFINITY == result,
  558. "Copysign(%f,%.1f), expected %f, got %f",
  559. -INFINITY, -1.0, -INFINITY, result);
  560. result = SDL_copysign(-INFINITY, 1.0);
  561. SDLTest_AssertCheck(INFINITY == result,
  562. "Copysign(%f,%.1f), expected %f, got %f",
  563. -INFINITY, 1.0, INFINITY, result);
  564. return TEST_COMPLETED;
  565. }
  566. /**
  567. * \brief Checks positive and negative zero.
  568. */
  569. static int
  570. copysign_zeroCases(void *args)
  571. {
  572. const dd_to_d zero_cases[] = {
  573. { 0.0, 1.0, 0.0 },
  574. { 0.0, -1.0, -0.0 },
  575. { -0.0, 1.0, 0.0 },
  576. { -0.0, -1.0, -0.0 }
  577. };
  578. return helper_ddtod("Copysign", SDL_copysign, zero_cases, SDL_arraysize(zero_cases));
  579. }
  580. /**
  581. * \brief Checks the NaN cases.
  582. */
  583. static int
  584. copysign_nanCases(void *args)
  585. {
  586. double result;
  587. result = SDL_copysign(NAN, 1.0);
  588. SDLTest_AssertCheck(isnan(result),
  589. "Copysign(nan,1.0), expected nan, got %f",
  590. result);
  591. result = SDL_copysign(NAN, -1.0);
  592. SDLTest_AssertCheck(isnan(result),
  593. "Copysign(nan,-1.0), expected nan, got %f",
  594. result);
  595. return TEST_COMPLETED;
  596. }
  597. /**
  598. * \brief Checks a range of values between 0 and UINT32_MAX
  599. */
  600. static int
  601. copysign_rangeTest(void *args)
  602. {
  603. Uint32 i;
  604. double test_value = 0.0;
  605. SDLTest_AssertPass("Copysign: Testing a range of %u values with steps of %u",
  606. RANGE_TEST_ITERATIONS,
  607. RANGE_TEST_STEP);
  608. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  609. double result;
  610. /* These are tested elsewhere */
  611. if (isnan(test_value) || isinf(test_value)) {
  612. continue;
  613. }
  614. /* Only log failures to save performances */
  615. result = SDL_copysign(test_value, 1.0);
  616. if (result != test_value) {
  617. SDLTest_AssertCheck(SDL_FALSE,
  618. "Copysign(%.1f,%.1f), expected %.1f, got %.1f",
  619. test_value, 1.0, test_value, result);
  620. return TEST_ABORTED;
  621. }
  622. result = SDL_copysign(test_value, -1.0);
  623. if (result != -test_value) {
  624. SDLTest_AssertCheck(SDL_FALSE,
  625. "Copysign(%.1f,%.1f), expected %.1f, got %.1f",
  626. test_value, -1.0, -test_value, result);
  627. return TEST_ABORTED;
  628. }
  629. }
  630. return TEST_COMPLETED;
  631. }
  632. /* SDL_fmod tests functions */
  633. /**
  634. * \brief Checks division of positive and negative inifnity.
  635. */
  636. static int
  637. fmod_divOfInfCases(void *args)
  638. {
  639. double result;
  640. result = SDL_fmod(INFINITY, -1.0);
  641. SDLTest_AssertCheck(isnan(result),
  642. "Fmod(%f,%.1f), expected %f, got %f",
  643. INFINITY, -1.0, NAN, result);
  644. result = SDL_fmod(INFINITY, 1.0);
  645. SDLTest_AssertCheck(isnan(result),
  646. "Fmod(%f,%.1f), expected %f, got %f",
  647. INFINITY, 1.0, NAN, result);
  648. result = SDL_fmod(-INFINITY, -1.0);
  649. SDLTest_AssertCheck(isnan(result),
  650. "Fmod(%f,%.1f), expected %f, got %f",
  651. -INFINITY, -1.0, NAN, result);
  652. result = SDL_fmod(-INFINITY, 1.0);
  653. SDLTest_AssertCheck(isnan(result),
  654. "Fmod(%f,%.1f), expected %f, got %f",
  655. -INFINITY, 1.0, NAN, result);
  656. return TEST_COMPLETED;
  657. }
  658. /**
  659. * \brief Checks division by positive and negative inifnity.
  660. */
  661. static int
  662. fmod_divByInfCases(void *args)
  663. {
  664. double result;
  665. result = SDL_fmod(1.0, INFINITY);
  666. SDLTest_AssertCheck(1.0 == result,
  667. "Fmod(%.1f,%f), expected %f, got %f",
  668. 1.0, INFINITY, 1.0, result);
  669. result = SDL_fmod(-1.0, INFINITY);
  670. SDLTest_AssertCheck(-1.0 == result,
  671. "Fmod(%.1f,%f), expected %f, got %f",
  672. -1.0, INFINITY, -1.0, result);
  673. result = SDL_fmod(1.0, -INFINITY);
  674. SDLTest_AssertCheck(1.0 == result,
  675. "Fmod(%.1f,%f), expected %f, got %f",
  676. 1.0, -INFINITY, 1.0, result);
  677. result = SDL_fmod(-1.0, -INFINITY);
  678. SDLTest_AssertCheck(-1.0 == result,
  679. "Fmod(%.1f,%f), expected %f, got %f",
  680. -1.0, -INFINITY, -1.0, result);
  681. return TEST_COMPLETED;
  682. }
  683. /**
  684. * \brief Checks division of positive and negative zero.
  685. */
  686. static int
  687. fmod_divOfZeroCases(void *args)
  688. {
  689. const dd_to_d zero_cases[] = {
  690. { 0.0, 1.0, 0.0 },
  691. { 0.0, -1.0, 0.0 },
  692. { -0.0, 1.0, -0.0 },
  693. { -0.0, -1.0, -0.0 }
  694. };
  695. return helper_ddtod("Fmod", SDL_fmod, zero_cases, SDL_arraysize(zero_cases));
  696. }
  697. /**
  698. * \brief Checks division by positive and negative zero.
  699. */
  700. static int
  701. fmod_divByZeroCases(void *args)
  702. {
  703. double result;
  704. result = SDL_fmod(1.0, 0.0);
  705. SDLTest_AssertCheck(isnan(result),
  706. "Fmod(1.0,0.0), expected nan, got %f",
  707. result);
  708. result = SDL_fmod(-1.0, 0.0);
  709. SDLTest_AssertCheck(isnan(result),
  710. "Fmod(-1.0,0.0), expected nan, got %f",
  711. result);
  712. result = SDL_fmod(1.0, -0.0);
  713. SDLTest_AssertCheck(isnan(result),
  714. "Fmod(1.0,-0.0), expected nan, got %f",
  715. result);
  716. result = SDL_fmod(-1.0, -0.0);
  717. SDLTest_AssertCheck(isnan(result),
  718. "Fmod(-1.0,-0.0), expected nan, got %f",
  719. result);
  720. return TEST_COMPLETED;
  721. }
  722. /**
  723. * \brief Checks the NaN cases.
  724. */
  725. static int
  726. fmod_nanCases(void *args)
  727. {
  728. double result;
  729. result = SDL_fmod(NAN, 1.0);
  730. SDLTest_AssertCheck(isnan(result),
  731. "Fmod(nan,1.0), expected nan, got %f",
  732. result);
  733. result = SDL_fmod(NAN, -1.0);
  734. SDLTest_AssertCheck(isnan(result),
  735. "Fmod(nan,-1.0), expected nan, got %f",
  736. result);
  737. result = SDL_fmod(1.0, NAN);
  738. SDLTest_AssertCheck(isnan(result),
  739. "Fmod(1.0,nan), expected nan, got %f",
  740. result);
  741. result = SDL_fmod(-1.0, NAN);
  742. SDLTest_AssertCheck(isnan(result),
  743. "Fmod(-1.0,nan), expected nan, got %f",
  744. result);
  745. return TEST_COMPLETED;
  746. }
  747. /**
  748. * \brief Checks a set of regular values.
  749. */
  750. static int
  751. fmod_regularCases(void *args)
  752. {
  753. const dd_to_d regular_cases[] = {
  754. { 3.5, 2.0, 1.5 },
  755. { -6.25, 3.0, -0.25 },
  756. { 7.5, 2.5, 0.0 },
  757. { 2.0 / 3.0, -1.0 / 3.0, 0.0 }
  758. };
  759. return helper_ddtod("Fmod", SDL_fmod, regular_cases, SDL_arraysize(regular_cases));
  760. }
  761. /**
  762. * \brief Checks a range of values between 0 and UINT32_MAX
  763. */
  764. static int
  765. fmod_rangeTest(void *args)
  766. {
  767. Uint32 i;
  768. double test_value = 0.0;
  769. SDLTest_AssertPass("Fmod: Testing a range of %u values with steps of %u",
  770. RANGE_TEST_ITERATIONS,
  771. RANGE_TEST_STEP);
  772. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  773. double result;
  774. /* These are tested elsewhere */
  775. if (isnan(test_value) || isinf(test_value)) {
  776. continue;
  777. }
  778. /* Only log failures to save performances */
  779. result = SDL_fmod(test_value, 1.0);
  780. if (0.0 != result) {
  781. SDLTest_AssertCheck(SDL_FALSE,
  782. "Fmod(%.1f,%.1f), expected %.1f, got %.1f",
  783. test_value, 1.0, 0.0, result);
  784. return TEST_ABORTED;
  785. }
  786. }
  787. return TEST_COMPLETED;
  788. }
  789. /* SDL_exp tests functions */
  790. /**
  791. * \brief Checks positive and negative infinity.
  792. */
  793. static int
  794. exp_infCases(void *args)
  795. {
  796. double result;
  797. result = SDL_exp(INFINITY);
  798. SDLTest_AssertCheck(INFINITY == result,
  799. "Exp(%f), expected %f, got %f",
  800. INFINITY, INFINITY, result);
  801. result = SDL_exp(-INFINITY);
  802. SDLTest_AssertCheck(0.0 == result,
  803. "Exp(%f), expected %f, got %f",
  804. -INFINITY, 0.0, result);
  805. return TEST_COMPLETED;
  806. }
  807. /**
  808. * \brief Checks positive and negative zero.
  809. */
  810. static int
  811. exp_zeroCases(void *args)
  812. {
  813. const d_to_d zero_cases[] = {
  814. { 0.0, 1.0 },
  815. { -0.0, 1.0 }
  816. };
  817. return helper_dtod("Exp", SDL_exp, zero_cases, SDL_arraysize(zero_cases));
  818. }
  819. /**
  820. * \brief Checks for overflow.
  821. *
  822. * This test is skipped for double types larger than 64 bits.
  823. */
  824. static int
  825. exp_overflowCase(void *args)
  826. {
  827. double result;
  828. if (sizeof(double) > 8) {
  829. return TEST_SKIPPED;
  830. }
  831. result = SDL_exp(710.0);
  832. SDLTest_AssertCheck(isinf(result),
  833. "Exp(%f), expected %f, got %f",
  834. 710.0, INFINITY, result);
  835. return TEST_COMPLETED;
  836. }
  837. /**
  838. * \brief Checks the base case of 1.0.
  839. */
  840. static int
  841. exp_baseCase(void *args)
  842. {
  843. const double result = SDL_exp(1.0);
  844. SDLTest_AssertCheck(EULER == result,
  845. "Exp(%f), expected %f, got %f",
  846. 1.0, EULER, result);
  847. return TEST_COMPLETED;
  848. }
  849. /**
  850. * \brief Checks a set of regular cases.
  851. */
  852. static int
  853. exp_regularCases(void *args)
  854. {
  855. /* Hexadecimal floating constants are not supported on C89 compilers */
  856. const d_to_d regular_cases[] = {
  857. { -101.0, 1.36853947117385291381565719268793547578002532127613087E-44 },
  858. { -15.73, 0.00000014741707833928422931856502906683425990763681 },
  859. { -1.0, 0.36787944117144233402427744294982403516769409179688 },
  860. { -0.5, 0.60653065971263342426311737654032185673713684082031 },
  861. { 0.5, 1.64872127070012819416433558217249810695648193359375 },
  862. { 2.25, 9.48773583635852624240669683786109089851379394531250 },
  863. { 34.125, 661148770968660.375 },
  864. { 112.89, 10653788283588960962604279261058893737879589093376.0 },
  865. { 539.483, 1970107755334319939701129934673541628417235942656909222826926175622435588279443011110464355295725187195188154768877850257012251677751742837992843520967922303961718983154427294786640886286983037548604937796221048661733679844353544028160.0 },
  866. };
  867. return helper_dtod("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases));
  868. }
  869. /* SDL_log tests functions */
  870. /**
  871. * \brief Checks limits (zeros and positive infinity).
  872. */
  873. static int
  874. log_limitCases(void *args)
  875. {
  876. double result;
  877. result = SDL_log(INFINITY);
  878. SDLTest_AssertCheck(INFINITY == result,
  879. "Log(%f), expected %f, got %f",
  880. INFINITY, INFINITY, result);
  881. result = SDL_log(0.0);
  882. SDLTest_AssertCheck(-INFINITY == result,
  883. "Log(%f), expected %f, got %f",
  884. 0.0, -INFINITY, result);
  885. result = SDL_log(-0.0);
  886. SDLTest_AssertCheck(-INFINITY == result,
  887. "Log(%f), expected %f, got %f",
  888. -0.0, -INFINITY, result);
  889. return TEST_COMPLETED;
  890. }
  891. /**
  892. * \brief Checks some base cases.
  893. */
  894. static int
  895. log_baseCases(void *args)
  896. {
  897. double result;
  898. result = SDL_log(1.0);
  899. SDLTest_AssertCheck(0.0 == result,
  900. "Log(%f), expected %f, got %f",
  901. 1.0, 0.0, result);
  902. result = SDL_log(EULER);
  903. SDLTest_AssertCheck(1.0 == result,
  904. "Log(%f), expected %f, got %f",
  905. EULER, 1.0, result);
  906. return TEST_COMPLETED;
  907. }
  908. /**
  909. * \brief Checks the nan cases.
  910. */
  911. static int
  912. log_nanCases(void *args)
  913. {
  914. double result;
  915. result = SDL_log(NAN);
  916. SDLTest_AssertCheck(isnan(result),
  917. "Log(%f), expected %f, got %f",
  918. NAN, NAN, result);
  919. result = SDL_log(-1234.5678);
  920. SDLTest_AssertCheck(isnan(result),
  921. "Log(%f), expected %f, got %f",
  922. -1234.5678, NAN, result);
  923. return TEST_COMPLETED;
  924. }
  925. /**
  926. * \brief Checks a set of regular cases.
  927. */
  928. static int
  929. log_regularCases(void *args)
  930. {
  931. const d_to_d regular_cases[] = {
  932. { 5.0, 1.60943791243410028179994242236716672778129577636718750 },
  933. { 10.0, 2.302585092994045901093613792909309267997741699218750 },
  934. { 56.32, 4.031049711849786554296315443934872746467590332031250 },
  935. { 789.123, 6.670922202231861497523368598194792866706848144531250 },
  936. { 2734.876324, 7.91384149408957959792587644187733530998229980468750 }
  937. };
  938. return helper_dtod("Log", SDL_log, regular_cases, SDL_arraysize(regular_cases));
  939. }
  940. /* SDL_log10 tests functions */
  941. /**
  942. * \brief Checks limits (zeros and positive infinity).
  943. */
  944. static int
  945. log10_limitCases(void *args)
  946. {
  947. double result;
  948. result = SDL_log10(INFINITY);
  949. SDLTest_AssertCheck(INFINITY == result,
  950. "Log10(%f), expected %f, got %f",
  951. INFINITY, INFINITY, result);
  952. result = SDL_log10(0.0);
  953. SDLTest_AssertCheck(-INFINITY == result,
  954. "Log10(%f), expected %f, got %f",
  955. 0.0, -INFINITY, result);
  956. result = SDL_log10(-0.0);
  957. SDLTest_AssertCheck(-INFINITY == result,
  958. "Log10(%f), expected %f, got %f",
  959. -0.0, -INFINITY, result);
  960. return TEST_COMPLETED;
  961. }
  962. /**
  963. * \brief Checks some base cases.
  964. */
  965. static int
  966. log10_baseCases(void *args)
  967. {
  968. const d_to_d base_cases[] = {
  969. { 1.0, 0.0 },
  970. { 10.0, 1.0 },
  971. { 100.0, 2.0 },
  972. { 1000.0, 3.0 },
  973. { 10000.0, 4.0 },
  974. { 100000.0, 5.0 },
  975. { 1000000.0, 6.0 },
  976. { 10000000.0, 7.0 },
  977. { 100000000.0, 8.0 },
  978. { 1000000000.0, 9.0 },
  979. };
  980. return helper_dtod("Log10", SDL_log10, base_cases, SDL_arraysize(base_cases));
  981. }
  982. /**
  983. * \brief Checks the nan cases.
  984. */
  985. static int
  986. log10_nanCases(void *args)
  987. {
  988. double result;
  989. result = SDL_log10(NAN);
  990. SDLTest_AssertCheck(isnan(result),
  991. "Log10(%f), expected %f, got %f",
  992. NAN, NAN, result);
  993. result = SDL_log10(-1234.5678);
  994. SDLTest_AssertCheck(isnan(result),
  995. "Log10(%f), expected %f, got %f",
  996. -1234.5678, NAN, result);
  997. return TEST_COMPLETED;
  998. }
  999. /**
  1000. * \brief Checks a set of regular cases.
  1001. */
  1002. static int
  1003. log10_regularCases(void *args)
  1004. {
  1005. const d_to_d regular_cases[] = {
  1006. { 5.0, 0.698970004336018857493684208748163655400276184082031250 },
  1007. { 12.5, 1.09691001300805646145875016372883692383766174316406250 },
  1008. { 56.32, 1.750662646134055755453573510749265551567077636718750 },
  1009. { 789.123, 2.8971447016351858927407647570362314581871032714843750 },
  1010. { 2734.876324, 3.436937691540090433761633903486654162406921386718750 }
  1011. };
  1012. return helper_dtod("Log10", SDL_log10, regular_cases, SDL_arraysize(regular_cases));
  1013. }
  1014. /* SDL_pow tests functions */
  1015. /* Tests with positive and negative infinities as exponents */
  1016. /**
  1017. * \brief Checks the cases where the base is negative one and the exponent is infinity.
  1018. */
  1019. static int
  1020. pow_baseNOneExpInfCases(void *args)
  1021. {
  1022. double result;
  1023. result = SDL_pow(-1.0, INFINITY);
  1024. SDLTest_AssertCheck(1.0 == result,
  1025. "Pow(%f,%f), expected %f, got %f",
  1026. -1.0, INFINITY, 1.0, result);
  1027. result = SDL_pow(-1.0, -INFINITY);
  1028. SDLTest_AssertCheck(1.0 == result,
  1029. "Pow(%f,%f), expected %f, got %f",
  1030. -1.0, -INFINITY, 1.0, result);
  1031. return TEST_COMPLETED;
  1032. }
  1033. /**
  1034. * \brief Checks the case where the base is zero and the exponent is negative infinity.
  1035. */
  1036. static int
  1037. pow_baseZeroExpNInfCases(void *args)
  1038. {
  1039. double result;
  1040. result = SDL_pow(0.0, -INFINITY);
  1041. SDLTest_AssertCheck(INFINITY == result,
  1042. "Pow(%f,%f), expected %f, got %f",
  1043. 0.0, -INFINITY, INFINITY, result);
  1044. result = SDL_pow(-0.0, -INFINITY);
  1045. SDLTest_AssertCheck(INFINITY == result,
  1046. "Pow(%f,%f), expected %f, got %f",
  1047. -0.0, -INFINITY, INFINITY, result);
  1048. return TEST_COMPLETED;
  1049. }
  1050. /**
  1051. * \brief Checks the remaining cases where the exponent is infinity.
  1052. */
  1053. static int
  1054. pow_expInfCases(void *args)
  1055. {
  1056. double result;
  1057. result = SDL_pow(0.5, INFINITY);
  1058. SDLTest_AssertCheck(0.0 == result,
  1059. "Pow(%f,%f), expected %f, got %f",
  1060. 0.5, INFINITY, 0.0, result);
  1061. result = SDL_pow(1.5, INFINITY);
  1062. SDLTest_AssertCheck(INFINITY == result,
  1063. "Pow(%f,%f), expected %f, got %f",
  1064. 1.5, INFINITY, INFINITY, result);
  1065. result = SDL_pow(0.5, -INFINITY);
  1066. SDLTest_AssertCheck(INFINITY == result,
  1067. "Pow(%f,%f), expected %f, got %f",
  1068. 0.5, INFINITY, INFINITY, result);
  1069. result = SDL_pow(1.5, -INFINITY);
  1070. SDLTest_AssertCheck(0.0 == result,
  1071. "Pow(%f,%f), expected %f, got %f",
  1072. 1.5, -INFINITY, 0.0, result);
  1073. return TEST_COMPLETED;
  1074. }
  1075. /* Tests with positive and negative infinities as base */
  1076. /**
  1077. * \brief Checks the cases with positive infinity as base.
  1078. */
  1079. static int
  1080. pow_basePInfCases(void *args)
  1081. {
  1082. double result;
  1083. result = SDL_pow(INFINITY, -3.0);
  1084. SDLTest_AssertCheck(0.0 == result,
  1085. "Pow(%f,%f), expected %f, got %f",
  1086. INFINITY, -3.0, 0.0, result);
  1087. result = SDL_pow(INFINITY, 2.0);
  1088. SDLTest_AssertCheck(INFINITY == result,
  1089. "Pow(%f,%f), expected %f, got %f",
  1090. INFINITY, 2.0, INFINITY, result);
  1091. result = SDL_pow(INFINITY, -2.12345);
  1092. SDLTest_AssertCheck(0.0 == result,
  1093. "Pow(%f,%f), expected %f, got %f",
  1094. INFINITY, -2.12345, 0.0, result);
  1095. result = SDL_pow(INFINITY, 3.1345);
  1096. SDLTest_AssertCheck(INFINITY == result,
  1097. "Pow(%f,%f), expected %f, got %f",
  1098. INFINITY, 3.12345, INFINITY, result);
  1099. return TEST_COMPLETED;
  1100. }
  1101. /**
  1102. * \brief Checks the cases with negative infinity as base.
  1103. */
  1104. static int
  1105. pow_baseNInfCases(void *args)
  1106. {
  1107. double result;
  1108. result = SDL_pow(-INFINITY, -3.0);
  1109. SDLTest_AssertCheck(-0.0 == result,
  1110. "Pow(%f,%f), expected %f, got %f",
  1111. -INFINITY, -3.0, -0.0, result);
  1112. result = SDL_pow(-INFINITY, -2.0);
  1113. SDLTest_AssertCheck(0.0 == result,
  1114. "Pow(%f,%f), expected %f, got %f",
  1115. -INFINITY, -2.0, 0.0, result);
  1116. result = SDL_pow(-INFINITY, -5.5);
  1117. SDLTest_AssertCheck(0.0 == result,
  1118. "Pow(%f,%f), expected %f, got %f",
  1119. -INFINITY, -5.5, 0.0, result);
  1120. result = SDL_pow(-INFINITY, 3.0);
  1121. SDLTest_AssertCheck(-INFINITY == result,
  1122. "Pow(%f,%f), expected %f, got %f",
  1123. -INFINITY, 3.0, -INFINITY, result);
  1124. result = SDL_pow(-INFINITY, 2.0);
  1125. SDLTest_AssertCheck(INFINITY == result,
  1126. "Pow(%f,%f), expected %f, got %f",
  1127. -INFINITY, 2.0, INFINITY, result);
  1128. result = SDL_pow(-INFINITY, 5.5);
  1129. SDLTest_AssertCheck(INFINITY == result,
  1130. "Pow(%f,%f), expected %f, got %f",
  1131. -INFINITY, 5.5, INFINITY, result);
  1132. return TEST_COMPLETED;
  1133. }
  1134. /* Tests related to nan */
  1135. /**
  1136. * \brief Checks the case where the base is finite and negative and exponent is finite and non-integer.
  1137. */
  1138. static int
  1139. pow_badOperationCase(void *args)
  1140. {
  1141. const double result = SDL_pow(-2.0, 4.2);
  1142. SDLTest_AssertCheck(isnan(result),
  1143. "Pow(%f,%f), expected %f, got %f",
  1144. -2.0, 4.2, NAN, result);
  1145. return TEST_COMPLETED;
  1146. }
  1147. /**
  1148. * \brief Checks the case where the exponent is nan but the base is 1.
  1149. */
  1150. static int
  1151. pow_base1ExpNanCase(void *args)
  1152. {
  1153. const double result = SDL_pow(1.0, NAN);
  1154. SDLTest_AssertCheck(1.0 == result,
  1155. "Pow(%f,%f), expected %f, got %f",
  1156. 1.0, NAN, 1.0, result);
  1157. return TEST_COMPLETED;
  1158. }
  1159. /**
  1160. * \brief Checks the cases where the base is nan but the exponent is 0.
  1161. */
  1162. static int
  1163. pow_baseNanExp0Cases(void *args)
  1164. {
  1165. double result;
  1166. result = SDL_pow(NAN, 0.0);
  1167. SDLTest_AssertCheck(1.0 == result,
  1168. "Pow(%f,%f), expected %f, got %f",
  1169. NAN, 0.0, 1.0, result);
  1170. result = SDL_pow(NAN, -0.0);
  1171. SDLTest_AssertCheck(1.0 == result,
  1172. "Pow(%f,%f), expected %f, got %f",
  1173. NAN, -0.0, 1.0, result);
  1174. return TEST_COMPLETED;
  1175. }
  1176. /**
  1177. * \brief Checks the cases where either argument is nan.
  1178. */
  1179. static int
  1180. pow_nanArgsCases(void *args)
  1181. {
  1182. double result;
  1183. result = SDL_pow(7.8, NAN);
  1184. SDLTest_AssertCheck(isnan(result),
  1185. "Pow(%f,%f), expected %f, got %f",
  1186. 7.8, NAN, NAN, result);
  1187. result = SDL_pow(NAN, 10.0);
  1188. SDLTest_AssertCheck(isnan(result),
  1189. "Pow(%f,%f), expected %f, got %f",
  1190. NAN, 10.0, NAN, result);
  1191. result = SDL_pow(NAN, NAN);
  1192. SDLTest_AssertCheck(isnan(result),
  1193. "Pow(%f,%f), expected %f, got %f",
  1194. NAN, NAN, NAN, result);
  1195. return TEST_COMPLETED;
  1196. }
  1197. /* Tests with positive and negative zeros as base */
  1198. /**
  1199. * \brief Checks cases with negative zero as base and an odd exponent.
  1200. */
  1201. static int
  1202. pow_baseNZeroExpOddCases(void *args)
  1203. {
  1204. double result;
  1205. result = SDL_pow(-0.0, -3.0);
  1206. SDLTest_AssertCheck(-INFINITY == result,
  1207. "Pow(%f,%f), expected %f, got %f",
  1208. -0.0, -3.0, -INFINITY, result);
  1209. result = SDL_pow(-0.0, 3.0);
  1210. SDLTest_AssertCheck(-0.0 == result,
  1211. "Pow(%f,%f), expected %f, got %f",
  1212. -0.0, 3.0, -0.0, result);
  1213. return TEST_COMPLETED;
  1214. }
  1215. /**
  1216. * \brief Checks cases with positive zero as base and an odd exponent.
  1217. */
  1218. static int
  1219. pow_basePZeroExpOddCases(void *args)
  1220. {
  1221. double result;
  1222. result = SDL_pow(0.0, -5.0);
  1223. SDLTest_AssertCheck(INFINITY == result,
  1224. "Pow(%f,%f), expected %f, got %f",
  1225. 0.0, -5.0, INFINITY, result);
  1226. result = SDL_pow(0.0, 5.0);
  1227. SDLTest_AssertCheck(0.0 == result,
  1228. "Pow(%f,%f), expected %f, got %f",
  1229. 0.0, 5.0, 0.0, result);
  1230. return TEST_COMPLETED;
  1231. }
  1232. /**
  1233. * \brief Checks cases with negative zero as base and the exponent is finite and even or non-integer.
  1234. */
  1235. static int
  1236. pow_baseNZeroCases(void *args)
  1237. {
  1238. double result;
  1239. result = SDL_pow(-0.0, -3.5);
  1240. SDLTest_AssertCheck(INFINITY == result,
  1241. "Pow(%f,%f), expected %f, got %f",
  1242. -0.0, -3.5, INFINITY, result);
  1243. result = SDL_pow(-0.0, -4.0);
  1244. SDLTest_AssertCheck(INFINITY == result,
  1245. "Pow(%f,%f), expected %f, got %f",
  1246. -0.0, -4.0, INFINITY, result);
  1247. result = SDL_pow(-0.0, 3.5);
  1248. SDLTest_AssertCheck(0.0 == result,
  1249. "Pow(%f,%f), expected %f, got %f",
  1250. -0.0, 3.5, 0.0, result);
  1251. result = SDL_pow(-0.0, 4.0);
  1252. SDLTest_AssertCheck(0.0 == result,
  1253. "Pow(%f,%f), expected %f, got %f",
  1254. -0.0, 4.0, 0.0, result);
  1255. return TEST_COMPLETED;
  1256. }
  1257. /**
  1258. * \brief Checks cases with positive zero as base and the exponent is finite and even or non-integer.
  1259. */
  1260. static int
  1261. pow_basePZeroCases(void *args)
  1262. {
  1263. double result;
  1264. result = SDL_pow(0.0, -3.5);
  1265. SDLTest_AssertCheck(INFINITY == result,
  1266. "Pow(%f,%f), expected %f, got %f",
  1267. 0.0, -3.5, INFINITY, result);
  1268. result = SDL_pow(0.0, -4.0);
  1269. SDLTest_AssertCheck(INFINITY == result,
  1270. "Pow(%f,%f), expected %f, got %f",
  1271. 0.0, -4.0, INFINITY, result);
  1272. result = SDL_pow(0.0, 3.5);
  1273. SDLTest_AssertCheck(0.0 == result,
  1274. "Pow(%f,%f), expected %f, got %f",
  1275. 0.0, 3.5, 0.0, result);
  1276. result = SDL_pow(0.0, 4.0);
  1277. SDLTest_AssertCheck(0.0 == result,
  1278. "Pow(%f,%f), expected %f, got %f",
  1279. 0.0, 4.0, 0.0, result);
  1280. return TEST_COMPLETED;
  1281. }
  1282. /* Remaining tests */
  1283. /**
  1284. * \brief Checks a set of regular values.
  1285. */
  1286. static int
  1287. pow_regularCases(void *args)
  1288. {
  1289. const dd_to_d regular_cases[] = {
  1290. { -391.25, -2.0, 0.00000653267870448815438463212659780943170062528224661946296691894531250 },
  1291. { -72.3, 12.0, 20401381050275984310272.0 },
  1292. { -5.0, 3.0, -125.0 },
  1293. { 3.0, 2.5, 15.58845726811989607085706666111946105957031250 },
  1294. { 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 },
  1295. { 478.972, 12.125, 315326359630449587856007411793920.0 }
  1296. };
  1297. return helper_ddtod("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases));
  1298. }
  1299. /**
  1300. * \brief Checks the powers of two from 1 to 8.
  1301. */
  1302. static int
  1303. pow_powerOfTwo(void *args)
  1304. {
  1305. const dd_to_d power_of_two_cases[] = {
  1306. { 2.0, 1, 2.0 },
  1307. { 2.0, 2, 4.0 },
  1308. { 2.0, 3, 8.0 },
  1309. { 2.0, 4, 16.0 },
  1310. { 2.0, 5, 32.0 },
  1311. { 2.0, 6, 64.0 },
  1312. { 2.0, 7, 128.0 },
  1313. { 2.0, 8, 256.0 },
  1314. };
  1315. return helper_ddtod("Pow", SDL_pow, power_of_two_cases, SDL_arraysize(power_of_two_cases));
  1316. }
  1317. /**
  1318. * \brief Checks a range of values between 0 and UINT32_MAX to the power of 0.
  1319. */
  1320. static int
  1321. pow_rangeTest(void *args)
  1322. {
  1323. Uint32 i;
  1324. double test_value = 0.0;
  1325. SDLTest_AssertPass("Pow: Testing a range of %u values with steps of %u",
  1326. RANGE_TEST_ITERATIONS,
  1327. RANGE_TEST_STEP);
  1328. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1329. double result;
  1330. /* These are tested elsewhere */
  1331. if (isnan(test_value) || isinf(test_value)) {
  1332. continue;
  1333. }
  1334. /* Only log failures to save performances */
  1335. result = SDL_pow(test_value, 0.0);
  1336. if (result != 1.0) {
  1337. SDLTest_AssertCheck(SDL_FALSE,
  1338. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1339. test_value, 1.0, 1.0, result);
  1340. return TEST_ABORTED;
  1341. }
  1342. result = SDL_pow(test_value, -0.0);
  1343. if (result != 1.0) {
  1344. SDLTest_AssertCheck(SDL_FALSE,
  1345. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1346. test_value, -0.0, 1.0, result);
  1347. return TEST_ABORTED;
  1348. }
  1349. }
  1350. return TEST_COMPLETED;
  1351. }
  1352. /* SDL_sqrt tests functions */
  1353. /**
  1354. * \brief Checks for positive infinity.
  1355. */
  1356. static int
  1357. sqrt_infCase(void *args)
  1358. {
  1359. const double result = SDL_sqrt(INFINITY);
  1360. SDLTest_AssertCheck(INFINITY == result,
  1361. "Sqrt(%f), expected %f, got %f",
  1362. INFINITY, INFINITY, result);
  1363. return TEST_COMPLETED;
  1364. }
  1365. /**
  1366. * \brief Checks for the nan case.
  1367. */
  1368. static int
  1369. sqrt_nanCase(void *args)
  1370. {
  1371. const double result = SDL_sqrt(NAN);
  1372. SDLTest_AssertCheck(isnan(result),
  1373. "Sqrt(%f), expected %f, got %f",
  1374. NAN, NAN, result);
  1375. return TEST_COMPLETED;
  1376. }
  1377. /**
  1378. * \brief Checks for out of domain values (<0).
  1379. */
  1380. static int
  1381. sqrt_outOfDomainCases(void *args)
  1382. {
  1383. double result;
  1384. result = SDL_sqrt(-1.0);
  1385. SDLTest_AssertCheck(isnan(result),
  1386. "Sqrt(%f), expected %f, got %f",
  1387. -1.0, NAN, result);
  1388. result = SDL_sqrt(-12345.6789);
  1389. SDLTest_AssertCheck(isnan(result),
  1390. "Sqrt(%f), expected %f, got %f",
  1391. -12345.6789, NAN, result);
  1392. result = SDL_sqrt(-INFINITY);
  1393. SDLTest_AssertCheck(isnan(result),
  1394. "Sqrt(%f), expected %f, got %f",
  1395. -INFINITY, NAN, result);
  1396. return TEST_COMPLETED;
  1397. }
  1398. /**
  1399. * \brief Checks a set of base cases.
  1400. */
  1401. static int
  1402. sqrt_baseCases(void *args)
  1403. {
  1404. const d_to_d base_cases[] = {
  1405. { -0.0, -0.0 },
  1406. { 0.0, 0.0 },
  1407. { 1.0, 1.0 }
  1408. };
  1409. return helper_dtod("Sqrt", SDL_sqrt, base_cases, SDL_arraysize(base_cases));
  1410. }
  1411. /**
  1412. * \brief Checks a set of regular cases.
  1413. */
  1414. static int
  1415. sqrt_regularCases(void *args)
  1416. {
  1417. const d_to_d regular_cases[] = {
  1418. { 4.0, 2.0 },
  1419. { 9.0, 3.0 },
  1420. { 27.2, 5.21536192416211896727418206864967942237854003906250 },
  1421. { 240.250, 15.5 },
  1422. { 1337.0, 36.565010597564445049556525191292166709899902343750 },
  1423. { 2887.12782400000014604302123188972473144531250, 53.732 },
  1424. { 65600.0156250, 256.125 }
  1425. };
  1426. return helper_dtod("Sqrt", SDL_sqrt, regular_cases, SDL_arraysize(regular_cases));
  1427. }
  1428. /* SDL_scalbn tests functions */
  1429. /**
  1430. * \brief Checks for positive and negative infinity arg.
  1431. */
  1432. static int
  1433. scalbn_infCases(void *args)
  1434. {
  1435. double result;
  1436. result = SDL_scalbn(INFINITY, 1);
  1437. SDLTest_AssertCheck(INFINITY == result,
  1438. "Scalbn(%f,%d), expected %f, got %f",
  1439. INFINITY, 1, INFINITY, result);
  1440. result = SDL_scalbn(-INFINITY, 1);
  1441. SDLTest_AssertCheck(-INFINITY == result,
  1442. "Scalbn(%f,%d), expected %f, got %f",
  1443. -INFINITY, 1, -INFINITY, result);
  1444. return TEST_COMPLETED;
  1445. }
  1446. /**
  1447. * \brief Checks for positive and negative zero arg.
  1448. */
  1449. static int
  1450. scalbn_baseZeroCases(void *args)
  1451. {
  1452. double result;
  1453. result = SDL_scalbn(0.0, 1);
  1454. SDLTest_AssertCheck(0.0 == result,
  1455. "Scalbn(%f,%d), expected %f, got %f",
  1456. 0.0, 1, 0.0, result);
  1457. result = SDL_scalbn(-0.0, 1);
  1458. SDLTest_AssertCheck(-0.0 == result,
  1459. "Scalbn(%f,%d), expected %f, got %f",
  1460. -0.0, 1, -0.0, result);
  1461. return TEST_COMPLETED;
  1462. }
  1463. /**
  1464. * \brief Checks for zero exp.
  1465. */
  1466. static int
  1467. scalbn_expZeroCase(void *args)
  1468. {
  1469. const double result = SDL_scalbn(42.0, 0);
  1470. SDLTest_AssertCheck(42.0 == result,
  1471. "Scalbn(%f,%d), expected %f, got %f",
  1472. 42.0, 0, 42.0, result);
  1473. return TEST_COMPLETED;
  1474. }
  1475. /**
  1476. * \brief Checks for NAN arg.
  1477. */
  1478. static int
  1479. scalbn_nanCase(void *args)
  1480. {
  1481. const double result = SDL_scalbn(NAN, 2);
  1482. SDLTest_AssertCheck(isnan(result),
  1483. "Scalbn(%f,%d), expected %f, got %f",
  1484. NAN, 2, NAN, result);
  1485. return TEST_COMPLETED;
  1486. }
  1487. /**
  1488. * \brief Checks a set of regular values.
  1489. *
  1490. * This test depends on SDL_pow functionning.
  1491. */
  1492. static int
  1493. scalbn_regularCases(void *args)
  1494. {
  1495. double result, expected;
  1496. result = SDL_scalbn(2.0, 2);
  1497. expected = 2.0 * SDL_pow(FLT_RADIX, 2);
  1498. SDLTest_AssertCheck(result == expected,
  1499. "Scalbn(%f,%d), expected %f, got %f",
  1500. 2.0, 2, expected, result);
  1501. result = SDL_scalbn(1.0, 13);
  1502. expected = 1.0 * SDL_pow(FLT_RADIX, 13);
  1503. SDLTest_AssertCheck(result == expected,
  1504. "Scalbn(%f,%d), expected %f, got %f",
  1505. 1.0, 13, expected, result);
  1506. result = SDL_scalbn(2.0, -5);
  1507. expected = 2.0 * SDL_pow(FLT_RADIX, -5);
  1508. SDLTest_AssertCheck(result == expected,
  1509. "Scalbn(%f,%d), expected %f, got %f",
  1510. 2.0, -5, expected, result);
  1511. result = SDL_scalbn(-1.0, -13);
  1512. expected = -1.0 * SDL_pow(FLT_RADIX, -13);
  1513. SDLTest_AssertCheck(result == expected,
  1514. "Scalbn(%f,%d), expected %f, got %f",
  1515. -1.0, -13, expected, result);
  1516. return TEST_COMPLETED;
  1517. }
  1518. /* SDL_cos tests functions */
  1519. /**
  1520. * \brief Checks positive and negative infinity.
  1521. */
  1522. static int
  1523. cos_infCases(void *args)
  1524. {
  1525. double result;
  1526. result = SDL_cos(INFINITY);
  1527. SDLTest_AssertCheck(isnan(result),
  1528. "Cos(%f), expected %f, got %f",
  1529. INFINITY, NAN, result);
  1530. result = SDL_cos(-INFINITY);
  1531. SDLTest_AssertCheck(isnan(result),
  1532. "Cos(%f), expected %f, got %f",
  1533. -INFINITY, NAN, result);
  1534. return TEST_COMPLETED;
  1535. }
  1536. /**
  1537. * \brief Checks for nan.
  1538. */
  1539. static int
  1540. cos_nanCase(void *args)
  1541. {
  1542. const double result = SDL_cos(NAN);
  1543. SDLTest_AssertCheck(isnan(result),
  1544. "Cos(%f), expected %f, got %f",
  1545. NAN, NAN, result);
  1546. return TEST_COMPLETED;
  1547. }
  1548. /**
  1549. * \brief Checks a set of regular values.
  1550. */
  1551. static int
  1552. cos_regularCases(void *args)
  1553. {
  1554. const d_to_d regular_cases[] = {
  1555. { -M_PI, -1.0 },
  1556. { -0.0, 1.0 },
  1557. { 0.0, 1.0 },
  1558. { M_PI, -1.0 }
  1559. };
  1560. return helper_dtod("Cos", SDL_cos, regular_cases, SDL_arraysize(regular_cases));
  1561. }
  1562. /**
  1563. * \brief Checks cosine precision for the first 10 decimals.
  1564. */
  1565. static int
  1566. cos_precisionTest(void *args)
  1567. {
  1568. const d_to_d precision_cases[] = {
  1569. { M_PI * 1.0 / 10.0, 9510565162.0 },
  1570. { M_PI * 2.0 / 10.0, 8090169943.0 },
  1571. { M_PI * 3.0 / 10.0, 5877852522.0 },
  1572. { M_PI * 4.0 / 10.0, 3090169943.0 },
  1573. { M_PI * 5.0 / 10.0, 0.0 },
  1574. { M_PI * 6.0 / 10.0, -3090169943.0 },
  1575. { M_PI * 7.0 / 10.0, -5877852522.0 },
  1576. { M_PI * 8.0 / 10.0, -8090169943.0 },
  1577. { M_PI * 9.0 / 10.0, -9510565162.0 },
  1578. { M_PI * -1.0 / 10.0, 9510565162.0 },
  1579. { M_PI * -2.0 / 10.0, 8090169943.0 },
  1580. { M_PI * -3.0 / 10.0, 5877852522.0 },
  1581. { M_PI * -4.0 / 10.0, 3090169943.0 },
  1582. { M_PI * -5.0 / 10.0, 0.0 },
  1583. { M_PI * -6.0 / 10.0, -3090169943.0 },
  1584. { M_PI * -7.0 / 10.0, -5877852522.0 },
  1585. { M_PI * -8.0 / 10.0, -8090169943.0 },
  1586. { M_PI * -9.0 / 10.0, -9510565162.0 }
  1587. };
  1588. return helper_dtod_approx("Cos", SDL_cos, precision_cases, SDL_arraysize(precision_cases));
  1589. }
  1590. /**
  1591. * \brief Checks a range of values between 0 and UINT32_MAX.
  1592. */
  1593. static int
  1594. cos_rangeTest(void *args)
  1595. {
  1596. Uint32 i;
  1597. double test_value = 0.0;
  1598. SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %u",
  1599. RANGE_TEST_ITERATIONS,
  1600. RANGE_TEST_STEP);
  1601. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1602. double result;
  1603. /* These are tested elsewhere */
  1604. if (isnan(test_value) || isinf(test_value)) {
  1605. continue;
  1606. }
  1607. /* Only log failures to save performances */
  1608. result = SDL_cos(test_value);
  1609. if (result < -1.0 || result > 1.0) {
  1610. SDLTest_AssertCheck(SDL_FALSE,
  1611. "Cos(%.1f), expected [%.1f,%.1f], got %.1f",
  1612. test_value, -1.0, 1.0, result);
  1613. return TEST_ABORTED;
  1614. }
  1615. }
  1616. return TEST_COMPLETED;
  1617. }
  1618. /* SDL_sin tests functions */
  1619. /**
  1620. * \brief Checks positive and negative infinity.
  1621. */
  1622. static int
  1623. sin_infCases(void *args)
  1624. {
  1625. double result;
  1626. result = SDL_sin(INFINITY);
  1627. SDLTest_AssertCheck(isnan(result),
  1628. "Sin(%f), expected %f, got %f",
  1629. INFINITY, NAN, result);
  1630. result = SDL_sin(-INFINITY);
  1631. SDLTest_AssertCheck(isnan(result),
  1632. "Sin(%f), expected %f, got %f",
  1633. -INFINITY, NAN, result);
  1634. return TEST_COMPLETED;
  1635. }
  1636. /**
  1637. * \brief Checks for nan.
  1638. */
  1639. static int
  1640. sin_nanCase(void *args)
  1641. {
  1642. const double result = SDL_sin(NAN);
  1643. SDLTest_AssertCheck(isnan(result),
  1644. "Sin(%f), expected %f, got %f",
  1645. NAN, NAN, result);
  1646. return TEST_COMPLETED;
  1647. }
  1648. /**
  1649. * \brief Checks a set of regular values.
  1650. */
  1651. static int
  1652. sin_regularCases(void *args)
  1653. {
  1654. const d_to_d regular_cases[] = {
  1655. { -M_PI / 2, -1.0 },
  1656. { -0.0, -0.0 },
  1657. { 0.0, 0.0 },
  1658. { M_PI / 2, 1.0 }
  1659. };
  1660. return helper_dtod("Sin", SDL_sin, regular_cases, SDL_arraysize(regular_cases));
  1661. }
  1662. /**
  1663. * \brief Checks sine precision for the first 10 decimals.
  1664. */
  1665. static int
  1666. sin_precisionTest(void *args)
  1667. {
  1668. const d_to_d precision_cases[] = {
  1669. { M_PI * 1.0 / 10.0, 3090169943.0 },
  1670. { M_PI * 2.0 / 10.0, 5877852522.0 },
  1671. { M_PI * 3.0 / 10.0, 8090169943.0 },
  1672. { M_PI * 4.0 / 10.0, 9510565162.0 },
  1673. { M_PI * 5.0 / 10.0, 10000000000.0 },
  1674. { M_PI * 6.0 / 10.0, 9510565162.0 },
  1675. { M_PI * 7.0 / 10.0, 8090169943.0 },
  1676. { M_PI * 8.0 / 10.0, 5877852522.0 },
  1677. { M_PI * 9.0 / 10.0, 3090169943.0 },
  1678. { M_PI * -1.0 / 10.0, -3090169943.0 },
  1679. { M_PI * -2.0 / 10.0, -5877852522.0 },
  1680. { M_PI * -3.0 / 10.0, -8090169943.0 },
  1681. { M_PI * -4.0 / 10.0, -9510565162.0 },
  1682. { M_PI * -5.0 / 10.0, -10000000000.0 },
  1683. { M_PI * -6.0 / 10.0, -9510565162.0 },
  1684. { M_PI * -7.0 / 10.0, -8090169943.0 },
  1685. { M_PI * -8.0 / 10.0, -5877852522.0 },
  1686. { M_PI * -9.0 / 10.0, -3090169943.0 }
  1687. };
  1688. return helper_dtod_approx("Sin", SDL_sin, precision_cases, SDL_arraysize(precision_cases));
  1689. }
  1690. /**
  1691. * \brief Checks a range of values between 0 and UINT32_MAX.
  1692. */
  1693. static int
  1694. sin_rangeTest(void *args)
  1695. {
  1696. Uint32 i;
  1697. double test_value = 0.0;
  1698. SDLTest_AssertPass("Sin: Testing a range of %u values with steps of %u",
  1699. RANGE_TEST_ITERATIONS,
  1700. RANGE_TEST_STEP);
  1701. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1702. double result;
  1703. /* These are tested elsewhere */
  1704. if (isnan(test_value) || isinf(test_value)) {
  1705. continue;
  1706. }
  1707. /* Only log failures to save performances */
  1708. result = SDL_sin(test_value);
  1709. if (result < -1.0 || result > 1.0) {
  1710. SDLTest_AssertCheck(SDL_FALSE,
  1711. "Sin(%.1f), expected [%.1f,%.1f], got %.1f",
  1712. test_value, -1.0, 1.0, result);
  1713. return TEST_ABORTED;
  1714. }
  1715. }
  1716. return TEST_COMPLETED;
  1717. }
  1718. /* SDL_tan tests functions */
  1719. /**
  1720. * \brief Checks positive and negative infinity.
  1721. */
  1722. static int
  1723. tan_infCases(void *args)
  1724. {
  1725. double result;
  1726. result = SDL_tan(INFINITY);
  1727. SDLTest_AssertCheck(isnan(result),
  1728. "Tan(%f), expected %f, got %f",
  1729. INFINITY, NAN, result);
  1730. result = SDL_tan(-INFINITY);
  1731. SDLTest_AssertCheck(isnan(result),
  1732. "Tan(%f), expected %f, got %f",
  1733. -INFINITY, NAN, result);
  1734. return TEST_COMPLETED;
  1735. }
  1736. /**
  1737. * \brief Checks for nan.
  1738. */
  1739. static int
  1740. tan_nanCase(void *args)
  1741. {
  1742. const double result = SDL_tan(NAN);
  1743. SDLTest_AssertCheck(isnan(result),
  1744. "Tan(%f), expected %f, got %f",
  1745. NAN, NAN, result);
  1746. return TEST_COMPLETED;
  1747. }
  1748. /**
  1749. * \brief Checks positive and negative zero.
  1750. */
  1751. static int
  1752. tan_zeroCases(void *args)
  1753. {
  1754. const d_to_d regular_cases[] = {
  1755. { -0.0, -0.0 },
  1756. { 0.0, 0.0 }
  1757. };
  1758. return helper_dtod("Tan", SDL_tan, regular_cases, SDL_arraysize(regular_cases));
  1759. }
  1760. /**
  1761. * \brief Checks tangent precision for the first 10 decimals.
  1762. */
  1763. static int
  1764. tan_precisionTest(void *args)
  1765. {
  1766. const d_to_d precision_cases[] = {
  1767. { M_PI * 1.0 / 11.0, 2936264929.0 },
  1768. { M_PI * 2.0 / 11.0, 6426609771.0 },
  1769. { M_PI * 3.0 / 11.0, 11540615205.0 },
  1770. { M_PI * 4.0 / 11.0, 21896945629.0 },
  1771. { M_PI * 5.0 / 11.0, 69551527717.0 },
  1772. { M_PI * 6.0 / 11.0, -69551527717.0 },
  1773. { M_PI * 7.0 / 11.0, -21896945629.0 },
  1774. { M_PI * 8.0 / 11.0, -11540615205.0 },
  1775. { M_PI * 9.0 / 11.0, -6426609771.0 },
  1776. { M_PI * 10.0 / 11.0, -2936264929.0 },
  1777. { M_PI * -1.0 / 11.0, -2936264929.0 },
  1778. { M_PI * -2.0 / 11.0, -6426609771.0 },
  1779. { M_PI * -3.0 / 11.0, -11540615205.0 },
  1780. { M_PI * -4.0 / 11.0, -21896945629.0 },
  1781. { M_PI * -5.0 / 11.0, -69551527717.0 },
  1782. { M_PI * -6.0 / 11.0, 69551527717.0 },
  1783. { M_PI * -7.0 / 11.0, 21896945629.0 },
  1784. { M_PI * -8.0 / 11.0, 11540615205.0 },
  1785. { M_PI * -9.0 / 11.0, 6426609771.0 },
  1786. { M_PI * -10.0 / 11.0, 2936264929.0 }
  1787. };
  1788. return helper_dtod_approx("Tan", SDL_tan, precision_cases, SDL_arraysize(precision_cases));
  1789. }
  1790. /* SDL_acos tests functions */
  1791. /**
  1792. * \brief Checks limits of the domain (+/-1).
  1793. */
  1794. static int
  1795. acos_limitCases(void *args)
  1796. {
  1797. double result;
  1798. result = SDL_acos(1.0);
  1799. SDLTest_AssertCheck(0.0 == result,
  1800. "Acos(%f), expected %f, got %f",
  1801. 1.0, 0.0, result);
  1802. result = SDL_acos(-1.0);
  1803. SDLTest_AssertCheck(M_PI == result,
  1804. "Acos(%f), expected %f, got %f",
  1805. -1.0, M_PI, result);
  1806. return TEST_COMPLETED;
  1807. }
  1808. /**
  1809. * \brief Checks values outside the domain (|x| > 1).
  1810. */
  1811. static int
  1812. acos_outOfDomainCases(void *args)
  1813. {
  1814. double result;
  1815. result = SDL_acos(1.1);
  1816. SDLTest_AssertCheck(isnan(result),
  1817. "Acos(%f), expected %f, got %f",
  1818. 1.1, NAN, result);
  1819. result = SDL_acos(-1.1);
  1820. SDLTest_AssertCheck(isnan(result),
  1821. "Acos(%f), expected %f, got %f",
  1822. -1.1, NAN, result);
  1823. return TEST_COMPLETED;
  1824. }
  1825. /**
  1826. * \brief Checks for nan.
  1827. */
  1828. static int
  1829. acos_nanCase(void *args)
  1830. {
  1831. const double result = SDL_acos(NAN);
  1832. SDLTest_AssertCheck(isnan(result),
  1833. "Acos(%f), expected %f, got %f",
  1834. NAN, NAN, result);
  1835. return TEST_COMPLETED;
  1836. }
  1837. /**
  1838. * \brief Checks arc cosine precision for the first 10 decimals.
  1839. */
  1840. static int
  1841. acos_precisionTest(void *args)
  1842. {
  1843. const d_to_d precision_cases[] = {
  1844. { 0.1, 14706289056.0 },
  1845. { 0.2, 13694384060.0 },
  1846. { 0.3, 12661036727.0 },
  1847. { 0.4, 11592794807.0 },
  1848. { 0.5, 10471975511.0 },
  1849. { 0.6, 9272952180.0 },
  1850. { 0.7, 7953988301.0 },
  1851. { 0.8, 6435011087.0 },
  1852. { 0.9, 4510268117.0 },
  1853. { -0.1, 16709637479.0 },
  1854. { -0.2, 17721542475.0 },
  1855. { -0.3, 18754889808.0 },
  1856. { -0.4, 19823131728.0 },
  1857. { -0.5, 20943951023.0 },
  1858. { -0.6, 22142974355.0 },
  1859. { -0.7, 23461938234.0 },
  1860. { -0.8, 24980915447.0 },
  1861. { -0.9, 26905658417.0 },
  1862. };
  1863. return helper_dtod_approx("Acos", SDL_acos, precision_cases, SDL_arraysize(precision_cases));
  1864. }
  1865. /* SDL_asin tests functions */
  1866. /**
  1867. * \brief Checks limits of the domain (+/-1).
  1868. */
  1869. static int
  1870. asin_limitCases(void *args)
  1871. {
  1872. double result;
  1873. result = SDL_asin(1.0);
  1874. SDLTest_AssertCheck(M_PI / 2.0 == result,
  1875. "Asin(%f), expected %f, got %f",
  1876. 1.0, M_PI / 2.0, result);
  1877. result = SDL_asin(-1.0);
  1878. SDLTest_AssertCheck(-M_PI / 2.0 == result,
  1879. "Asin(%f), expected %f, got %f",
  1880. -1.0, -M_PI / 2.0, result);
  1881. return TEST_COMPLETED;
  1882. }
  1883. /**
  1884. * \brief Checks values outside the domain (|x| > 1).
  1885. */
  1886. static int
  1887. asin_outOfDomainCases(void *args)
  1888. {
  1889. double result;
  1890. result = SDL_asin(1.1);
  1891. SDLTest_AssertCheck(isnan(result),
  1892. "Asin(%f), expected %f, got %f",
  1893. 1.1, NAN, result);
  1894. result = SDL_asin(-1.1);
  1895. SDLTest_AssertCheck(isnan(result),
  1896. "Asin(%f), expected %f, got %f",
  1897. -1.1, NAN, result);
  1898. return TEST_COMPLETED;
  1899. }
  1900. /**
  1901. * \brief Checks for nan.
  1902. */
  1903. static int
  1904. asin_nanCase(void *args)
  1905. {
  1906. const double result = SDL_asin(NAN);
  1907. SDLTest_AssertCheck(isnan(result),
  1908. "Asin(%f), expected %f, got %f",
  1909. NAN, NAN, result);
  1910. return TEST_COMPLETED;
  1911. }
  1912. /**
  1913. * \brief Checks arc sine precision for the first 10 decimals.
  1914. */
  1915. static int
  1916. asin_precisionTest(void *args)
  1917. {
  1918. const d_to_d precision_cases[] = {
  1919. { 0.9, 11197695149.0 },
  1920. { 0.8, 9272952180.0 },
  1921. { 0.7, 7753974966.0 },
  1922. { 0.6, 6435011087.0 },
  1923. { 0.5, 5235987755.0 },
  1924. { 0.4, 4115168460.0 },
  1925. { 0.3, 3046926540.0 },
  1926. { 0.2, 2013579207.0 },
  1927. { 0.1, 1001674211.0 },
  1928. { 0.0, 0.0 },
  1929. { -0.0, -0.0 },
  1930. { -0.1, -1001674211.0 },
  1931. { -0.2, -2013579207.0 },
  1932. { -0.3, -3046926540.0 },
  1933. { -0.4, -4115168460.0 },
  1934. { -0.5, -5235987755.0 },
  1935. { -0.6, -6435011087.0 },
  1936. { -0.7, -7753974966.0 },
  1937. { -0.8, -9272952180.0 },
  1938. { -0.9, -11197695149.0 }
  1939. };
  1940. return helper_dtod_approx("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases));
  1941. }
  1942. /* ================= Test References ================== */
  1943. /* SDL_floor test cases */
  1944. static const SDLTest_TestCaseReference floorTestInf = {
  1945. (SDLTest_TestCaseFp) floor_infCases, "floor_infCases",
  1946. "Check positive and negative infinity", TEST_ENABLED
  1947. };
  1948. static const SDLTest_TestCaseReference floorTestZero = {
  1949. (SDLTest_TestCaseFp) floor_zeroCases, "floor_zeroCases",
  1950. "Check positive and negative zero", TEST_ENABLED
  1951. };
  1952. static const SDLTest_TestCaseReference floorTestNan = {
  1953. (SDLTest_TestCaseFp) floor_nanCase, "floor_nanCase",
  1954. "Check the NaN special case", TEST_ENABLED
  1955. };
  1956. static const SDLTest_TestCaseReference floorTestRound = {
  1957. (SDLTest_TestCaseFp) floor_roundNumbersCases, "floor_roundNumberCases",
  1958. "Check a set of round numbers", TEST_ENABLED
  1959. };
  1960. static const SDLTest_TestCaseReference floorTestFraction = {
  1961. (SDLTest_TestCaseFp) floor_fractionCases, "floor_fractionCases",
  1962. "Check a set of fractions", TEST_ENABLED
  1963. };
  1964. static const SDLTest_TestCaseReference floorTestRange = {
  1965. (SDLTest_TestCaseFp) floor_rangeTest, "floor_rangeTest",
  1966. "Check a range of positive integer", TEST_ENABLED
  1967. };
  1968. /* SDL_ceil test cases */
  1969. static const SDLTest_TestCaseReference ceilTestInf = {
  1970. (SDLTest_TestCaseFp) ceil_infCases, "ceil_infCases",
  1971. "Check positive and negative infinity", TEST_ENABLED
  1972. };
  1973. static const SDLTest_TestCaseReference ceilTestZero = {
  1974. (SDLTest_TestCaseFp) ceil_zeroCases, "ceil_zeroCases",
  1975. "Check positive and negative zero", TEST_ENABLED
  1976. };
  1977. static const SDLTest_TestCaseReference ceilTestNan = {
  1978. (SDLTest_TestCaseFp) ceil_nanCase, "ceil_nanCase",
  1979. "Check the NaN special case", TEST_ENABLED
  1980. };
  1981. static const SDLTest_TestCaseReference ceilTestRound = {
  1982. (SDLTest_TestCaseFp) ceil_roundNumbersCases, "ceil_roundNumberCases",
  1983. "Check a set of round numbers", TEST_ENABLED
  1984. };
  1985. static const SDLTest_TestCaseReference ceilTestFraction = {
  1986. (SDLTest_TestCaseFp) ceil_fractionCases, "ceil_fractionCases",
  1987. "Check a set of fractions", TEST_ENABLED
  1988. };
  1989. static const SDLTest_TestCaseReference ceilTestRange = {
  1990. (SDLTest_TestCaseFp) ceil_rangeTest, "ceil_rangeTest",
  1991. "Check a range of positive integer", TEST_ENABLED
  1992. };
  1993. /* SDL_trunc test cases */
  1994. static const SDLTest_TestCaseReference truncTestInf = {
  1995. (SDLTest_TestCaseFp) trunc_infCases, "trunc_infCases",
  1996. "Check positive and negative infinity", TEST_ENABLED
  1997. };
  1998. static const SDLTest_TestCaseReference truncTestZero = {
  1999. (SDLTest_TestCaseFp) trunc_zeroCases, "trunc_zeroCases",
  2000. "Check positive and negative zero", TEST_ENABLED
  2001. };
  2002. static const SDLTest_TestCaseReference truncTestNan = {
  2003. (SDLTest_TestCaseFp) trunc_nanCase, "trunc_nanCase",
  2004. "Check the NaN special case", TEST_ENABLED
  2005. };
  2006. static const SDLTest_TestCaseReference truncTestRound = {
  2007. (SDLTest_TestCaseFp) trunc_roundNumbersCases, "trunc_roundNumberCases",
  2008. "Check a set of round numbers", TEST_ENABLED
  2009. };
  2010. static const SDLTest_TestCaseReference truncTestFraction = {
  2011. (SDLTest_TestCaseFp) trunc_fractionCases, "trunc_fractionCases",
  2012. "Check a set of fractions", TEST_ENABLED
  2013. };
  2014. static const SDLTest_TestCaseReference truncTestRange = {
  2015. (SDLTest_TestCaseFp) trunc_rangeTest, "trunc_rangeTest",
  2016. "Check a range of positive integer", TEST_ENABLED
  2017. };
  2018. /* SDL_round test cases */
  2019. static const SDLTest_TestCaseReference roundTestInf = {
  2020. (SDLTest_TestCaseFp) round_infCases, "round_infCases",
  2021. "Check positive and negative infinity", TEST_ENABLED
  2022. };
  2023. static const SDLTest_TestCaseReference roundTestZero = {
  2024. (SDLTest_TestCaseFp) round_zeroCases, "round_zeroCases",
  2025. "Check positive and negative zero", TEST_ENABLED
  2026. };
  2027. static const SDLTest_TestCaseReference roundTestNan = {
  2028. (SDLTest_TestCaseFp) round_nanCase, "round_nanCase",
  2029. "Check the NaN special case", TEST_ENABLED
  2030. };
  2031. static const SDLTest_TestCaseReference roundTestRound = {
  2032. (SDLTest_TestCaseFp) round_roundNumbersCases, "round_roundNumberCases",
  2033. "Check a set of round numbers", TEST_ENABLED
  2034. };
  2035. static const SDLTest_TestCaseReference roundTestFraction = {
  2036. (SDLTest_TestCaseFp) round_fractionCases, "round_fractionCases",
  2037. "Check a set of fractions", TEST_ENABLED
  2038. };
  2039. static const SDLTest_TestCaseReference roundTestRange = {
  2040. (SDLTest_TestCaseFp) round_rangeTest, "round_rangeTest",
  2041. "Check a range of positive integer", TEST_ENABLED
  2042. };
  2043. /* SDL_fabs test cases */
  2044. static const SDLTest_TestCaseReference fabsTestInf = {
  2045. (SDLTest_TestCaseFp) fabs_infCases, "fabs_infCases",
  2046. "Check positive and negative infinity", TEST_ENABLED
  2047. };
  2048. static const SDLTest_TestCaseReference fabsTestZero = {
  2049. (SDLTest_TestCaseFp) fabs_zeroCases, "fabs_zeroCases",
  2050. "Check positive and negative zero", TEST_ENABLED
  2051. };
  2052. static const SDLTest_TestCaseReference fabsTestNan = {
  2053. (SDLTest_TestCaseFp) fabs_nanCase, "fabs_nanCase",
  2054. "Check the NaN special case", TEST_ENABLED
  2055. };
  2056. static const SDLTest_TestCaseReference fabsTestRange = {
  2057. (SDLTest_TestCaseFp) fabs_rangeTest, "fabs_rangeTest",
  2058. "Check a range of positive integer", TEST_ENABLED
  2059. };
  2060. /* SDL_copysign test cases */
  2061. static const SDLTest_TestCaseReference copysignTestInf = {
  2062. (SDLTest_TestCaseFp) copysign_infCases, "copysign_infCases",
  2063. "Check positive and negative infinity", TEST_ENABLED
  2064. };
  2065. static const SDLTest_TestCaseReference copysignTestZero = {
  2066. (SDLTest_TestCaseFp) copysign_zeroCases, "copysign_zeroCases",
  2067. "Check positive and negative zero", TEST_ENABLED
  2068. };
  2069. static const SDLTest_TestCaseReference copysignTestNan = {
  2070. (SDLTest_TestCaseFp) copysign_nanCases, "copysign_nanCases",
  2071. "Check the NaN special cases", TEST_ENABLED
  2072. };
  2073. static const SDLTest_TestCaseReference copysignTestRange = {
  2074. (SDLTest_TestCaseFp) copysign_rangeTest, "copysign_rangeTest",
  2075. "Check a range of positive integer", TEST_ENABLED
  2076. };
  2077. /* SDL_fmod test cases */
  2078. static const SDLTest_TestCaseReference fmodTestDivOfInf = {
  2079. (SDLTest_TestCaseFp) fmod_divOfInfCases, "fmod_divOfInfCases",
  2080. "Check division of positive and negative infinity", TEST_ENABLED
  2081. };
  2082. static const SDLTest_TestCaseReference fmodTestDivByInf = {
  2083. (SDLTest_TestCaseFp) fmod_divByInfCases, "fmod_divByInfCases",
  2084. "Check division by positive and negative infinity", TEST_ENABLED
  2085. };
  2086. static const SDLTest_TestCaseReference fmodTestDivOfZero = {
  2087. (SDLTest_TestCaseFp) fmod_divOfZeroCases, "fmod_divOfZeroCases",
  2088. "Check division of positive and negative zero", TEST_ENABLED
  2089. };
  2090. static const SDLTest_TestCaseReference fmodTestDivByZero = {
  2091. (SDLTest_TestCaseFp) fmod_divByZeroCases, "fmod_divByZeroCases",
  2092. "Check division by positive and negative zero", TEST_ENABLED
  2093. };
  2094. static const SDLTest_TestCaseReference fmodTestNan = {
  2095. (SDLTest_TestCaseFp) fmod_nanCases, "fmod_nanCases",
  2096. "Check the NaN special cases", TEST_ENABLED
  2097. };
  2098. static const SDLTest_TestCaseReference fmodTestRegular = {
  2099. (SDLTest_TestCaseFp) fmod_regularCases, "fmod_regularCases",
  2100. "Check a set of regular values", TEST_ENABLED
  2101. };
  2102. static const SDLTest_TestCaseReference fmodTestRange = {
  2103. (SDLTest_TestCaseFp) fmod_rangeTest, "fmod_rangeTest",
  2104. "Check a range of positive integer", TEST_ENABLED
  2105. };
  2106. /* SDL_exp test cases */
  2107. static const SDLTest_TestCaseReference expTestInf = {
  2108. (SDLTest_TestCaseFp) exp_infCases, "exp_infCases",
  2109. "Check positive and negative infinity", TEST_ENABLED
  2110. };
  2111. static const SDLTest_TestCaseReference expTestZero = {
  2112. (SDLTest_TestCaseFp) exp_zeroCases, "exp_zeroCases",
  2113. "Check for positive and negative zero", TEST_ENABLED
  2114. };
  2115. static const SDLTest_TestCaseReference expTestOverflow = {
  2116. (SDLTest_TestCaseFp) exp_overflowCase, "exp_overflowCase",
  2117. "Check for overflow", TEST_ENABLED
  2118. };
  2119. static const SDLTest_TestCaseReference expTestBase = {
  2120. (SDLTest_TestCaseFp) exp_baseCase, "exp_baseCase",
  2121. "Check the base case of 1.0", TEST_ENABLED
  2122. };
  2123. static const SDLTest_TestCaseReference expTestRegular = {
  2124. (SDLTest_TestCaseFp) exp_regularCases, "exp_regularCases",
  2125. "Check a set of regular values", TEST_ENABLED
  2126. };
  2127. /* SDL_log test cases */
  2128. static const SDLTest_TestCaseReference logTestLimit = {
  2129. (SDLTest_TestCaseFp) log_limitCases, "log_limitCases",
  2130. "Check for limits", TEST_ENABLED
  2131. };
  2132. static const SDLTest_TestCaseReference logTestNan = {
  2133. (SDLTest_TestCaseFp) log_nanCases, "log_nanCases",
  2134. "Check for the nan cases", TEST_ENABLED
  2135. };
  2136. static const SDLTest_TestCaseReference logTestBase = {
  2137. (SDLTest_TestCaseFp) log_baseCases, "log_baseCases",
  2138. "Check for base cases", TEST_ENABLED
  2139. };
  2140. static const SDLTest_TestCaseReference logTestRegular = {
  2141. (SDLTest_TestCaseFp) log_regularCases, "log_regularCases",
  2142. "Check a set of regular values", TEST_ENABLED
  2143. };
  2144. /* SDL_log10 test cases */
  2145. static const SDLTest_TestCaseReference log10TestLimit = {
  2146. (SDLTest_TestCaseFp) log10_limitCases, "log10_limitCases",
  2147. "Check for limits", TEST_ENABLED
  2148. };
  2149. static const SDLTest_TestCaseReference log10TestNan = {
  2150. (SDLTest_TestCaseFp) log10_nanCases, "log10_nanCases",
  2151. "Check for the nan cases", TEST_ENABLED
  2152. };
  2153. static const SDLTest_TestCaseReference log10TestBase = {
  2154. (SDLTest_TestCaseFp) log10_baseCases, "log10_baseCases",
  2155. "Check for base cases", TEST_ENABLED
  2156. };
  2157. static const SDLTest_TestCaseReference log10TestRegular = {
  2158. (SDLTest_TestCaseFp) log10_regularCases, "log10_regularCases",
  2159. "Check a set of regular values", TEST_ENABLED
  2160. };
  2161. /* SDL_pow test cases */
  2162. static const SDLTest_TestCaseReference powTestExpInf1 = {
  2163. (SDLTest_TestCaseFp) pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
  2164. "Check for pow(-1, +/-inf)", TEST_ENABLED
  2165. };
  2166. static const SDLTest_TestCaseReference powTestExpInf2 = {
  2167. (SDLTest_TestCaseFp) pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
  2168. "Check for pow(+/-0, -inf)", TEST_ENABLED
  2169. };
  2170. static const SDLTest_TestCaseReference powTestExpInf3 = {
  2171. (SDLTest_TestCaseFp) pow_expInfCases, "pow_expInfCases",
  2172. "Check for pow(x, +/-inf)", TEST_ENABLED
  2173. };
  2174. static const SDLTest_TestCaseReference powTestBaseInf1 = {
  2175. (SDLTest_TestCaseFp) pow_basePInfCases, "pow_basePInfCases",
  2176. "Check for pow(inf, x)", TEST_ENABLED
  2177. };
  2178. static const SDLTest_TestCaseReference powTestBaseInf2 = {
  2179. (SDLTest_TestCaseFp) pow_baseNInfCases, "pow_baseNInfCases",
  2180. "Check for pow(-inf, x)", TEST_ENABLED
  2181. };
  2182. static const SDLTest_TestCaseReference powTestNan1 = {
  2183. (SDLTest_TestCaseFp) pow_badOperationCase, "pow_badOperationCase",
  2184. "Check for negative finite base and non-integer finite exponent", TEST_ENABLED
  2185. };
  2186. static const SDLTest_TestCaseReference powTestNan2 = {
  2187. (SDLTest_TestCaseFp) pow_base1ExpNanCase, "pow_base1ExpNanCase",
  2188. "Check for pow(1.0, nan)", TEST_ENABLED
  2189. };
  2190. static const SDLTest_TestCaseReference powTestNan3 = {
  2191. (SDLTest_TestCaseFp) pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
  2192. "Check for pow(nan, +/-0)", TEST_ENABLED
  2193. };
  2194. static const SDLTest_TestCaseReference powTestNan4 = {
  2195. (SDLTest_TestCaseFp) pow_nanArgsCases, "pow_nanArgsCases",
  2196. "Check for pow(x, y) with either x or y being nan", TEST_ENABLED
  2197. };
  2198. static const SDLTest_TestCaseReference powTestZero1 = {
  2199. (SDLTest_TestCaseFp) pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
  2200. "Check for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
  2201. };
  2202. static const SDLTest_TestCaseReference powTestZero2 = {
  2203. (SDLTest_TestCaseFp) pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
  2204. "Check for pow(0.0, y), with y an odd integer.", TEST_ENABLED
  2205. };
  2206. static const SDLTest_TestCaseReference powTestZero3 = {
  2207. (SDLTest_TestCaseFp) pow_baseNZeroCases, "pow_baseNZeroCases",
  2208. "Check for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2209. };
  2210. static const SDLTest_TestCaseReference powTestZero4 = {
  2211. (SDLTest_TestCaseFp) pow_basePZeroCases, "pow_basePZeroCases",
  2212. "Check for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2213. };
  2214. static const SDLTest_TestCaseReference powTestRegular = {
  2215. (SDLTest_TestCaseFp) pow_regularCases, "pow_regularCases",
  2216. "Check a set of regular values", TEST_ENABLED
  2217. };
  2218. static const SDLTest_TestCaseReference powTestPowOf2 = {
  2219. (SDLTest_TestCaseFp) pow_powerOfTwo, "pow_powerOfTwo",
  2220. "Check the powers of two from 1 to 8", TEST_ENABLED
  2221. };
  2222. static const SDLTest_TestCaseReference powTestRange = {
  2223. (SDLTest_TestCaseFp) pow_rangeTest, "pow_rangeTest",
  2224. "Check a range of positive integer to the power of 0", TEST_ENABLED
  2225. };
  2226. /* SDL_sqrt test cases */
  2227. static const SDLTest_TestCaseReference sqrtTestInf = {
  2228. (SDLTest_TestCaseFp) sqrt_infCase, "sqrt_infCase",
  2229. "Check positive infinity", TEST_ENABLED
  2230. };
  2231. static const SDLTest_TestCaseReference sqrtTestNan = {
  2232. (SDLTest_TestCaseFp) sqrt_nanCase, "sqrt_nanCase",
  2233. "Check the NaN special case", TEST_ENABLED
  2234. };
  2235. static const SDLTest_TestCaseReference sqrtTestDomain = {
  2236. (SDLTest_TestCaseFp) sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
  2237. "Check for out of domain values", TEST_ENABLED
  2238. };
  2239. static const SDLTest_TestCaseReference sqrtTestBase = {
  2240. (SDLTest_TestCaseFp) sqrt_baseCases, "sqrt_baseCases",
  2241. "Check the base cases", TEST_ENABLED
  2242. };
  2243. static const SDLTest_TestCaseReference sqrtTestRegular = {
  2244. (SDLTest_TestCaseFp) sqrt_regularCases, "sqrt_regularCases",
  2245. "Check a set of regular values", TEST_ENABLED
  2246. };
  2247. /* SDL_scalbn test cases */
  2248. static const SDLTest_TestCaseReference scalbnTestInf = {
  2249. (SDLTest_TestCaseFp) scalbn_infCases, "scalbn_infCases",
  2250. "Check positive and negative infinity arg", TEST_ENABLED
  2251. };
  2252. static const SDLTest_TestCaseReference scalbnTestBaseZero = {
  2253. (SDLTest_TestCaseFp) scalbn_baseZeroCases, "scalbn_baseZeroCases",
  2254. "Check for positive and negative zero arg", TEST_ENABLED
  2255. };
  2256. static const SDLTest_TestCaseReference scalbnTestExpZero = {
  2257. (SDLTest_TestCaseFp) scalbn_expZeroCase, "scalbn_expZeroCase",
  2258. "Check for zero exp", TEST_ENABLED
  2259. };
  2260. static const SDLTest_TestCaseReference scalbnTestNan = {
  2261. (SDLTest_TestCaseFp) scalbn_nanCase, "scalbn_nanCase",
  2262. "Check the NaN special case", TEST_ENABLED
  2263. };
  2264. static const SDLTest_TestCaseReference scalbnTestRegular = {
  2265. (SDLTest_TestCaseFp) scalbn_regularCases, "scalbn_regularCases",
  2266. "Check a set of regular cases", TEST_ENABLED
  2267. };
  2268. /* SDL_cos test cases */
  2269. static const SDLTest_TestCaseReference cosTestInf = {
  2270. (SDLTest_TestCaseFp) cos_infCases, "cos_infCases",
  2271. "Check for positive and negative infinity", TEST_ENABLED
  2272. };
  2273. static const SDLTest_TestCaseReference cosTestNan = {
  2274. (SDLTest_TestCaseFp) cos_nanCase, "cos_nanCase",
  2275. "Check the NaN special case", TEST_ENABLED
  2276. };
  2277. static const SDLTest_TestCaseReference cosTestRegular = {
  2278. (SDLTest_TestCaseFp) cos_regularCases, "cos_regularCases",
  2279. "Check a set of regular cases", TEST_ENABLED
  2280. };
  2281. static const SDLTest_TestCaseReference cosTestPrecision = {
  2282. (SDLTest_TestCaseFp) cos_precisionTest, "cos_precisionTest",
  2283. "Check cosine precision to the tenth decimal", TEST_ENABLED
  2284. };
  2285. static const SDLTest_TestCaseReference cosTestRange = {
  2286. (SDLTest_TestCaseFp) cos_rangeTest, "cos_rangeTest",
  2287. "Check a range of positive integer", TEST_ENABLED
  2288. };
  2289. /* SDL_sin test cases */
  2290. static const SDLTest_TestCaseReference sinTestInf = {
  2291. (SDLTest_TestCaseFp) sin_infCases, "sin_infCases",
  2292. "Check for positive and negative infinity", TEST_ENABLED
  2293. };
  2294. static const SDLTest_TestCaseReference sinTestNan = {
  2295. (SDLTest_TestCaseFp) sin_nanCase, "sin_nanCase",
  2296. "Check the NaN special case", TEST_ENABLED
  2297. };
  2298. static const SDLTest_TestCaseReference sinTestRegular = {
  2299. (SDLTest_TestCaseFp) sin_regularCases, "sin_regularCases",
  2300. "Check a set of regular cases", TEST_ENABLED
  2301. };
  2302. static const SDLTest_TestCaseReference sinTestPrecision = {
  2303. (SDLTest_TestCaseFp) sin_precisionTest, "sin_precisionTest",
  2304. "Check sine precision to the tenth decimal", TEST_ENABLED
  2305. };
  2306. static const SDLTest_TestCaseReference sinTestRange = {
  2307. (SDLTest_TestCaseFp) sin_rangeTest, "sin_rangeTest",
  2308. "Check a range of positive integer", TEST_ENABLED
  2309. };
  2310. /* SDL_tan test cases */
  2311. static const SDLTest_TestCaseReference tanTestInf = {
  2312. (SDLTest_TestCaseFp) tan_infCases, "tan_infCases",
  2313. "Check for positive and negative infinity", TEST_ENABLED
  2314. };
  2315. static const SDLTest_TestCaseReference tanTestNan = {
  2316. (SDLTest_TestCaseFp) tan_nanCase, "tan_nanCase",
  2317. "Check the NaN special case", TEST_ENABLED
  2318. };
  2319. static const SDLTest_TestCaseReference tanTestZero = {
  2320. (SDLTest_TestCaseFp) tan_zeroCases, "tan_zeroCases",
  2321. "Check a set of regular cases", TEST_ENABLED
  2322. };
  2323. static const SDLTest_TestCaseReference tanTestPrecision = {
  2324. (SDLTest_TestCaseFp) tan_precisionTest, "tan_precisionTest",
  2325. "Check tane precision to the tenth decimal", TEST_ENABLED
  2326. };
  2327. /* SDL_acos test cases */
  2328. static const SDLTest_TestCaseReference acosTestLimit = {
  2329. (SDLTest_TestCaseFp) acos_limitCases, "acos_limitCases",
  2330. "Check the edge of the domain (+/-1)", TEST_ENABLED
  2331. };
  2332. static const SDLTest_TestCaseReference acosTestOutOfDomain = {
  2333. (SDLTest_TestCaseFp) acos_outOfDomainCases, "acos_outOfDomainCases",
  2334. "Check a for value outside the domain", TEST_ENABLED
  2335. };
  2336. static const SDLTest_TestCaseReference acosTestNan = {
  2337. (SDLTest_TestCaseFp) acos_nanCase, "acos_nanCase",
  2338. "Check the NaN special case", TEST_ENABLED
  2339. };
  2340. static const SDLTest_TestCaseReference acosTestPrecision = {
  2341. (SDLTest_TestCaseFp) acos_precisionTest, "acos_precisionTest",
  2342. "Check acos precision to the tenth decimal", TEST_ENABLED
  2343. };
  2344. /* SDL_asin test cases */
  2345. static const SDLTest_TestCaseReference asinTestLimit = {
  2346. (SDLTest_TestCaseFp) asin_limitCases, "asin_limitCases",
  2347. "Check the edge of the domain (+/-1)", TEST_ENABLED
  2348. };
  2349. static const SDLTest_TestCaseReference asinTestOutOfDomain = {
  2350. (SDLTest_TestCaseFp) asin_outOfDomainCases, "asin_outOfDomainCases",
  2351. "Check a for value outside the domain", TEST_ENABLED
  2352. };
  2353. static const SDLTest_TestCaseReference asinTestNan = {
  2354. (SDLTest_TestCaseFp) asin_nanCase, "asin_nanCase",
  2355. "Check the NaN special case", TEST_ENABLED
  2356. };
  2357. static const SDLTest_TestCaseReference asinTestPrecision = {
  2358. (SDLTest_TestCaseFp) asin_precisionTest, "asin_precisionTest",
  2359. "Check asin precision to the tenth decimal", TEST_ENABLED
  2360. };
  2361. static const SDLTest_TestCaseReference *mathTests[] = {
  2362. &floorTestInf, &floorTestZero, &floorTestNan,
  2363. &floorTestRound, &floorTestFraction, &floorTestRange,
  2364. &ceilTestInf, &ceilTestZero, &ceilTestNan,
  2365. &ceilTestRound, &ceilTestFraction, &ceilTestRange,
  2366. &truncTestInf, &truncTestZero, &truncTestNan,
  2367. &truncTestRound, &truncTestFraction, &truncTestRange,
  2368. &roundTestInf, &roundTestZero, &roundTestNan,
  2369. &roundTestRound, &roundTestFraction, &roundTestRange,
  2370. &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
  2371. &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
  2372. &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
  2373. &fmodTestNan, &fmodTestRegular, &fmodTestRange,
  2374. &expTestInf, &expTestZero, &expTestOverflow,
  2375. &expTestBase, &expTestRegular,
  2376. &logTestLimit, &logTestNan,
  2377. &logTestBase, &logTestRegular,
  2378. &log10TestLimit, &log10TestNan,
  2379. &log10TestBase, &log10TestRegular,
  2380. &powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
  2381. &powTestBaseInf1, &powTestBaseInf2,
  2382. &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
  2383. &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
  2384. &powTestRegular, &powTestPowOf2, &powTestRange,
  2385. &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
  2386. &sqrtTestBase, &sqrtTestRegular,
  2387. &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
  2388. &scalbnTestNan, &scalbnTestRegular,
  2389. &cosTestInf, &cosTestNan, &cosTestRegular,
  2390. &cosTestPrecision, &cosTestRange,
  2391. &sinTestInf, &sinTestNan, &sinTestRegular,
  2392. &sinTestPrecision, &sinTestRange,
  2393. &tanTestInf, &tanTestNan, &tanTestZero, &tanTestPrecision,
  2394. &acosTestLimit, &acosTestOutOfDomain, &acosTestNan, &acosTestPrecision,
  2395. &asinTestLimit, &asinTestOutOfDomain, &asinTestNan, &asinTestPrecision,
  2396. NULL
  2397. };
  2398. SDLTest_TestSuiteReference mathTestSuite = { "Math", NULL, mathTests, NULL };