testautomation_math.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872
  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.9, 4510268117.0 },
  1845. { 0.8, 6435011087.0 },
  1846. { 0.7, 7953988301.0 },
  1847. { 0.6, 9272952180.0 },
  1848. { 0.5, 10471975511.0 },
  1849. { 0.4, 11592794807.0 },
  1850. { 0.3, 12661036727.0 },
  1851. { 0.2, 13694384060.0 },
  1852. { 0.1, 14706289056.0 },
  1853. { 0.0, 15707963267.0 },
  1854. { -0.0, 15707963267.0 },
  1855. { -0.1, 16709637479.0 },
  1856. { -0.2, 17721542475.0 },
  1857. { -0.3, 18754889808.0 },
  1858. { -0.4, 19823131728.0 },
  1859. { -0.5, 20943951023.0 },
  1860. { -0.6, 22142974355.0 },
  1861. { -0.7, 23461938234.0 },
  1862. { -0.8, 24980915447.0 },
  1863. { -0.9, 26905658417.0 },
  1864. };
  1865. return helper_dtod_approx("Acos", SDL_acos, precision_cases, SDL_arraysize(precision_cases));
  1866. }
  1867. /* SDL_asin tests functions */
  1868. /**
  1869. * \brief Checks limits of the domain (+/-1).
  1870. */
  1871. static int
  1872. asin_limitCases(void *args)
  1873. {
  1874. double result;
  1875. result = SDL_asin(1.0);
  1876. SDLTest_AssertCheck(M_PI / 2.0 == result,
  1877. "Asin(%f), expected %f, got %f",
  1878. 1.0, M_PI / 2.0, result);
  1879. result = SDL_asin(-1.0);
  1880. SDLTest_AssertCheck(-M_PI / 2.0 == result,
  1881. "Asin(%f), expected %f, got %f",
  1882. -1.0, -M_PI / 2.0, result);
  1883. return TEST_COMPLETED;
  1884. }
  1885. /**
  1886. * \brief Checks values outside the domain (|x| > 1).
  1887. */
  1888. static int
  1889. asin_outOfDomainCases(void *args)
  1890. {
  1891. double result;
  1892. result = SDL_asin(1.1);
  1893. SDLTest_AssertCheck(isnan(result),
  1894. "Asin(%f), expected %f, got %f",
  1895. 1.1, NAN, result);
  1896. result = SDL_asin(-1.1);
  1897. SDLTest_AssertCheck(isnan(result),
  1898. "Asin(%f), expected %f, got %f",
  1899. -1.1, NAN, result);
  1900. return TEST_COMPLETED;
  1901. }
  1902. /**
  1903. * \brief Checks for nan.
  1904. */
  1905. static int
  1906. asin_nanCase(void *args)
  1907. {
  1908. const double result = SDL_asin(NAN);
  1909. SDLTest_AssertCheck(isnan(result),
  1910. "Asin(%f), expected %f, got %f",
  1911. NAN, NAN, result);
  1912. return TEST_COMPLETED;
  1913. }
  1914. /**
  1915. * \brief Checks arc sine precision for the first 10 decimals.
  1916. */
  1917. static int
  1918. asin_precisionTest(void *args)
  1919. {
  1920. const d_to_d precision_cases[] = {
  1921. { 0.9, 11197695149.0 },
  1922. { 0.8, 9272952180.0 },
  1923. { 0.7, 7753974966.0 },
  1924. { 0.6, 6435011087.0 },
  1925. { 0.5, 5235987755.0 },
  1926. { 0.4, 4115168460.0 },
  1927. { 0.3, 3046926540.0 },
  1928. { 0.2, 2013579207.0 },
  1929. { 0.1, 1001674211.0 },
  1930. { 0.0, 0.0 },
  1931. { -0.0, -0.0 },
  1932. { -0.1, -1001674211.0 },
  1933. { -0.2, -2013579207.0 },
  1934. { -0.3, -3046926540.0 },
  1935. { -0.4, -4115168460.0 },
  1936. { -0.5, -5235987755.0 },
  1937. { -0.6, -6435011087.0 },
  1938. { -0.7, -7753974966.0 },
  1939. { -0.8, -9272952180.0 },
  1940. { -0.9, -11197695149.0 }
  1941. };
  1942. return helper_dtod_approx("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases));
  1943. }
  1944. /* SDL_atan tests functions */
  1945. /**
  1946. * \brief Checks limits of the domain (+/- infinity).
  1947. */
  1948. static int
  1949. atan_limitCases(void *args)
  1950. {
  1951. double result;
  1952. result = SDL_atan(INFINITY);
  1953. SDLTest_AssertCheck(M_PI / 2.0 == result,
  1954. "Atan(%f), expected %f, got %f",
  1955. INFINITY, M_PI / 2.0, result);
  1956. result = SDL_atan(-INFINITY);
  1957. SDLTest_AssertCheck(-M_PI / 2.0 == result,
  1958. "Atan(%f), expected %f, got %f",
  1959. -INFINITY, -M_PI / 2.0, result);
  1960. return TEST_COMPLETED;
  1961. }
  1962. /**
  1963. * \brief Checks positive and negative zeros.
  1964. */
  1965. static int
  1966. atan_zeroCases(void *args)
  1967. {
  1968. double result;
  1969. result = SDL_atan(0.0);
  1970. SDLTest_AssertCheck(0.0 == result,
  1971. "Atan(%f), expected %f, got %f",
  1972. 0.0, 0.0, result);
  1973. result = SDL_atan(-0.0);
  1974. SDLTest_AssertCheck(-0.0 == result,
  1975. "Atan(%f), expected %f, got %f",
  1976. -0.0, -0.0, result);
  1977. return TEST_COMPLETED;
  1978. }
  1979. /**
  1980. * \brief Checks for nan.
  1981. */
  1982. static int
  1983. atan_nanCase(void *args)
  1984. {
  1985. const double result = SDL_atan(NAN);
  1986. SDLTest_AssertCheck(isnan(result),
  1987. "Atan(%f), expected %f, got %f",
  1988. NAN, NAN, result);
  1989. return TEST_COMPLETED;
  1990. }
  1991. /**
  1992. * \brief Checks arc tangent precision for the first 10 decimals.
  1993. */
  1994. static int
  1995. atan_precisionTest(void *args)
  1996. {
  1997. /* Checks angles from 9PI/20 -> -9PI/20 with steps of 1/20th */
  1998. const d_to_d precision_cases[] = {
  1999. { 6.313751514675041, 14137166941.0 },
  2000. { 3.0776835371752527, 12566370614.0 },
  2001. { 1.9626105055051504, 10995574287.0 },
  2002. { 1.3763819204711734, 9424777960.0 },
  2003. { 1.0, 7853981633.0 },
  2004. { 0.7265425280053609, 6283185307.0 },
  2005. { 0.5095254494944288, 4712388980.0 },
  2006. { 0.3249196962329063, 3141592653.0 },
  2007. { 0.15838444032453627, 1570796326.0 },
  2008. { -0.15838444032453627, -1570796326.0 },
  2009. { -0.3249196962329063, -3141592653.0 },
  2010. { -0.5095254494944288, -4712388980.0 },
  2011. { -0.7265425280053609, -6283185307.0 },
  2012. { -1.0, -7853981633.0 },
  2013. { -1.3763819204711734, -9424777960.0 },
  2014. { -1.9626105055051504, -10995574287.0 },
  2015. { -3.0776835371752527, -12566370614.0 },
  2016. { -6.313751514675041, -14137166941.0 },
  2017. };
  2018. return helper_dtod_approx("Atan", SDL_atan, precision_cases, SDL_arraysize(precision_cases));
  2019. }
  2020. /* ================= Test References ================== */
  2021. /* SDL_floor test cases */
  2022. static const SDLTest_TestCaseReference floorTestInf = {
  2023. (SDLTest_TestCaseFp) floor_infCases, "floor_infCases",
  2024. "Check positive and negative infinity", TEST_ENABLED
  2025. };
  2026. static const SDLTest_TestCaseReference floorTestZero = {
  2027. (SDLTest_TestCaseFp) floor_zeroCases, "floor_zeroCases",
  2028. "Check positive and negative zero", TEST_ENABLED
  2029. };
  2030. static const SDLTest_TestCaseReference floorTestNan = {
  2031. (SDLTest_TestCaseFp) floor_nanCase, "floor_nanCase",
  2032. "Check the NaN special case", TEST_ENABLED
  2033. };
  2034. static const SDLTest_TestCaseReference floorTestRound = {
  2035. (SDLTest_TestCaseFp) floor_roundNumbersCases, "floor_roundNumberCases",
  2036. "Check a set of round numbers", TEST_ENABLED
  2037. };
  2038. static const SDLTest_TestCaseReference floorTestFraction = {
  2039. (SDLTest_TestCaseFp) floor_fractionCases, "floor_fractionCases",
  2040. "Check a set of fractions", TEST_ENABLED
  2041. };
  2042. static const SDLTest_TestCaseReference floorTestRange = {
  2043. (SDLTest_TestCaseFp) floor_rangeTest, "floor_rangeTest",
  2044. "Check a range of positive integer", TEST_ENABLED
  2045. };
  2046. /* SDL_ceil test cases */
  2047. static const SDLTest_TestCaseReference ceilTestInf = {
  2048. (SDLTest_TestCaseFp) ceil_infCases, "ceil_infCases",
  2049. "Check positive and negative infinity", TEST_ENABLED
  2050. };
  2051. static const SDLTest_TestCaseReference ceilTestZero = {
  2052. (SDLTest_TestCaseFp) ceil_zeroCases, "ceil_zeroCases",
  2053. "Check positive and negative zero", TEST_ENABLED
  2054. };
  2055. static const SDLTest_TestCaseReference ceilTestNan = {
  2056. (SDLTest_TestCaseFp) ceil_nanCase, "ceil_nanCase",
  2057. "Check the NaN special case", TEST_ENABLED
  2058. };
  2059. static const SDLTest_TestCaseReference ceilTestRound = {
  2060. (SDLTest_TestCaseFp) ceil_roundNumbersCases, "ceil_roundNumberCases",
  2061. "Check a set of round numbers", TEST_ENABLED
  2062. };
  2063. static const SDLTest_TestCaseReference ceilTestFraction = {
  2064. (SDLTest_TestCaseFp) ceil_fractionCases, "ceil_fractionCases",
  2065. "Check a set of fractions", TEST_ENABLED
  2066. };
  2067. static const SDLTest_TestCaseReference ceilTestRange = {
  2068. (SDLTest_TestCaseFp) ceil_rangeTest, "ceil_rangeTest",
  2069. "Check a range of positive integer", TEST_ENABLED
  2070. };
  2071. /* SDL_trunc test cases */
  2072. static const SDLTest_TestCaseReference truncTestInf = {
  2073. (SDLTest_TestCaseFp) trunc_infCases, "trunc_infCases",
  2074. "Check positive and negative infinity", TEST_ENABLED
  2075. };
  2076. static const SDLTest_TestCaseReference truncTestZero = {
  2077. (SDLTest_TestCaseFp) trunc_zeroCases, "trunc_zeroCases",
  2078. "Check positive and negative zero", TEST_ENABLED
  2079. };
  2080. static const SDLTest_TestCaseReference truncTestNan = {
  2081. (SDLTest_TestCaseFp) trunc_nanCase, "trunc_nanCase",
  2082. "Check the NaN special case", TEST_ENABLED
  2083. };
  2084. static const SDLTest_TestCaseReference truncTestRound = {
  2085. (SDLTest_TestCaseFp) trunc_roundNumbersCases, "trunc_roundNumberCases",
  2086. "Check a set of round numbers", TEST_ENABLED
  2087. };
  2088. static const SDLTest_TestCaseReference truncTestFraction = {
  2089. (SDLTest_TestCaseFp) trunc_fractionCases, "trunc_fractionCases",
  2090. "Check a set of fractions", TEST_ENABLED
  2091. };
  2092. static const SDLTest_TestCaseReference truncTestRange = {
  2093. (SDLTest_TestCaseFp) trunc_rangeTest, "trunc_rangeTest",
  2094. "Check a range of positive integer", TEST_ENABLED
  2095. };
  2096. /* SDL_round test cases */
  2097. static const SDLTest_TestCaseReference roundTestInf = {
  2098. (SDLTest_TestCaseFp) round_infCases, "round_infCases",
  2099. "Check positive and negative infinity", TEST_ENABLED
  2100. };
  2101. static const SDLTest_TestCaseReference roundTestZero = {
  2102. (SDLTest_TestCaseFp) round_zeroCases, "round_zeroCases",
  2103. "Check positive and negative zero", TEST_ENABLED
  2104. };
  2105. static const SDLTest_TestCaseReference roundTestNan = {
  2106. (SDLTest_TestCaseFp) round_nanCase, "round_nanCase",
  2107. "Check the NaN special case", TEST_ENABLED
  2108. };
  2109. static const SDLTest_TestCaseReference roundTestRound = {
  2110. (SDLTest_TestCaseFp) round_roundNumbersCases, "round_roundNumberCases",
  2111. "Check a set of round numbers", TEST_ENABLED
  2112. };
  2113. static const SDLTest_TestCaseReference roundTestFraction = {
  2114. (SDLTest_TestCaseFp) round_fractionCases, "round_fractionCases",
  2115. "Check a set of fractions", TEST_ENABLED
  2116. };
  2117. static const SDLTest_TestCaseReference roundTestRange = {
  2118. (SDLTest_TestCaseFp) round_rangeTest, "round_rangeTest",
  2119. "Check a range of positive integer", TEST_ENABLED
  2120. };
  2121. /* SDL_fabs test cases */
  2122. static const SDLTest_TestCaseReference fabsTestInf = {
  2123. (SDLTest_TestCaseFp) fabs_infCases, "fabs_infCases",
  2124. "Check positive and negative infinity", TEST_ENABLED
  2125. };
  2126. static const SDLTest_TestCaseReference fabsTestZero = {
  2127. (SDLTest_TestCaseFp) fabs_zeroCases, "fabs_zeroCases",
  2128. "Check positive and negative zero", TEST_ENABLED
  2129. };
  2130. static const SDLTest_TestCaseReference fabsTestNan = {
  2131. (SDLTest_TestCaseFp) fabs_nanCase, "fabs_nanCase",
  2132. "Check the NaN special case", TEST_ENABLED
  2133. };
  2134. static const SDLTest_TestCaseReference fabsTestRange = {
  2135. (SDLTest_TestCaseFp) fabs_rangeTest, "fabs_rangeTest",
  2136. "Check a range of positive integer", TEST_ENABLED
  2137. };
  2138. /* SDL_copysign test cases */
  2139. static const SDLTest_TestCaseReference copysignTestInf = {
  2140. (SDLTest_TestCaseFp) copysign_infCases, "copysign_infCases",
  2141. "Check positive and negative infinity", TEST_ENABLED
  2142. };
  2143. static const SDLTest_TestCaseReference copysignTestZero = {
  2144. (SDLTest_TestCaseFp) copysign_zeroCases, "copysign_zeroCases",
  2145. "Check positive and negative zero", TEST_ENABLED
  2146. };
  2147. static const SDLTest_TestCaseReference copysignTestNan = {
  2148. (SDLTest_TestCaseFp) copysign_nanCases, "copysign_nanCases",
  2149. "Check the NaN special cases", TEST_ENABLED
  2150. };
  2151. static const SDLTest_TestCaseReference copysignTestRange = {
  2152. (SDLTest_TestCaseFp) copysign_rangeTest, "copysign_rangeTest",
  2153. "Check a range of positive integer", TEST_ENABLED
  2154. };
  2155. /* SDL_fmod test cases */
  2156. static const SDLTest_TestCaseReference fmodTestDivOfInf = {
  2157. (SDLTest_TestCaseFp) fmod_divOfInfCases, "fmod_divOfInfCases",
  2158. "Check division of positive and negative infinity", TEST_ENABLED
  2159. };
  2160. static const SDLTest_TestCaseReference fmodTestDivByInf = {
  2161. (SDLTest_TestCaseFp) fmod_divByInfCases, "fmod_divByInfCases",
  2162. "Check division by positive and negative infinity", TEST_ENABLED
  2163. };
  2164. static const SDLTest_TestCaseReference fmodTestDivOfZero = {
  2165. (SDLTest_TestCaseFp) fmod_divOfZeroCases, "fmod_divOfZeroCases",
  2166. "Check division of positive and negative zero", TEST_ENABLED
  2167. };
  2168. static const SDLTest_TestCaseReference fmodTestDivByZero = {
  2169. (SDLTest_TestCaseFp) fmod_divByZeroCases, "fmod_divByZeroCases",
  2170. "Check division by positive and negative zero", TEST_ENABLED
  2171. };
  2172. static const SDLTest_TestCaseReference fmodTestNan = {
  2173. (SDLTest_TestCaseFp) fmod_nanCases, "fmod_nanCases",
  2174. "Check the NaN special cases", TEST_ENABLED
  2175. };
  2176. static const SDLTest_TestCaseReference fmodTestRegular = {
  2177. (SDLTest_TestCaseFp) fmod_regularCases, "fmod_regularCases",
  2178. "Check a set of regular values", TEST_ENABLED
  2179. };
  2180. static const SDLTest_TestCaseReference fmodTestRange = {
  2181. (SDLTest_TestCaseFp) fmod_rangeTest, "fmod_rangeTest",
  2182. "Check a range of positive integer", TEST_ENABLED
  2183. };
  2184. /* SDL_exp test cases */
  2185. static const SDLTest_TestCaseReference expTestInf = {
  2186. (SDLTest_TestCaseFp) exp_infCases, "exp_infCases",
  2187. "Check positive and negative infinity", TEST_ENABLED
  2188. };
  2189. static const SDLTest_TestCaseReference expTestZero = {
  2190. (SDLTest_TestCaseFp) exp_zeroCases, "exp_zeroCases",
  2191. "Check for positive and negative zero", TEST_ENABLED
  2192. };
  2193. static const SDLTest_TestCaseReference expTestOverflow = {
  2194. (SDLTest_TestCaseFp) exp_overflowCase, "exp_overflowCase",
  2195. "Check for overflow", TEST_ENABLED
  2196. };
  2197. static const SDLTest_TestCaseReference expTestBase = {
  2198. (SDLTest_TestCaseFp) exp_baseCase, "exp_baseCase",
  2199. "Check the base case of 1.0", TEST_ENABLED
  2200. };
  2201. static const SDLTest_TestCaseReference expTestRegular = {
  2202. (SDLTest_TestCaseFp) exp_regularCases, "exp_regularCases",
  2203. "Check a set of regular values", TEST_ENABLED
  2204. };
  2205. /* SDL_log test cases */
  2206. static const SDLTest_TestCaseReference logTestLimit = {
  2207. (SDLTest_TestCaseFp) log_limitCases, "log_limitCases",
  2208. "Check for limits", TEST_ENABLED
  2209. };
  2210. static const SDLTest_TestCaseReference logTestNan = {
  2211. (SDLTest_TestCaseFp) log_nanCases, "log_nanCases",
  2212. "Check for the nan cases", TEST_ENABLED
  2213. };
  2214. static const SDLTest_TestCaseReference logTestBase = {
  2215. (SDLTest_TestCaseFp) log_baseCases, "log_baseCases",
  2216. "Check for base cases", TEST_ENABLED
  2217. };
  2218. static const SDLTest_TestCaseReference logTestRegular = {
  2219. (SDLTest_TestCaseFp) log_regularCases, "log_regularCases",
  2220. "Check a set of regular values", TEST_ENABLED
  2221. };
  2222. /* SDL_log10 test cases */
  2223. static const SDLTest_TestCaseReference log10TestLimit = {
  2224. (SDLTest_TestCaseFp) log10_limitCases, "log10_limitCases",
  2225. "Check for limits", TEST_ENABLED
  2226. };
  2227. static const SDLTest_TestCaseReference log10TestNan = {
  2228. (SDLTest_TestCaseFp) log10_nanCases, "log10_nanCases",
  2229. "Check for the nan cases", TEST_ENABLED
  2230. };
  2231. static const SDLTest_TestCaseReference log10TestBase = {
  2232. (SDLTest_TestCaseFp) log10_baseCases, "log10_baseCases",
  2233. "Check for base cases", TEST_ENABLED
  2234. };
  2235. static const SDLTest_TestCaseReference log10TestRegular = {
  2236. (SDLTest_TestCaseFp) log10_regularCases, "log10_regularCases",
  2237. "Check a set of regular values", TEST_ENABLED
  2238. };
  2239. /* SDL_pow test cases */
  2240. static const SDLTest_TestCaseReference powTestExpInf1 = {
  2241. (SDLTest_TestCaseFp) pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
  2242. "Check for pow(-1, +/-inf)", TEST_ENABLED
  2243. };
  2244. static const SDLTest_TestCaseReference powTestExpInf2 = {
  2245. (SDLTest_TestCaseFp) pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
  2246. "Check for pow(+/-0, -inf)", TEST_ENABLED
  2247. };
  2248. static const SDLTest_TestCaseReference powTestExpInf3 = {
  2249. (SDLTest_TestCaseFp) pow_expInfCases, "pow_expInfCases",
  2250. "Check for pow(x, +/-inf)", TEST_ENABLED
  2251. };
  2252. static const SDLTest_TestCaseReference powTestBaseInf1 = {
  2253. (SDLTest_TestCaseFp) pow_basePInfCases, "pow_basePInfCases",
  2254. "Check for pow(inf, x)", TEST_ENABLED
  2255. };
  2256. static const SDLTest_TestCaseReference powTestBaseInf2 = {
  2257. (SDLTest_TestCaseFp) pow_baseNInfCases, "pow_baseNInfCases",
  2258. "Check for pow(-inf, x)", TEST_ENABLED
  2259. };
  2260. static const SDLTest_TestCaseReference powTestNan1 = {
  2261. (SDLTest_TestCaseFp) pow_badOperationCase, "pow_badOperationCase",
  2262. "Check for negative finite base and non-integer finite exponent", TEST_ENABLED
  2263. };
  2264. static const SDLTest_TestCaseReference powTestNan2 = {
  2265. (SDLTest_TestCaseFp) pow_base1ExpNanCase, "pow_base1ExpNanCase",
  2266. "Check for pow(1.0, nan)", TEST_ENABLED
  2267. };
  2268. static const SDLTest_TestCaseReference powTestNan3 = {
  2269. (SDLTest_TestCaseFp) pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
  2270. "Check for pow(nan, +/-0)", TEST_ENABLED
  2271. };
  2272. static const SDLTest_TestCaseReference powTestNan4 = {
  2273. (SDLTest_TestCaseFp) pow_nanArgsCases, "pow_nanArgsCases",
  2274. "Check for pow(x, y) with either x or y being nan", TEST_ENABLED
  2275. };
  2276. static const SDLTest_TestCaseReference powTestZero1 = {
  2277. (SDLTest_TestCaseFp) pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
  2278. "Check for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
  2279. };
  2280. static const SDLTest_TestCaseReference powTestZero2 = {
  2281. (SDLTest_TestCaseFp) pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
  2282. "Check for pow(0.0, y), with y an odd integer.", TEST_ENABLED
  2283. };
  2284. static const SDLTest_TestCaseReference powTestZero3 = {
  2285. (SDLTest_TestCaseFp) pow_baseNZeroCases, "pow_baseNZeroCases",
  2286. "Check for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2287. };
  2288. static const SDLTest_TestCaseReference powTestZero4 = {
  2289. (SDLTest_TestCaseFp) pow_basePZeroCases, "pow_basePZeroCases",
  2290. "Check for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2291. };
  2292. static const SDLTest_TestCaseReference powTestRegular = {
  2293. (SDLTest_TestCaseFp) pow_regularCases, "pow_regularCases",
  2294. "Check a set of regular values", TEST_ENABLED
  2295. };
  2296. static const SDLTest_TestCaseReference powTestPowOf2 = {
  2297. (SDLTest_TestCaseFp) pow_powerOfTwo, "pow_powerOfTwo",
  2298. "Check the powers of two from 1 to 8", TEST_ENABLED
  2299. };
  2300. static const SDLTest_TestCaseReference powTestRange = {
  2301. (SDLTest_TestCaseFp) pow_rangeTest, "pow_rangeTest",
  2302. "Check a range of positive integer to the power of 0", TEST_ENABLED
  2303. };
  2304. /* SDL_sqrt test cases */
  2305. static const SDLTest_TestCaseReference sqrtTestInf = {
  2306. (SDLTest_TestCaseFp) sqrt_infCase, "sqrt_infCase",
  2307. "Check positive infinity", TEST_ENABLED
  2308. };
  2309. static const SDLTest_TestCaseReference sqrtTestNan = {
  2310. (SDLTest_TestCaseFp) sqrt_nanCase, "sqrt_nanCase",
  2311. "Check the NaN special case", TEST_ENABLED
  2312. };
  2313. static const SDLTest_TestCaseReference sqrtTestDomain = {
  2314. (SDLTest_TestCaseFp) sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
  2315. "Check for out of domain values", TEST_ENABLED
  2316. };
  2317. static const SDLTest_TestCaseReference sqrtTestBase = {
  2318. (SDLTest_TestCaseFp) sqrt_baseCases, "sqrt_baseCases",
  2319. "Check the base cases", TEST_ENABLED
  2320. };
  2321. static const SDLTest_TestCaseReference sqrtTestRegular = {
  2322. (SDLTest_TestCaseFp) sqrt_regularCases, "sqrt_regularCases",
  2323. "Check a set of regular values", TEST_ENABLED
  2324. };
  2325. /* SDL_scalbn test cases */
  2326. static const SDLTest_TestCaseReference scalbnTestInf = {
  2327. (SDLTest_TestCaseFp) scalbn_infCases, "scalbn_infCases",
  2328. "Check positive and negative infinity arg", TEST_ENABLED
  2329. };
  2330. static const SDLTest_TestCaseReference scalbnTestBaseZero = {
  2331. (SDLTest_TestCaseFp) scalbn_baseZeroCases, "scalbn_baseZeroCases",
  2332. "Check for positive and negative zero arg", TEST_ENABLED
  2333. };
  2334. static const SDLTest_TestCaseReference scalbnTestExpZero = {
  2335. (SDLTest_TestCaseFp) scalbn_expZeroCase, "scalbn_expZeroCase",
  2336. "Check for zero exp", TEST_ENABLED
  2337. };
  2338. static const SDLTest_TestCaseReference scalbnTestNan = {
  2339. (SDLTest_TestCaseFp) scalbn_nanCase, "scalbn_nanCase",
  2340. "Check the NaN special case", TEST_ENABLED
  2341. };
  2342. static const SDLTest_TestCaseReference scalbnTestRegular = {
  2343. (SDLTest_TestCaseFp) scalbn_regularCases, "scalbn_regularCases",
  2344. "Check a set of regular cases", TEST_ENABLED
  2345. };
  2346. /* SDL_cos test cases */
  2347. static const SDLTest_TestCaseReference cosTestInf = {
  2348. (SDLTest_TestCaseFp) cos_infCases, "cos_infCases",
  2349. "Check for positive and negative infinity", TEST_ENABLED
  2350. };
  2351. static const SDLTest_TestCaseReference cosTestNan = {
  2352. (SDLTest_TestCaseFp) cos_nanCase, "cos_nanCase",
  2353. "Check the NaN special case", TEST_ENABLED
  2354. };
  2355. static const SDLTest_TestCaseReference cosTestRegular = {
  2356. (SDLTest_TestCaseFp) cos_regularCases, "cos_regularCases",
  2357. "Check a set of regular cases", TEST_ENABLED
  2358. };
  2359. static const SDLTest_TestCaseReference cosTestPrecision = {
  2360. (SDLTest_TestCaseFp) cos_precisionTest, "cos_precisionTest",
  2361. "Check cosine precision to the tenth decimal", TEST_ENABLED
  2362. };
  2363. static const SDLTest_TestCaseReference cosTestRange = {
  2364. (SDLTest_TestCaseFp) cos_rangeTest, "cos_rangeTest",
  2365. "Check a range of positive integer", TEST_ENABLED
  2366. };
  2367. /* SDL_sin test cases */
  2368. static const SDLTest_TestCaseReference sinTestInf = {
  2369. (SDLTest_TestCaseFp) sin_infCases, "sin_infCases",
  2370. "Check for positive and negative infinity", TEST_ENABLED
  2371. };
  2372. static const SDLTest_TestCaseReference sinTestNan = {
  2373. (SDLTest_TestCaseFp) sin_nanCase, "sin_nanCase",
  2374. "Check the NaN special case", TEST_ENABLED
  2375. };
  2376. static const SDLTest_TestCaseReference sinTestRegular = {
  2377. (SDLTest_TestCaseFp) sin_regularCases, "sin_regularCases",
  2378. "Check a set of regular cases", TEST_ENABLED
  2379. };
  2380. static const SDLTest_TestCaseReference sinTestPrecision = {
  2381. (SDLTest_TestCaseFp) sin_precisionTest, "sin_precisionTest",
  2382. "Check sine precision to the tenth decimal", TEST_ENABLED
  2383. };
  2384. static const SDLTest_TestCaseReference sinTestRange = {
  2385. (SDLTest_TestCaseFp) sin_rangeTest, "sin_rangeTest",
  2386. "Check a range of positive integer", TEST_ENABLED
  2387. };
  2388. /* SDL_tan test cases */
  2389. static const SDLTest_TestCaseReference tanTestInf = {
  2390. (SDLTest_TestCaseFp) tan_infCases, "tan_infCases",
  2391. "Check for positive and negative infinity", TEST_ENABLED
  2392. };
  2393. static const SDLTest_TestCaseReference tanTestNan = {
  2394. (SDLTest_TestCaseFp) tan_nanCase, "tan_nanCase",
  2395. "Check the NaN special case", TEST_ENABLED
  2396. };
  2397. static const SDLTest_TestCaseReference tanTestZero = {
  2398. (SDLTest_TestCaseFp) tan_zeroCases, "tan_zeroCases",
  2399. "Check a set of regular cases", TEST_ENABLED
  2400. };
  2401. static const SDLTest_TestCaseReference tanTestPrecision = {
  2402. (SDLTest_TestCaseFp) tan_precisionTest, "tan_precisionTest",
  2403. "Check tane precision to the tenth decimal", TEST_ENABLED
  2404. };
  2405. /* SDL_acos test cases */
  2406. static const SDLTest_TestCaseReference acosTestLimit = {
  2407. (SDLTest_TestCaseFp) acos_limitCases, "acos_limitCases",
  2408. "Check the edge of the domain (+/-1)", TEST_ENABLED
  2409. };
  2410. static const SDLTest_TestCaseReference acosTestOutOfDomain = {
  2411. (SDLTest_TestCaseFp) acos_outOfDomainCases, "acos_outOfDomainCases",
  2412. "Check a for value outside the domain", TEST_ENABLED
  2413. };
  2414. static const SDLTest_TestCaseReference acosTestNan = {
  2415. (SDLTest_TestCaseFp) acos_nanCase, "acos_nanCase",
  2416. "Check the NaN special case", TEST_ENABLED
  2417. };
  2418. static const SDLTest_TestCaseReference acosTestPrecision = {
  2419. (SDLTest_TestCaseFp) acos_precisionTest, "acos_precisionTest",
  2420. "Check acos precision to the tenth decimal", TEST_ENABLED
  2421. };
  2422. /* SDL_asin test cases */
  2423. static const SDLTest_TestCaseReference asinTestLimit = {
  2424. (SDLTest_TestCaseFp) asin_limitCases, "asin_limitCases",
  2425. "Check the edge of the domain (+/-1)", TEST_ENABLED
  2426. };
  2427. static const SDLTest_TestCaseReference asinTestOutOfDomain = {
  2428. (SDLTest_TestCaseFp) asin_outOfDomainCases, "asin_outOfDomainCases",
  2429. "Check a for value outside the domain", TEST_ENABLED
  2430. };
  2431. static const SDLTest_TestCaseReference asinTestNan = {
  2432. (SDLTest_TestCaseFp) asin_nanCase, "asin_nanCase",
  2433. "Check the NaN special case", TEST_ENABLED
  2434. };
  2435. static const SDLTest_TestCaseReference asinTestPrecision = {
  2436. (SDLTest_TestCaseFp) asin_precisionTest, "asin_precisionTest",
  2437. "Check asin precision to the tenth decimal", TEST_ENABLED
  2438. };
  2439. /* SDL_atan test cases */
  2440. static const SDLTest_TestCaseReference atanTestLimit = {
  2441. (SDLTest_TestCaseFp) atan_limitCases, "atan_limitCases",
  2442. "Check the edge of the domain (+/- infinity)", TEST_ENABLED
  2443. };
  2444. static const SDLTest_TestCaseReference atanTestZero = {
  2445. (SDLTest_TestCaseFp) atan_zeroCases, "atan_zeroCases",
  2446. "Check for positive and negative zero", TEST_ENABLED
  2447. };
  2448. static const SDLTest_TestCaseReference atanTestNan = {
  2449. (SDLTest_TestCaseFp) atan_nanCase, "atan_nanCase",
  2450. "Check the NaN special case", TEST_ENABLED
  2451. };
  2452. static const SDLTest_TestCaseReference atanTestPrecision = {
  2453. (SDLTest_TestCaseFp) atan_precisionTest, "atan_precisionTest",
  2454. "Check atan precision to the tenth decimal", TEST_ENABLED
  2455. };
  2456. static const SDLTest_TestCaseReference *mathTests[] = {
  2457. &floorTestInf, &floorTestZero, &floorTestNan,
  2458. &floorTestRound, &floorTestFraction, &floorTestRange,
  2459. &ceilTestInf, &ceilTestZero, &ceilTestNan,
  2460. &ceilTestRound, &ceilTestFraction, &ceilTestRange,
  2461. &truncTestInf, &truncTestZero, &truncTestNan,
  2462. &truncTestRound, &truncTestFraction, &truncTestRange,
  2463. &roundTestInf, &roundTestZero, &roundTestNan,
  2464. &roundTestRound, &roundTestFraction, &roundTestRange,
  2465. &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
  2466. &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
  2467. &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
  2468. &fmodTestNan, &fmodTestRegular, &fmodTestRange,
  2469. &expTestInf, &expTestZero, &expTestOverflow,
  2470. &expTestBase, &expTestRegular,
  2471. &logTestLimit, &logTestNan,
  2472. &logTestBase, &logTestRegular,
  2473. &log10TestLimit, &log10TestNan,
  2474. &log10TestBase, &log10TestRegular,
  2475. &powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
  2476. &powTestBaseInf1, &powTestBaseInf2,
  2477. &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
  2478. &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
  2479. &powTestRegular, &powTestPowOf2, &powTestRange,
  2480. &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
  2481. &sqrtTestBase, &sqrtTestRegular,
  2482. &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
  2483. &scalbnTestNan, &scalbnTestRegular,
  2484. &cosTestInf, &cosTestNan, &cosTestRegular,
  2485. &cosTestPrecision, &cosTestRange,
  2486. &sinTestInf, &sinTestNan, &sinTestRegular,
  2487. &sinTestPrecision, &sinTestRange,
  2488. &tanTestInf, &tanTestNan, &tanTestZero, &tanTestPrecision,
  2489. &acosTestLimit, &acosTestOutOfDomain, &acosTestNan, &acosTestPrecision,
  2490. &asinTestLimit, &asinTestOutOfDomain, &asinTestNan, &asinTestPrecision,
  2491. &atanTestLimit, &atanTestZero, &atanTestNan, &atanTestPrecision,
  2492. NULL
  2493. };
  2494. SDLTest_TestSuiteReference mathTestSuite = { "Math", NULL, mathTests, NULL };