testautomation_math.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328
  1. /**
  2. * Math test suite
  3. */
  4. #include <float.h>
  5. #include <math.h>
  6. #include "SDL.h"
  7. #include "SDL_test.h"
  8. /* ================= Test Constants ================== */
  9. /* Range tests parameters */
  10. #define RANGE_TEST_ITERATIONS 10000000
  11. #define RANGE_TEST_STEP ((Uint32)(SDL_MAX_UINT32 / RANGE_TEST_ITERATIONS))
  12. /* Margin of error for imprecise tests */
  13. #define EPSILON 1.0E-10
  14. /* Euler constant (used in exp/log) */
  15. #ifndef M_E
  16. #define EULER 2.7182818284590450907955982984276488423347473144531250
  17. #else
  18. #define EULER M_E
  19. #endif
  20. #define IS_INFINITY(V) fpclassify(V) == FP_INFINITE
  21. /* Square root of 3 (used in atan2) */
  22. #define SQRT3 1.7320508075688771931766041234368458390235900878906250
  23. /* ================= Test Structs ================== */
  24. /**
  25. * Stores a single input and the expected result
  26. */
  27. typedef struct
  28. {
  29. double input;
  30. double expected;
  31. } d_to_d;
  32. /**
  33. * Stores a pair of inputs and the expected result
  34. */
  35. typedef struct
  36. {
  37. double x_input, y_input;
  38. double expected;
  39. } dd_to_d;
  40. #define DD_TO_D_CASE(IDX, X, Y, E) do { \
  41. cases[IDX].x_input = (X); \
  42. cases[IDX].y_input = (Y); \
  43. cases[IDX].expected = (E); \
  44. } while (0)
  45. /*
  46. NB: You cannot create an array of these structures containing INFINITY or NAN.
  47. On platforms such as OS/2, they are defined as 'extern const double' making them
  48. not compile-time constant.
  49. */
  50. /* ================= Test Helpers ================== */
  51. typedef double(SDLCALL *d_to_d_func)(double);
  52. typedef double(SDLCALL *dd_to_d_func)(double, double);
  53. /**
  54. * \brief Runs all the cases on a given function with a signature double -> double.
  55. * The result is expected to be exact.
  56. *
  57. * \param func_name a printable name for the tested function.
  58. * \param func the function to call.
  59. * \param cases an array of all the cases.
  60. * \param cases_size the size of the cases array.
  61. */
  62. static int
  63. helper_dtod(const char *func_name, d_to_d_func func,
  64. const d_to_d *cases, const size_t cases_size)
  65. {
  66. Uint32 i;
  67. for (i = 0; i < cases_size; i++) {
  68. const double result = func(cases[i].input);
  69. SDLTest_AssertCheck((result - cases[i].expected) < FLT_EPSILON,
  70. "%s(%f), expected %f, got %f",
  71. func_name,
  72. cases[i].input,
  73. cases[i].expected, result);
  74. }
  75. return TEST_COMPLETED;
  76. }
  77. /**
  78. * \brief Runs all the cases on a given function with a signature double -> double.
  79. * Checks if the result between expected +/- EPSILON.
  80. *
  81. * \param func_name a printable name for the tested function.
  82. * \param func the function to call.
  83. * \param cases an array of all the cases.
  84. * \param cases_size the size of the cases array.
  85. */
  86. static int
  87. helper_dtod_inexact(const char *func_name, d_to_d_func func,
  88. const d_to_d *cases, const size_t cases_size)
  89. {
  90. Uint32 i;
  91. for (i = 0; i < cases_size; i++) {
  92. const double result = func(cases[i].input);
  93. double diff = result - cases[i].expected;
  94. double max_err = (cases[i].expected + 1.) * EPSILON;
  95. if (diff < 0) {
  96. diff = -diff;
  97. }
  98. if (max_err < 0) {
  99. max_err = -max_err;
  100. }
  101. SDLTest_AssertCheck(diff <= max_err,
  102. "%s(%f), expected [%f,%f], got %f",
  103. func_name,
  104. cases[i].input,
  105. cases[i].expected - EPSILON,
  106. cases[i].expected + EPSILON,
  107. result);
  108. }
  109. return TEST_COMPLETED;
  110. }
  111. /**
  112. * \brief Runs all the cases on a given function with a signature
  113. * (double, double) -> double. The result is expected to be exact.
  114. *
  115. * \param func_name a printable name for the tested function.
  116. * \param func the function to call.
  117. * \param cases an array of all the cases.
  118. * \param cases_size the size of the cases array.
  119. */
  120. static int
  121. helper_ddtod(const char *func_name, dd_to_d_func func,
  122. const dd_to_d *cases, const size_t cases_size)
  123. {
  124. Uint32 i;
  125. for (i = 0; i < cases_size; i++) {
  126. const double result = func(cases[i].x_input, cases[i].y_input);
  127. /* By using the result as input, the compiler is less likely to use higher precision floating point number */
  128. (void)SDL_sin(result);
  129. SDLTest_AssertCheck(result == cases[i].expected,
  130. "%s(%f,%f), expected %f, got %f",
  131. func_name,
  132. cases[i].x_input, cases[i].y_input,
  133. cases[i].expected, result);
  134. }
  135. return TEST_COMPLETED;
  136. }
  137. /**
  138. * \brief Runs all the cases on a given function with a signature
  139. * (double, double) -> double. Checks if the result between expected +/- EPSILON.
  140. *
  141. * \param func_name a printable name for the tested function.
  142. * \param func the function to call.
  143. * \param cases an array of all the cases.
  144. * \param cases_size the size of the cases array.
  145. */
  146. static int
  147. helper_ddtod_inexact(const char *func_name, dd_to_d_func func,
  148. const dd_to_d *cases, const size_t cases_size)
  149. {
  150. Uint32 i;
  151. for (i = 0; i < cases_size; i++) {
  152. const double result = func(cases[i].x_input, cases[i].y_input);
  153. double diff = result - cases[i].expected;
  154. double max_err = (cases[i].expected + 1.) * EPSILON;
  155. if (diff < 0) {
  156. diff = -diff;
  157. }
  158. if (max_err < 0) {
  159. max_err = -max_err;
  160. }
  161. SDLTest_AssertCheck(diff <= max_err,
  162. "%s(%f,%f), expected [%f,%f], got %f",
  163. func_name,
  164. cases[i].x_input, cases[i].y_input,
  165. cases[i].expected - EPSILON,
  166. cases[i].expected + EPSILON,
  167. result);
  168. }
  169. return TEST_COMPLETED;
  170. }
  171. /**
  172. * \brief Runs a range of values on a given function with a signature double -> double
  173. *
  174. * This function is only meant to test functions that returns the input value if it is
  175. * integral: f(x) -> x for x in N.
  176. *
  177. * \param func_name a printable name for the tested function.
  178. * \param func the function to call.
  179. */
  180. static int
  181. helper_range(const char *func_name, d_to_d_func func)
  182. {
  183. Uint32 i;
  184. double test_value = 0.0;
  185. SDLTest_AssertPass("%s: Testing a range of %u values with steps of %" SDL_PRIu32,
  186. func_name,
  187. RANGE_TEST_ITERATIONS,
  188. RANGE_TEST_STEP);
  189. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  190. double result;
  191. /* These are tested elsewhere */
  192. if (isnan(test_value) || isinf(test_value)) {
  193. continue;
  194. }
  195. result = func(test_value);
  196. if (result != test_value) { /* Only log failures to save performances */
  197. SDLTest_AssertCheck(SDL_FALSE,
  198. "%s(%.1f), expected %.1f, got %.1f",
  199. func_name, test_value,
  200. test_value, result);
  201. return TEST_ABORTED;
  202. }
  203. }
  204. return TEST_COMPLETED;
  205. }
  206. /* ================= Test Case Implementation ================== */
  207. /* SDL_floor tests functions */
  208. /**
  209. * Inputs: +/-Infinity.
  210. * Expected: Infinity is returned as-is.
  211. */
  212. static int
  213. floor_infCases(void *args)
  214. {
  215. double result;
  216. result = SDL_floor(INFINITY);
  217. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  218. "Floor(%f), expected %f, got %f",
  219. INFINITY, INFINITY, result);
  220. result = SDL_floor(-INFINITY);
  221. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  222. "Floor(%f), expected %f, got %f",
  223. -INFINITY, -INFINITY, result);
  224. return TEST_COMPLETED;
  225. }
  226. /**
  227. * Inputs: +/-0.0.
  228. * Expected: Zero is returned as-is.
  229. */
  230. static int
  231. floor_zeroCases(void *args)
  232. {
  233. const d_to_d zero_cases[] = {
  234. { 0.0, 0.0 },
  235. { -0.0, -0.0 }
  236. };
  237. return helper_dtod("Floor", SDL_floor, zero_cases, SDL_arraysize(zero_cases));
  238. }
  239. /**
  240. * Input: NAN.
  241. * Expected: NAN is returned.
  242. */
  243. static int
  244. floor_nanCase(void *args)
  245. {
  246. const double result = SDL_floor(NAN);
  247. SDLTest_AssertCheck(isnan(result),
  248. "Floor(nan), expected nan, got %f",
  249. result);
  250. return TEST_COMPLETED;
  251. }
  252. /**
  253. * Inputs: integral values.
  254. * Expected: the input value is returned as-is.
  255. */
  256. static int
  257. floor_roundNumbersCases(void *args)
  258. {
  259. const d_to_d round_cases[] = {
  260. { 1.0, 1.0 },
  261. { -1.0, -1.0 },
  262. { 15.0, 15.0 },
  263. { -15.0, -15.0 },
  264. { 125.0, 125.0 },
  265. { -125.0, -125.0 },
  266. { 1024.0, 1024.0 },
  267. { -1024.0, -1024.0 }
  268. };
  269. return helper_dtod("Floor", SDL_floor, round_cases, SDL_arraysize(round_cases));
  270. }
  271. /**
  272. * Inputs: fractional values.
  273. * Expected: the lower integral value is returned.
  274. */
  275. static int
  276. floor_fractionCases(void *args)
  277. {
  278. const d_to_d frac_cases[] = {
  279. { 1.0 / 2.0, 0.0 },
  280. { -1.0 / 2.0, -1.0 },
  281. { 4.0 / 3.0, 1.0 },
  282. { -4.0 / 3.0, -2.0 },
  283. { 76.0 / 7.0, 10.0 },
  284. { -76.0 / 7.0, -11.0 },
  285. { 535.0 / 8.0, 66.0 },
  286. { -535.0 / 8.0, -67.0 },
  287. { 19357.0 / 53.0, 365.0 },
  288. { -19357.0 / 53.0, -366.0 }
  289. };
  290. return helper_dtod("Floor", SDL_floor, frac_cases, SDL_arraysize(frac_cases));
  291. }
  292. /**
  293. * Inputs: values in the range [0, UINT32_MAX].
  294. * Expected: the input value is returned as-is.
  295. */
  296. static int
  297. floor_rangeTest(void *args)
  298. {
  299. return helper_range("Floor", SDL_floor);
  300. }
  301. /* SDL_ceil tests functions */
  302. /**
  303. * Inputs: +/-Infinity.
  304. * Expected: Infinity is returned as-is.
  305. */
  306. static int
  307. ceil_infCases(void *args)
  308. {
  309. double result;
  310. result = SDL_ceil(INFINITY);
  311. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  312. "Ceil(%f), expected %f, got %f",
  313. INFINITY, INFINITY, result);
  314. result = SDL_ceil(-INFINITY);
  315. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  316. "Ceil(%f), expected %f, got %f",
  317. -INFINITY, -INFINITY, result);
  318. return TEST_COMPLETED;
  319. }
  320. /**
  321. * Inputs: +/-0.0.
  322. * Expected: Zero is returned as-is.
  323. */
  324. static int
  325. ceil_zeroCases(void *args)
  326. {
  327. const d_to_d zero_cases[] = {
  328. { 0.0, 0.0 },
  329. { -0.0, -0.0 }
  330. };
  331. return helper_dtod("Ceil", SDL_ceil, zero_cases, SDL_arraysize(zero_cases));
  332. }
  333. /**
  334. * Input: NAN.
  335. * Expected: NAN is returned.
  336. */
  337. static int
  338. ceil_nanCase(void *args)
  339. {
  340. const double result = SDL_ceil(NAN);
  341. SDLTest_AssertCheck(isnan(result),
  342. "Ceil(nan), expected nan, got %f",
  343. result);
  344. return TEST_COMPLETED;
  345. }
  346. /**
  347. * Inputs: integral values.
  348. * Expected: the input value is returned as-is.
  349. */
  350. static int
  351. ceil_roundNumbersCases(void *args)
  352. {
  353. const d_to_d round_cases[] = {
  354. { 1.0, 1.0 },
  355. { -1.0, -1.0 },
  356. { 15.0, 15.0 },
  357. { -15.0, -15.0 },
  358. { 125.0, 125.0 },
  359. { -125.0, -125.0 },
  360. { 1024.0, 1024.0 },
  361. { -1024.0, -1024.0 }
  362. };
  363. return helper_dtod("Ceil", SDL_ceil, round_cases, SDL_arraysize(round_cases));
  364. }
  365. /**
  366. * Inputs: fractional values.
  367. * Expected: the higher integral value is returned.
  368. */
  369. static int
  370. ceil_fractionCases(void *args)
  371. {
  372. const d_to_d frac_cases[] = {
  373. { 1.0 / 2.0, 1.0 },
  374. { -1.0 / 2.0, -0.0 },
  375. { 4.0 / 3.0, 2.0 },
  376. { -4.0 / 3.0, -1.0 },
  377. { 76.0 / 7.0, 11.0 },
  378. { -76.0 / 7.0, -10.0 },
  379. { 535.0 / 8.0, 67.0 },
  380. { -535.0 / 8.0, -66.0 },
  381. { 19357.0 / 53.0, 366.0 },
  382. { -19357.0 / 53.0, -365.0 }
  383. };
  384. return helper_dtod("Ceil", SDL_ceil, frac_cases, SDL_arraysize(frac_cases));
  385. }
  386. /**
  387. * Inputs: values in the range [0, UINT32_MAX].
  388. * Expected: the input value is returned as-is.
  389. */
  390. static int
  391. ceil_rangeTest(void *args)
  392. {
  393. return helper_range("Ceil", SDL_ceil);
  394. }
  395. /* SDL_trunc tests functions */
  396. /**
  397. * Inputs: +/-Infinity.
  398. * Expected: Infinity is returned as-is.
  399. */
  400. static int
  401. trunc_infCases(void *args)
  402. {
  403. double result;
  404. result = SDL_trunc(INFINITY);
  405. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  406. "Trunc(%f), expected %f, got %f",
  407. INFINITY, INFINITY, result);
  408. result = SDL_trunc(-INFINITY);
  409. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  410. "Trunc(%f), expected %f, got %f",
  411. -INFINITY, -INFINITY, result);
  412. return TEST_COMPLETED;
  413. }
  414. /**
  415. * Inputs: +/-0.0.
  416. * Expected: Zero is returned as-is.
  417. */
  418. static int
  419. trunc_zeroCases(void *args)
  420. {
  421. const d_to_d zero_cases[] = {
  422. { 0.0, 0.0 },
  423. { -0.0, -0.0 }
  424. };
  425. return helper_dtod("Trunc", SDL_trunc, zero_cases, SDL_arraysize(zero_cases));
  426. }
  427. /**
  428. * Input: NAN.
  429. * Expected: NAN is returned.
  430. */
  431. static int
  432. trunc_nanCase(void *args)
  433. {
  434. const double result = SDL_trunc(NAN);
  435. SDLTest_AssertCheck(isnan(result),
  436. "Trunc(nan), expected nan, got %f",
  437. result);
  438. return TEST_COMPLETED;
  439. }
  440. /**
  441. * Inputs: integral values.
  442. * Expected: the input value is returned as-is.
  443. */
  444. static int
  445. trunc_roundNumbersCases(void *args)
  446. {
  447. const d_to_d round_cases[] = {
  448. { 1.0, 1.0 },
  449. { -1.0, -1.0 },
  450. { 15.0, 15.0 },
  451. { -15.0, -15.0 },
  452. { 125.0, 125.0 },
  453. { -125.0, -125.0 },
  454. { 1024.0, 1024.0 },
  455. { -1024.0, -1024.0 }
  456. };
  457. return helper_dtod("Trunc", SDL_trunc, round_cases, SDL_arraysize(round_cases));
  458. }
  459. /**
  460. * Inputs: fractional values.
  461. * Expected: the integral part is returned.
  462. */
  463. static int
  464. trunc_fractionCases(void *args)
  465. {
  466. const d_to_d frac_cases[] = {
  467. { 1.0 / 2.0, 0.0 },
  468. { -1.0 / 2.0, -0.0 },
  469. { 4.0 / 3.0, 1.0 },
  470. { -4.0 / 3.0, -1.0 },
  471. { 76.0 / 7.0, 10.0 },
  472. { -76.0 / 7.0, -10.0 },
  473. { 535.0 / 8.0, 66.0 },
  474. { -535.0 / 8.0, -66.0 },
  475. { 19357.0 / 53.0, 365.0 },
  476. { -19357.0 / 53.0, -365.0 }
  477. };
  478. return helper_dtod("Trunc", SDL_trunc, frac_cases, SDL_arraysize(frac_cases));
  479. }
  480. /**
  481. * Inputs: values in the range [0, UINT32_MAX].
  482. * Expected: the input value is returned as-is.
  483. */
  484. static int
  485. trunc_rangeTest(void *args)
  486. {
  487. return helper_range("Trunc", SDL_trunc);
  488. }
  489. /* SDL_round tests functions */
  490. /**
  491. * Inputs: +/-Infinity.
  492. * Expected: Infinity is returned as-is.
  493. */
  494. static int
  495. round_infCases(void *args)
  496. {
  497. double result;
  498. result = SDL_round(INFINITY);
  499. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  500. "Round(%f), expected %f, got %f",
  501. INFINITY, INFINITY, result);
  502. result = SDL_round(-INFINITY);
  503. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  504. "Round(%f), expected %f, got %f",
  505. -INFINITY, -INFINITY, result);
  506. return TEST_COMPLETED;
  507. }
  508. /**
  509. * Inputs: +/-0.0.
  510. * Expected: Zero is returned as-is.
  511. */
  512. static int
  513. round_zeroCases(void *args)
  514. {
  515. const d_to_d zero_cases[] = {
  516. { 0.0, 0.0 },
  517. { -0.0, -0.0 }
  518. };
  519. return helper_dtod("Round", SDL_round, zero_cases, SDL_arraysize(zero_cases));
  520. }
  521. /**
  522. * Input: NAN.
  523. * Expected: NAN is returned.
  524. */
  525. static int
  526. round_nanCase(void *args)
  527. {
  528. const double result = SDL_round(NAN);
  529. SDLTest_AssertCheck(isnan(result),
  530. "Round(nan), expected nan, got %f",
  531. result);
  532. return TEST_COMPLETED;
  533. }
  534. /**
  535. * Inputs: integral values.
  536. * Expected: the input value is returned as-is.
  537. */
  538. static int
  539. round_roundNumbersCases(void *args)
  540. {
  541. const d_to_d round_cases[] = {
  542. { 1.0, 1.0 },
  543. { -1.0, -1.0 },
  544. { 15.0, 15.0 },
  545. { -15.0, -15.0 },
  546. { 125.0, 125.0 },
  547. { -125.0, -125.0 },
  548. { 1024.0, 1024.0 },
  549. { -1024.0, -1024.0 }
  550. };
  551. return helper_dtod("Round", SDL_round, round_cases, SDL_arraysize(round_cases));
  552. }
  553. /**
  554. * Inputs: fractional values.
  555. * Expected: the nearest integral value is returned.
  556. */
  557. static int
  558. round_fractionCases(void *args)
  559. {
  560. const d_to_d frac_cases[] = {
  561. { 1.0 / 2.0, 1.0 },
  562. { -1.0 / 2.0, -1.0 },
  563. { 4.0 / 3.0, 1.0 },
  564. { -4.0 / 3.0, -1.0 },
  565. { 76.0 / 7.0, 11.0 },
  566. { -76.0 / 7.0, -11.0 },
  567. { 535.0 / 8.0, 67.0 },
  568. { -535.0 / 8.0, -67.0 },
  569. { 19357.0 / 53.0, 365.0 },
  570. { -19357.0 / 53.0, -365.0 }
  571. };
  572. return helper_dtod("Round", SDL_round, frac_cases, SDL_arraysize(frac_cases));
  573. }
  574. /**
  575. * Inputs: values in the range [0, UINT32_MAX].
  576. * Expected: the input value is returned as-is.
  577. */
  578. static int
  579. round_rangeTest(void *args)
  580. {
  581. return helper_range("Round", SDL_round);
  582. }
  583. /* SDL_fabs tests functions */
  584. /**
  585. * Inputs: +/-Infinity.
  586. * Expected: Positive Infinity is returned.
  587. */
  588. static int
  589. fabs_infCases(void *args)
  590. {
  591. double result;
  592. result = SDL_fabs(INFINITY);
  593. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  594. "Fabs(%f), expected %f, got %f",
  595. INFINITY, INFINITY, result);
  596. result = SDL_fabs(-INFINITY);
  597. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  598. "Fabs(%f), expected %f, got %f",
  599. -INFINITY, INFINITY, result);
  600. return TEST_COMPLETED;
  601. }
  602. /**
  603. * Inputs: +/-0.0.
  604. * Expected: Positive zero is returned.
  605. */
  606. static int
  607. fabs_zeroCases(void *args)
  608. {
  609. const d_to_d zero_cases[] = {
  610. { 0.0, 0.0 },
  611. { -0.0, 0.0 }
  612. };
  613. return helper_dtod("Fabs", SDL_fabs, zero_cases, SDL_arraysize(zero_cases));
  614. }
  615. /**
  616. * Input: NAN.
  617. * Expected: NAN is returned.
  618. */
  619. static int
  620. fabs_nanCase(void *args)
  621. {
  622. const double result = SDL_fabs(NAN);
  623. SDLTest_AssertCheck(isnan(result),
  624. "Fabs(nan), expected nan, got %f",
  625. result);
  626. return TEST_COMPLETED;
  627. }
  628. /**
  629. * Inputs: values in the range [0, UINT32_MAX].
  630. * Expected: the input value is returned as-is.
  631. */
  632. static int
  633. fabs_rangeTest(void *args)
  634. {
  635. return helper_range("Fabs", SDL_fabs);
  636. }
  637. /* SDL_copysign tests functions */
  638. /**
  639. * Inputs: (+/-Infinity, +/-1.0).
  640. * Expected: Infinity with the sign of 1.0 is returned.
  641. */
  642. static int
  643. copysign_infCases(void *args)
  644. {
  645. double result;
  646. result = SDL_copysign(INFINITY, -1.0);
  647. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  648. "Copysign(%f,%.1f), expected %f, got %f",
  649. INFINITY, -1.0, -INFINITY, result);
  650. result = SDL_copysign(INFINITY, 1.0);
  651. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  652. "Copysign(%f,%.1f), expected %f, got %f",
  653. INFINITY, 1.0, INFINITY, result);
  654. result = SDL_copysign(-INFINITY, -1.0);
  655. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  656. "Copysign(%f,%.1f), expected %f, got %f",
  657. -INFINITY, -1.0, -INFINITY, result);
  658. result = SDL_copysign(-INFINITY, 1.0);
  659. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  660. "Copysign(%f,%.1f), expected %f, got %f",
  661. -INFINITY, 1.0, INFINITY, result);
  662. return TEST_COMPLETED;
  663. }
  664. /**
  665. * Inputs: (+/-0.0, +/-1.0).
  666. * Expected: 0.0 with the sign of 1.0 is returned.
  667. */
  668. static int
  669. copysign_zeroCases(void *args)
  670. {
  671. const dd_to_d zero_cases[] = {
  672. { 0.0, 1.0, 0.0 },
  673. { 0.0, -1.0, -0.0 },
  674. { -0.0, 1.0, 0.0 },
  675. { -0.0, -1.0, -0.0 }
  676. };
  677. return helper_ddtod("Copysign", SDL_copysign, zero_cases, SDL_arraysize(zero_cases));
  678. }
  679. /**
  680. * Inputs: (NAN, +/-1.0).
  681. * Expected: NAN with the sign of 1.0 is returned.
  682. * NOTE: On some platforms signed NAN is not supported, so we only check if the result is still NAN.
  683. */
  684. static int
  685. copysign_nanCases(void *args)
  686. {
  687. double result;
  688. result = SDL_copysign(NAN, 1.0);
  689. SDLTest_AssertCheck(isnan(result),
  690. "Copysign(nan,1.0), expected nan, got %f",
  691. result);
  692. result = SDL_copysign(NAN, -1.0);
  693. SDLTest_AssertCheck(isnan(result),
  694. "Copysign(nan,-1.0), expected nan, got %f",
  695. result);
  696. return TEST_COMPLETED;
  697. }
  698. /**
  699. * Inputs: values in the range [0, UINT32_MAX], +/-1.0.
  700. * Expected: the input value with the sign of 1.0 is returned.
  701. */
  702. static int
  703. copysign_rangeTest(void *args)
  704. {
  705. Uint32 i;
  706. double test_value = 0.0;
  707. SDLTest_AssertPass("Copysign: Testing a range of %u values with steps of %" SDL_PRIu32,
  708. RANGE_TEST_ITERATIONS,
  709. RANGE_TEST_STEP);
  710. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  711. double result;
  712. /* These are tested elsewhere */
  713. if (isnan(test_value) || isinf(test_value)) {
  714. continue;
  715. }
  716. /* Only log failures to save performances */
  717. result = SDL_copysign(test_value, 1.0);
  718. if (result != test_value) {
  719. SDLTest_AssertCheck(SDL_FALSE,
  720. "Copysign(%.1f,%.1f), expected %.1f, got %.1f",
  721. test_value, 1.0, test_value, result);
  722. return TEST_ABORTED;
  723. }
  724. result = SDL_copysign(test_value, -1.0);
  725. if (result != -test_value) {
  726. SDLTest_AssertCheck(SDL_FALSE,
  727. "Copysign(%.1f,%.1f), expected %.1f, got %.1f",
  728. test_value, -1.0, -test_value, result);
  729. return TEST_ABORTED;
  730. }
  731. }
  732. return TEST_COMPLETED;
  733. }
  734. /* SDL_fmod tests functions */
  735. /**
  736. * Inputs: (+/-Infinity, +/-1.0).
  737. * Expected: NAN is returned.
  738. */
  739. static int
  740. fmod_divOfInfCases(void *args)
  741. {
  742. double result;
  743. result = SDL_fmod(INFINITY, -1.0);
  744. SDLTest_AssertCheck(isnan(result),
  745. "Fmod(%f,%.1f), expected %f, got %f",
  746. INFINITY, -1.0, NAN, result);
  747. result = SDL_fmod(INFINITY, 1.0);
  748. SDLTest_AssertCheck(isnan(result),
  749. "Fmod(%f,%.1f), expected %f, got %f",
  750. INFINITY, 1.0, NAN, result);
  751. result = SDL_fmod(-INFINITY, -1.0);
  752. SDLTest_AssertCheck(isnan(result),
  753. "Fmod(%f,%.1f), expected %f, got %f",
  754. -INFINITY, -1.0, NAN, result);
  755. result = SDL_fmod(-INFINITY, 1.0);
  756. SDLTest_AssertCheck(isnan(result),
  757. "Fmod(%f,%.1f), expected %f, got %f",
  758. -INFINITY, 1.0, NAN, result);
  759. return TEST_COMPLETED;
  760. }
  761. /**
  762. * Inputs: (+/-1.0, +/-Infinity).
  763. * Expected: 1.0 is returned as-is.
  764. */
  765. static int
  766. fmod_divByInfCases(void *args)
  767. {
  768. double result;
  769. result = SDL_fmod(1.0, INFINITY);
  770. SDLTest_AssertCheck(1.0 == result,
  771. "Fmod(%.1f,%f), expected %f, got %f",
  772. 1.0, INFINITY, 1.0, result);
  773. result = SDL_fmod(-1.0, INFINITY);
  774. SDLTest_AssertCheck(-1.0 == result,
  775. "Fmod(%.1f,%f), expected %f, got %f",
  776. -1.0, INFINITY, -1.0, result);
  777. result = SDL_fmod(1.0, -INFINITY);
  778. SDLTest_AssertCheck(1.0 == result,
  779. "Fmod(%.1f,%f), expected %f, got %f",
  780. 1.0, -INFINITY, 1.0, result);
  781. result = SDL_fmod(-1.0, -INFINITY);
  782. SDLTest_AssertCheck(-1.0 == result,
  783. "Fmod(%.1f,%f), expected %f, got %f",
  784. -1.0, -INFINITY, -1.0, result);
  785. return TEST_COMPLETED;
  786. }
  787. /**
  788. * Inputs: (+/-0.0, +/-1.0).
  789. * Expected: Zero is returned as-is.
  790. */
  791. static int
  792. fmod_divOfZeroCases(void *args)
  793. {
  794. const dd_to_d zero_cases[] = {
  795. { 0.0, 1.0, 0.0 },
  796. { 0.0, -1.0, 0.0 },
  797. { -0.0, 1.0, -0.0 },
  798. { -0.0, -1.0, -0.0 }
  799. };
  800. return helper_ddtod("Fmod", SDL_fmod, zero_cases, SDL_arraysize(zero_cases));
  801. }
  802. /**
  803. * Inputs: (+/-1.0, +/-0.0).
  804. * Expected: NAN is returned.
  805. */
  806. static int
  807. fmod_divByZeroCases(void *args)
  808. {
  809. double result;
  810. result = SDL_fmod(1.0, 0.0);
  811. SDLTest_AssertCheck(isnan(result),
  812. "Fmod(1.0,0.0), expected nan, got %f",
  813. result);
  814. result = SDL_fmod(-1.0, 0.0);
  815. SDLTest_AssertCheck(isnan(result),
  816. "Fmod(-1.0,0.0), expected nan, got %f",
  817. result);
  818. result = SDL_fmod(1.0, -0.0);
  819. SDLTest_AssertCheck(isnan(result),
  820. "Fmod(1.0,-0.0), expected nan, got %f",
  821. result);
  822. result = SDL_fmod(-1.0, -0.0);
  823. SDLTest_AssertCheck(isnan(result),
  824. "Fmod(-1.0,-0.0), expected nan, got %f",
  825. result);
  826. return TEST_COMPLETED;
  827. }
  828. /**
  829. * Inputs: all permutation of NAN and +/-1.0.
  830. * Expected: NAN is returned.
  831. */
  832. static int
  833. fmod_nanCases(void *args)
  834. {
  835. double result;
  836. result = SDL_fmod(NAN, 1.0);
  837. SDLTest_AssertCheck(isnan(result),
  838. "Fmod(nan,1.0), expected nan, got %f",
  839. result);
  840. result = SDL_fmod(NAN, -1.0);
  841. SDLTest_AssertCheck(isnan(result),
  842. "Fmod(nan,-1.0), expected nan, got %f",
  843. result);
  844. result = SDL_fmod(1.0, NAN);
  845. SDLTest_AssertCheck(isnan(result),
  846. "Fmod(1.0,nan), expected nan, got %f",
  847. result);
  848. result = SDL_fmod(-1.0, NAN);
  849. SDLTest_AssertCheck(isnan(result),
  850. "Fmod(-1.0,nan), expected nan, got %f",
  851. result);
  852. return TEST_COMPLETED;
  853. }
  854. /**
  855. * Inputs: values within the domain of the function.
  856. * Expected: the correct result is returned.
  857. */
  858. static int
  859. fmod_regularCases(void *args)
  860. {
  861. const dd_to_d regular_cases[] = {
  862. { 3.5, 2.0, 1.5 },
  863. { -6.25, 3.0, -0.25 },
  864. { 7.5, 2.5, 0.0 },
  865. { 2.0 / 3.0, -1.0 / 3.0, 0.0 }
  866. };
  867. return helper_ddtod("Fmod", SDL_fmod, regular_cases, SDL_arraysize(regular_cases));
  868. }
  869. /**
  870. * Inputs: values in the range [0, UINT32_MAX] divided by 1.0.
  871. * Expected: Positive zero is always returned.
  872. */
  873. static int
  874. fmod_rangeTest(void *args)
  875. {
  876. Uint32 i;
  877. double test_value = 0.0;
  878. SDLTest_AssertPass("Fmod: Testing a range of %u values with steps of %" SDL_PRIu32,
  879. RANGE_TEST_ITERATIONS,
  880. RANGE_TEST_STEP);
  881. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  882. double result;
  883. /* These are tested elsewhere */
  884. if (isnan(test_value) || isinf(test_value)) {
  885. continue;
  886. }
  887. /* Only log failures to save performances */
  888. result = SDL_fmod(test_value, 1.0);
  889. if (0.0 != result) {
  890. SDLTest_AssertCheck(SDL_FALSE,
  891. "Fmod(%.1f,%.1f), expected %.1f, got %.1f",
  892. test_value, 1.0, 0.0, result);
  893. return TEST_ABORTED;
  894. }
  895. }
  896. return TEST_COMPLETED;
  897. }
  898. /* SDL_exp tests functions */
  899. /**
  900. * Inputs: +/-Infinity.
  901. * Expected: Infinity is returned as-is.
  902. */
  903. static int
  904. exp_infCases(void *args)
  905. {
  906. double result;
  907. result = SDL_exp(INFINITY);
  908. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  909. "Exp(%f), expected %f, got %f",
  910. INFINITY, INFINITY, result);
  911. result = SDL_exp(-INFINITY);
  912. SDLTest_AssertCheck(0.0 == result,
  913. "Exp(%f), expected %f, got %f",
  914. -INFINITY, 0.0, result);
  915. return TEST_COMPLETED;
  916. }
  917. /**
  918. * Inputs: +/-0.0.
  919. * Expected: 1.0 is returned.
  920. */
  921. static int
  922. exp_zeroCases(void *args)
  923. {
  924. const d_to_d zero_cases[] = {
  925. { 0.0, 1.0 },
  926. { -0.0, 1.0 }
  927. };
  928. return helper_dtod("Exp", SDL_exp, zero_cases, SDL_arraysize(zero_cases));
  929. }
  930. /**
  931. * Input: 710.0 (overflows for 64bits double).
  932. * Expected: Infinity is returned.
  933. * NOTE: This test is skipped for double types larger than 64 bits.
  934. */
  935. static int
  936. exp_overflowCase(void *args)
  937. {
  938. double result;
  939. if (sizeof(double) > 8) {
  940. return TEST_SKIPPED;
  941. }
  942. result = SDL_exp(710.0);
  943. SDLTest_AssertCheck(isinf(result),
  944. "Exp(%f), expected %f, got %f",
  945. 710.0, INFINITY, result);
  946. return TEST_COMPLETED;
  947. }
  948. /**
  949. * Input: 1.0
  950. * Expected: The euler constant.
  951. */
  952. static int
  953. exp_baseCase(void *args)
  954. {
  955. const double result = SDL_exp(1.0);
  956. SDLTest_AssertCheck(result >= EULER - EPSILON &&
  957. result <= EULER + EPSILON,
  958. "Exp(%f), expected [%f,%f], got %f",
  959. 1.0, EULER - EPSILON, EULER + EPSILON, result);
  960. return TEST_COMPLETED;
  961. }
  962. /**
  963. * Inputs: values within the domain of the function.
  964. * Expected: the correct result is returned.
  965. */
  966. static int
  967. exp_regularCases(void *args)
  968. {
  969. /* Hexadecimal floating constants are not supported on C89 compilers */
  970. const d_to_d regular_cases[] = {
  971. { -101.0, 1.36853947117385291381565719268793547578002532127613087E-44 },
  972. { -15.73, 0.00000014741707833928422931856502906683425990763681 },
  973. { -1.0, 0.36787944117144233402427744294982403516769409179688 },
  974. { -0.5, 0.60653065971263342426311737654032185673713684082031 },
  975. { 0.5, 1.64872127070012819416433558217249810695648193359375 },
  976. { 2.25, 9.48773583635852624240669683786109089851379394531250 },
  977. { 34.125, 661148770968660.375 },
  978. { 112.89, 10653788283588960962604279261058893737879589093376.0 },
  979. { 539.483, 1970107755334319939701129934673541628417235942656909222826926175622435588279443011110464355295725187195188154768877850257012251677751742837992843520967922303961718983154427294786640886286983037548604937796221048661733679844353544028160.0 },
  980. };
  981. return helper_dtod("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases));
  982. }
  983. /* SDL_log tests functions */
  984. /**
  985. * Inputs: Positive Infinity and +/-0.0.
  986. * Expected: Positive and negative Infinity respectively.
  987. */
  988. static int
  989. log_limitCases(void *args)
  990. {
  991. double result;
  992. result = SDL_log(INFINITY);
  993. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  994. "Log(%f), expected %f, got %f",
  995. INFINITY, INFINITY, result);
  996. result = SDL_log(0.0);
  997. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  998. "Log(%f), expected %f, got %f",
  999. 0.0, -INFINITY, result);
  1000. result = SDL_log(-0.0);
  1001. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  1002. "Log(%f), expected %f, got %f",
  1003. -0.0, -INFINITY, result);
  1004. return TEST_COMPLETED;
  1005. }
  1006. /**
  1007. * Inputs: 1.0 and the Euler constant.
  1008. * Expected: 0.0 and 1.0 respectively.
  1009. */
  1010. static int
  1011. log_baseCases(void *args)
  1012. {
  1013. double result;
  1014. result = SDL_log(1.0);
  1015. SDLTest_AssertCheck(0.0 == result,
  1016. "Log(%f), expected %f, got %f",
  1017. 1.0, 0.0, result);
  1018. result = SDL_log(EULER);
  1019. SDLTest_AssertCheck((result - 1.) < FLT_EPSILON,
  1020. "Log(%f), expected %f, got %f",
  1021. EULER, 1.0, result);
  1022. return TEST_COMPLETED;
  1023. }
  1024. /**
  1025. * Inputs: NAN and a negative value.
  1026. * Expected: NAN is returned.
  1027. */
  1028. static int
  1029. log_nanCases(void *args)
  1030. {
  1031. double result;
  1032. result = SDL_log(NAN);
  1033. SDLTest_AssertCheck(isnan(result),
  1034. "Log(%f), expected %f, got %f",
  1035. NAN, NAN, result);
  1036. result = SDL_log(-1234.5678);
  1037. SDLTest_AssertCheck(isnan(result),
  1038. "Log(%f), expected %f, got %f",
  1039. -1234.5678, NAN, result);
  1040. return TEST_COMPLETED;
  1041. }
  1042. /**
  1043. * Inputs: values within the domain of the function.
  1044. * Expected: the correct result is returned.
  1045. */
  1046. static int
  1047. log_regularCases(void *args)
  1048. {
  1049. const d_to_d regular_cases[] = {
  1050. { 5.0, 1.60943791243410028179994242236716672778129577636718750 },
  1051. { 10.0, 2.302585092994045901093613792909309267997741699218750 },
  1052. { 56.32, 4.031049711849786554296315443934872746467590332031250 },
  1053. { 789.123, 6.670922202231861497523368598194792866706848144531250 },
  1054. { 2734.876324, 7.91384149408957959792587644187733530998229980468750 }
  1055. };
  1056. return helper_dtod("Log", SDL_log, regular_cases, SDL_arraysize(regular_cases));
  1057. }
  1058. /* SDL_log10 tests functions */
  1059. /**
  1060. * Inputs: Positive Infinity and +/-0.0.
  1061. * Expected: Positive and negative Infinity respectively.
  1062. */
  1063. static int
  1064. log10_limitCases(void *args)
  1065. {
  1066. double result;
  1067. result = SDL_log10(INFINITY);
  1068. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1069. "Log10(%f), expected %f, got %f",
  1070. INFINITY, INFINITY, result);
  1071. result = SDL_log10(0.0);
  1072. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  1073. "Log10(%f), expected %f, got %f",
  1074. 0.0, -INFINITY, result);
  1075. result = SDL_log10(-0.0);
  1076. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  1077. "Log10(%f), expected %f, got %f",
  1078. -0.0, -INFINITY, result);
  1079. return TEST_COMPLETED;
  1080. }
  1081. /**
  1082. * Inputs: Powers of ten from 0 to 9.
  1083. * Expected: the exact power of ten is returned.
  1084. */
  1085. static int
  1086. log10_baseCases(void *args)
  1087. {
  1088. const d_to_d base_cases[] = {
  1089. { 1.0, 0.0 },
  1090. { 10.0, 1.0 },
  1091. { 100.0, 2.0 },
  1092. { 1000.0, 3.0 },
  1093. { 10000.0, 4.0 },
  1094. { 100000.0, 5.0 },
  1095. { 1000000.0, 6.0 },
  1096. { 10000000.0, 7.0 },
  1097. { 100000000.0, 8.0 },
  1098. { 1000000000.0, 9.0 },
  1099. };
  1100. return helper_dtod("Log10", SDL_log10, base_cases, SDL_arraysize(base_cases));
  1101. }
  1102. /**
  1103. * Inputs: NAN and a negative value.
  1104. * Expected: NAN is returned.
  1105. */
  1106. static int
  1107. log10_nanCases(void *args)
  1108. {
  1109. double result;
  1110. result = SDL_log10(NAN);
  1111. SDLTest_AssertCheck(isnan(result),
  1112. "Log10(%f), expected %f, got %f",
  1113. NAN, NAN, result);
  1114. result = SDL_log10(-1234.5678);
  1115. SDLTest_AssertCheck(isnan(result),
  1116. "Log10(%f), expected %f, got %f",
  1117. -1234.5678, NAN, result);
  1118. return TEST_COMPLETED;
  1119. }
  1120. /**
  1121. * Inputs: values within the domain of the function.
  1122. * Expected: the correct result is returned.
  1123. */
  1124. static int
  1125. log10_regularCases(void *args)
  1126. {
  1127. const d_to_d regular_cases[] = {
  1128. { 5.0, 0.698970004336018857493684208748163655400276184082031250 },
  1129. { 12.5, 1.09691001300805646145875016372883692383766174316406250 },
  1130. { 56.32, 1.750662646134055755453573510749265551567077636718750 },
  1131. { 789.123, 2.8971447016351858927407647570362314581871032714843750 },
  1132. { 2734.876324, 3.436937691540090433761633903486654162406921386718750 }
  1133. };
  1134. return helper_dtod_inexact("Log10", SDL_log10, regular_cases, SDL_arraysize(regular_cases));
  1135. }
  1136. /* SDL_pow tests functions */
  1137. /* Tests with positive and negative infinities as exponents */
  1138. /**
  1139. * Inputs: (-1.0, +/-Infinity).
  1140. * Expected: 1.0 is returned.
  1141. */
  1142. static int
  1143. pow_baseNOneExpInfCases(void *args)
  1144. {
  1145. double result;
  1146. result = SDL_pow(-1.0, INFINITY);
  1147. SDLTest_AssertCheck(1.0 == result,
  1148. "Pow(%f,%f), expected %f, got %f",
  1149. -1.0, INFINITY, 1.0, result);
  1150. result = SDL_pow(-1.0, -INFINITY);
  1151. SDLTest_AssertCheck(1.0 == result,
  1152. "Pow(%f,%f), expected %f, got %f",
  1153. -1.0, -INFINITY, 1.0, result);
  1154. return TEST_COMPLETED;
  1155. }
  1156. /**
  1157. * Inputs: (+/-0.0, -Infinity).
  1158. * Expected: Infinity is returned.
  1159. */
  1160. static int
  1161. pow_baseZeroExpNInfCases(void *args)
  1162. {
  1163. double result;
  1164. result = SDL_pow(0.0, -INFINITY);
  1165. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1166. "Pow(%f,%f), expected %f, got %f",
  1167. 0.0, -INFINITY, INFINITY, result);
  1168. result = SDL_pow(-0.0, -INFINITY);
  1169. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1170. "Pow(%f,%f), expected %f, got %f",
  1171. -0.0, -INFINITY, INFINITY, result);
  1172. return TEST_COMPLETED;
  1173. }
  1174. /**
  1175. * Inputs: (x, +/-Infinity) where x is not +/-0.0.
  1176. * Expected: 0.0 when x < 1, Infinity when x > 1.
  1177. */
  1178. static int
  1179. pow_expInfCases(void *args)
  1180. {
  1181. double result;
  1182. result = SDL_pow(0.5, INFINITY);
  1183. SDLTest_AssertCheck(0.0 == result,
  1184. "Pow(%f,%f), expected %f, got %f",
  1185. 0.5, INFINITY, 0.0, result);
  1186. result = SDL_pow(1.5, INFINITY);
  1187. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1188. "Pow(%f,%f), expected %f, got %f",
  1189. 1.5, INFINITY, INFINITY, result);
  1190. result = SDL_pow(0.5, -INFINITY);
  1191. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1192. "Pow(%f,%f), expected %f, got %f",
  1193. 0.5, INFINITY, INFINITY, result);
  1194. result = SDL_pow(1.5, -INFINITY);
  1195. SDLTest_AssertCheck(0.0 == result,
  1196. "Pow(%f,%f), expected %f, got %f",
  1197. 1.5, -INFINITY, 0.0, result);
  1198. return TEST_COMPLETED;
  1199. }
  1200. /* Tests with positive and negative infinities as base */
  1201. /**
  1202. * Inputs: (Positive Infinity, x) where x is not +/-0.0.
  1203. * Expected: 0.0 when x is < 0, positive Infinity when x > 0.
  1204. */
  1205. static int
  1206. pow_basePInfCases(void *args)
  1207. {
  1208. double result;
  1209. result = SDL_pow(INFINITY, -3.0);
  1210. SDLTest_AssertCheck(0.0 == result,
  1211. "Pow(%f,%f), expected %f, got %f",
  1212. INFINITY, -3.0, 0.0, result);
  1213. result = SDL_pow(INFINITY, 2.0);
  1214. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1215. "Pow(%f,%f), expected %f, got %f",
  1216. INFINITY, 2.0, INFINITY, result);
  1217. result = SDL_pow(INFINITY, -2.12345);
  1218. SDLTest_AssertCheck(0.0 == result,
  1219. "Pow(%f,%f), expected %f, got %f",
  1220. INFINITY, -2.12345, 0.0, result);
  1221. result = SDL_pow(INFINITY, 3.1345);
  1222. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1223. "Pow(%f,%f), expected %f, got %f",
  1224. INFINITY, 3.12345, INFINITY, result);
  1225. return TEST_COMPLETED;
  1226. }
  1227. /**
  1228. * Inputs: (Negative Infinity, x) where x is not +/-0.0.
  1229. * Expected:
  1230. * - -0.0 when x is a negative odd integer,
  1231. * - 0.0 when x is a negative even integer or negative non-integer,
  1232. * - Negative Infinity when x is a positive odd integer,
  1233. * - Positive Infinity when x is a positive even integer or positive non-integer.
  1234. */
  1235. static int
  1236. pow_baseNInfCases(void *args)
  1237. {
  1238. double result;
  1239. result = SDL_pow(-INFINITY, -3.0);
  1240. SDLTest_AssertCheck(-0.0 == result,
  1241. "Pow(%f,%f), expected %f, got %f",
  1242. -INFINITY, -3.0, -0.0, result);
  1243. result = SDL_pow(-INFINITY, -2.0);
  1244. SDLTest_AssertCheck(0.0 == result,
  1245. "Pow(%f,%f), expected %f, got %f",
  1246. -INFINITY, -2.0, 0.0, result);
  1247. result = SDL_pow(-INFINITY, -5.5);
  1248. SDLTest_AssertCheck(0.0 == result,
  1249. "Pow(%f,%f), expected %f, got %f",
  1250. -INFINITY, -5.5, 0.0, result);
  1251. result = SDL_pow(-INFINITY, 3.0);
  1252. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  1253. "Pow(%f,%f), expected %f, got %f",
  1254. -INFINITY, 3.0, -INFINITY, result);
  1255. result = SDL_pow(-INFINITY, 2.0);
  1256. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1257. "Pow(%f,%f), expected %f, got %f",
  1258. -INFINITY, 2.0, INFINITY, result);
  1259. result = SDL_pow(-INFINITY, 5.5);
  1260. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1261. "Pow(%f,%f), expected %f, got %f",
  1262. -INFINITY, 5.5, INFINITY, result);
  1263. return TEST_COMPLETED;
  1264. }
  1265. /* Tests related to NAN */
  1266. /**
  1267. * Inputs:
  1268. * - finite and negative base,
  1269. * - finite and non-integer exponent.
  1270. * Expected: NAN is returned.
  1271. */
  1272. static int
  1273. pow_badOperationCase(void *args)
  1274. {
  1275. const double result = SDL_pow(-2.0, 4.2);
  1276. SDLTest_AssertCheck(isnan(result),
  1277. "Pow(%f,%f), expected %f, got %f",
  1278. -2.0, 4.2, NAN, result);
  1279. return TEST_COMPLETED;
  1280. }
  1281. /**
  1282. * Inputs: (1.0, NAN)
  1283. * Expected: 1.0 is returned.
  1284. */
  1285. static int
  1286. pow_base1ExpNanCase(void *args)
  1287. {
  1288. const double result = SDL_pow(1.0, NAN);
  1289. SDLTest_AssertCheck(1.0 == result,
  1290. "Pow(%f,%f), expected %f, got %f",
  1291. 1.0, NAN, 1.0, result);
  1292. return TEST_COMPLETED;
  1293. }
  1294. /**
  1295. * Inputs: (NAN, +/-0.0)
  1296. * Expected: 1.0 is returned.
  1297. */
  1298. static int
  1299. pow_baseNanExp0Cases(void *args)
  1300. {
  1301. double result;
  1302. result = SDL_pow(NAN, 0.0);
  1303. SDLTest_AssertCheck(1.0 == result,
  1304. "Pow(%f,%f), expected %f, got %f",
  1305. NAN, 0.0, 1.0, result);
  1306. result = SDL_pow(NAN, -0.0);
  1307. SDLTest_AssertCheck(1.0 == result,
  1308. "Pow(%f,%f), expected %f, got %f",
  1309. NAN, -0.0, 1.0, result);
  1310. return TEST_COMPLETED;
  1311. }
  1312. /**
  1313. * Inputs: NAN as base, exponent or both.
  1314. * Expected: NAN is returned.
  1315. */
  1316. static int
  1317. pow_nanArgsCases(void *args)
  1318. {
  1319. double result;
  1320. result = SDL_pow(7.8, NAN);
  1321. SDLTest_AssertCheck(isnan(result),
  1322. "Pow(%f,%f), expected %f, got %f",
  1323. 7.8, NAN, NAN, result);
  1324. result = SDL_pow(NAN, 10.0);
  1325. SDLTest_AssertCheck(isnan(result),
  1326. "Pow(%f,%f), expected %f, got %f",
  1327. NAN, 10.0, NAN, result);
  1328. result = SDL_pow(NAN, NAN);
  1329. SDLTest_AssertCheck(isnan(result),
  1330. "Pow(%f,%f), expected %f, got %f",
  1331. NAN, NAN, NAN, result);
  1332. return TEST_COMPLETED;
  1333. }
  1334. /* Tests with positive and negative zeros as base */
  1335. /**
  1336. * Inputs: (-0.0, x) where x is an odd integer.
  1337. * Expected:
  1338. * - Negative Infinity with a negative exponent,
  1339. * - -0.0 with a positive exponent.
  1340. */
  1341. static int
  1342. pow_baseNZeroExpOddCases(void *args)
  1343. {
  1344. double result;
  1345. result = SDL_pow(-0.0, -3.0);
  1346. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  1347. "Pow(%f,%f), expected %f, got %f",
  1348. -0.0, -3.0, -INFINITY, result);
  1349. result = SDL_pow(-0.0, 3.0);
  1350. SDLTest_AssertCheck(-0.0 == result,
  1351. "Pow(%f,%f), expected %f, got %f",
  1352. -0.0, 3.0, -0.0, result);
  1353. return TEST_COMPLETED;
  1354. }
  1355. /**
  1356. * Inputs: (0.0, x) where x is an odd integer.
  1357. * Expected:
  1358. * - 0.0 with a positive exponent,
  1359. * - Positive Infinity with a negative exponent.
  1360. */
  1361. static int
  1362. pow_basePZeroExpOddCases(void *args)
  1363. {
  1364. double result;
  1365. result = SDL_pow(0.0, -5.0);
  1366. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1367. "Pow(%f,%f), expected %f, got %f",
  1368. 0.0, -5.0, INFINITY, result);
  1369. result = SDL_pow(0.0, 5.0);
  1370. SDLTest_AssertCheck(0.0 == result,
  1371. "Pow(%f,%f), expected %f, got %f",
  1372. 0.0, 5.0, 0.0, result);
  1373. return TEST_COMPLETED;
  1374. }
  1375. /**
  1376. * Inputs: (-0.0, x), with x either:
  1377. * - finite and even,
  1378. * - finite and non-integer.
  1379. * Expected:
  1380. * - Positive Infinity if the exponent is negative,
  1381. * - 0.0 if the exponent is positive.
  1382. */
  1383. static int
  1384. pow_baseNZeroCases(void *args)
  1385. {
  1386. double result;
  1387. result = SDL_pow(-0.0, -3.5);
  1388. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1389. "Pow(%f,%f), expected %f, got %f",
  1390. -0.0, -3.5, INFINITY, result);
  1391. result = SDL_pow(-0.0, -4.0);
  1392. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1393. "Pow(%f,%f), expected %f, got %f",
  1394. -0.0, -4.0, INFINITY, result);
  1395. result = SDL_pow(-0.0, 3.5);
  1396. SDLTest_AssertCheck(0.0 == result,
  1397. "Pow(%f,%f), expected %f, got %f",
  1398. -0.0, 3.5, 0.0, result);
  1399. result = SDL_pow(-0.0, 4.0);
  1400. SDLTest_AssertCheck(0.0 == result,
  1401. "Pow(%f,%f), expected %f, got %f",
  1402. -0.0, 4.0, 0.0, result);
  1403. return TEST_COMPLETED;
  1404. }
  1405. /**
  1406. * Inputs: (0.0, x), with x either:
  1407. * - finite and even,
  1408. * - finite and non-integer.
  1409. * Expected:
  1410. * - Positive Infinity if the exponent is negative,
  1411. * - 0.0 if the exponent is positive.
  1412. */
  1413. static int
  1414. pow_basePZeroCases(void *args)
  1415. {
  1416. double result;
  1417. result = SDL_pow(0.0, -3.5);
  1418. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1419. "Pow(%f,%f), expected %f, got %f",
  1420. 0.0, -3.5, INFINITY, result);
  1421. result = SDL_pow(0.0, -4.0);
  1422. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1423. "Pow(%f,%f), expected %f, got %f",
  1424. 0.0, -4.0, INFINITY, result);
  1425. result = SDL_pow(0.0, 3.5);
  1426. SDLTest_AssertCheck(0.0 == result,
  1427. "Pow(%f,%f), expected %f, got %f",
  1428. 0.0, 3.5, 0.0, result);
  1429. result = SDL_pow(0.0, 4.0);
  1430. SDLTest_AssertCheck(0.0 == result,
  1431. "Pow(%f,%f), expected %f, got %f",
  1432. 0.0, 4.0, 0.0, result);
  1433. return TEST_COMPLETED;
  1434. }
  1435. /* Remaining tests */
  1436. /**
  1437. * Inputs: values within the domain of the function.
  1438. * Expected: the correct result is returned.
  1439. */
  1440. static int
  1441. pow_regularCases(void *args)
  1442. {
  1443. const dd_to_d regular_cases[] = {
  1444. #if 0 /* These tests fail when using the Mingw C runtime, we'll disable them for now */
  1445. { -391.25, -2.0, 0.00000653267870448815438463212659780943170062528224661946296691894531250 },
  1446. { -72.3, 12.0, 20401381050275984310272.0 },
  1447. #endif
  1448. { -5.0, 3.0, -125.0 },
  1449. { 3.0, 2.5, 15.58845726811989607085706666111946105957031250 },
  1450. { 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 },
  1451. { 478.972, 12.125, 315326359630449587856007411793920.0 }
  1452. };
  1453. return helper_ddtod_inexact("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases));
  1454. }
  1455. /**
  1456. * Inputs: (2.0, x), with x in range [0, 8].
  1457. * Expected: the correct result is returned.
  1458. */
  1459. static int
  1460. pow_powerOfTwo(void *args)
  1461. {
  1462. const dd_to_d power_of_two_cases[] = {
  1463. { 2.0, 1.0, 2.0 },
  1464. { 2.0, 2.0, 4.0 },
  1465. { 2.0, 3.0, 8.0 },
  1466. { 2.0, 4.0, 16.0 },
  1467. { 2.0, 5.0, 32.0 },
  1468. { 2.0, 6.0, 64.0 },
  1469. { 2.0, 7.0, 128.0 },
  1470. { 2.0, 8.0, 256.0 },
  1471. };
  1472. return helper_ddtod("Pow", SDL_pow, power_of_two_cases, SDL_arraysize(power_of_two_cases));
  1473. }
  1474. /**
  1475. * Inputs: values in the range [0, UINT32_MAX] to the power of +/-0.0.
  1476. * Expected: 1.0 is always returned.
  1477. */
  1478. static int
  1479. pow_rangeTest(void *args)
  1480. {
  1481. Uint32 i;
  1482. double test_value = 0.0;
  1483. SDLTest_AssertPass("Pow: Testing a range of %u values with steps of %" SDL_PRIu32,
  1484. RANGE_TEST_ITERATIONS,
  1485. RANGE_TEST_STEP);
  1486. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1487. double result;
  1488. /* These are tested elsewhere */
  1489. if (isnan(test_value) || isinf(test_value)) {
  1490. continue;
  1491. }
  1492. /* Only log failures to save performances */
  1493. result = SDL_pow(test_value, 0.0);
  1494. if (result != 1.0) {
  1495. SDLTest_AssertCheck(SDL_FALSE,
  1496. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1497. test_value, 1.0, 1.0, result);
  1498. return TEST_ABORTED;
  1499. }
  1500. result = SDL_pow(test_value, -0.0);
  1501. if (result != 1.0) {
  1502. SDLTest_AssertCheck(SDL_FALSE,
  1503. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1504. test_value, -0.0, 1.0, result);
  1505. return TEST_ABORTED;
  1506. }
  1507. }
  1508. return TEST_COMPLETED;
  1509. }
  1510. /* SDL_sqrt tests functions */
  1511. /**
  1512. * Input: Positive Infinity.
  1513. * Expected: Positive Infinity is returned.
  1514. */
  1515. static int
  1516. sqrt_infCase(void *args)
  1517. {
  1518. const double result = SDL_sqrt(INFINITY);
  1519. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1520. "Sqrt(%f), expected %f, got %f",
  1521. INFINITY, INFINITY, result);
  1522. return TEST_COMPLETED;
  1523. }
  1524. /**
  1525. * Input: NAN.
  1526. * Expected: NAN is returned.
  1527. */
  1528. static int
  1529. sqrt_nanCase(void *args)
  1530. {
  1531. const double result = SDL_sqrt(NAN);
  1532. SDLTest_AssertCheck(isnan(result),
  1533. "Sqrt(%f), expected %f, got %f",
  1534. NAN, NAN, result);
  1535. return TEST_COMPLETED;
  1536. }
  1537. /**
  1538. * Inputs: values outside the domain of the function.
  1539. * Expected: NAN is returned.
  1540. */
  1541. static int
  1542. sqrt_outOfDomainCases(void *args)
  1543. {
  1544. double result;
  1545. result = SDL_sqrt(-1.0);
  1546. SDLTest_AssertCheck(isnan(result),
  1547. "Sqrt(%f), expected %f, got %f",
  1548. -1.0, NAN, result);
  1549. result = SDL_sqrt(-12345.6789);
  1550. SDLTest_AssertCheck(isnan(result),
  1551. "Sqrt(%f), expected %f, got %f",
  1552. -12345.6789, NAN, result);
  1553. result = SDL_sqrt(-INFINITY);
  1554. SDLTest_AssertCheck(isnan(result),
  1555. "Sqrt(%f), expected %f, got %f",
  1556. -INFINITY, NAN, result);
  1557. return TEST_COMPLETED;
  1558. }
  1559. /**
  1560. * Inputs: +/-0.0 and 1.0.
  1561. * Expected: the input value is returned as-is.
  1562. */
  1563. static int
  1564. sqrt_baseCases(void *args)
  1565. {
  1566. const d_to_d base_cases[] = {
  1567. { -0.0, -0.0 },
  1568. { 0.0, 0.0 },
  1569. { 1.0, 1.0 }
  1570. };
  1571. return helper_dtod("Sqrt", SDL_sqrt, base_cases, SDL_arraysize(base_cases));
  1572. }
  1573. /**
  1574. * Inputs: values within the domain of the function.
  1575. * Expected: the correct result is returned.
  1576. */
  1577. static int
  1578. sqrt_regularCases(void *args)
  1579. {
  1580. const d_to_d regular_cases[] = {
  1581. { 4.0, 2.0 },
  1582. { 9.0, 3.0 },
  1583. { 27.2, 5.21536192416211896727418206864967942237854003906250 },
  1584. { 240.250, 15.5 },
  1585. { 1337.0, 36.565010597564445049556525191292166709899902343750 },
  1586. { 2887.12782400000014604302123188972473144531250, 53.732 },
  1587. { 65600.0156250, 256.125 }
  1588. };
  1589. return helper_dtod_inexact("Sqrt", SDL_sqrt, regular_cases, SDL_arraysize(regular_cases));
  1590. }
  1591. /* SDL_scalbn tests functions */
  1592. /**
  1593. * Input: (+/-Infinity, 1).
  1594. * Expected: Infinity is returned as-is.
  1595. */
  1596. static int
  1597. scalbn_infCases(void *args)
  1598. {
  1599. double result;
  1600. result = SDL_scalbn(INFINITY, 1);
  1601. SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
  1602. "Scalbn(%f,%d), expected %f, got %f",
  1603. INFINITY, 1, INFINITY, result);
  1604. result = SDL_scalbn(-INFINITY, 1);
  1605. SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
  1606. "Scalbn(%f,%d), expected %f, got %f",
  1607. -INFINITY, 1, -INFINITY, result);
  1608. return TEST_COMPLETED;
  1609. }
  1610. /**
  1611. * Inputs: (+/-0.0, 1).
  1612. * Expected: Zero is returned as-is.
  1613. */
  1614. static int
  1615. scalbn_baseZeroCases(void *args)
  1616. {
  1617. double result;
  1618. result = SDL_scalbn(0.0, 1);
  1619. SDLTest_AssertCheck(0.0 == result,
  1620. "Scalbn(%f,%d), expected %f, got %f",
  1621. 0.0, 1, 0.0, result);
  1622. result = SDL_scalbn(-0.0, 1);
  1623. SDLTest_AssertCheck(-0.0 == result,
  1624. "Scalbn(%f,%d), expected %f, got %f",
  1625. -0.0, 1, -0.0, result);
  1626. return TEST_COMPLETED;
  1627. }
  1628. /**
  1629. * Input: (x, 0)
  1630. * Expected: x is returned as-is.
  1631. */
  1632. static int
  1633. scalbn_expZeroCase(void *args)
  1634. {
  1635. const double result = SDL_scalbn(42.0, 0);
  1636. SDLTest_AssertCheck(42.0 == result,
  1637. "Scalbn(%f,%d), expected %f, got %f",
  1638. 42.0, 0, 42.0, result);
  1639. return TEST_COMPLETED;
  1640. }
  1641. /**
  1642. * Input: (NAN, x).
  1643. * Expected: NAN is returned.
  1644. */
  1645. static int
  1646. scalbn_nanCase(void *args)
  1647. {
  1648. const double result = SDL_scalbn(NAN, 2);
  1649. SDLTest_AssertCheck(isnan(result),
  1650. "Scalbn(%f,%d), expected %f, got %f",
  1651. NAN, 2, NAN, result);
  1652. return TEST_COMPLETED;
  1653. }
  1654. /**
  1655. * Inputs: values inside the domain of the function.
  1656. * Expected: the correct result is returned.
  1657. * NOTE: This test depends on SDL_pow and FLT_RADIX.
  1658. */
  1659. static int
  1660. scalbn_regularCases(void *args)
  1661. {
  1662. double result, expected;
  1663. result = SDL_scalbn(2.0, 2);
  1664. expected = 2.0 * SDL_pow(FLT_RADIX, 2);
  1665. SDLTest_AssertCheck(result == expected,
  1666. "Scalbn(%f,%d), expected %f, got %f",
  1667. 2.0, 2, expected, result);
  1668. result = SDL_scalbn(1.0, 13);
  1669. expected = 1.0 * SDL_pow(FLT_RADIX, 13);
  1670. SDLTest_AssertCheck(result == expected,
  1671. "Scalbn(%f,%d), expected %f, got %f",
  1672. 1.0, 13, expected, result);
  1673. result = SDL_scalbn(2.0, -5);
  1674. expected = 2.0 * SDL_pow(FLT_RADIX, -5);
  1675. SDLTest_AssertCheck(result == expected,
  1676. "Scalbn(%f,%d), expected %f, got %f",
  1677. 2.0, -5, expected, result);
  1678. result = SDL_scalbn(-1.0, -13);
  1679. expected = -1.0 * SDL_pow(FLT_RADIX, -13);
  1680. SDLTest_AssertCheck(result == expected,
  1681. "Scalbn(%f,%d), expected %f, got %f",
  1682. -1.0, -13, expected, result);
  1683. return TEST_COMPLETED;
  1684. }
  1685. /* SDL_cos tests functions */
  1686. /**
  1687. * Inputs: +/-Infinity.
  1688. * Expected: NAN is returned.
  1689. */
  1690. static int
  1691. cos_infCases(void *args)
  1692. {
  1693. double result;
  1694. result = SDL_cos(INFINITY);
  1695. SDLTest_AssertCheck(isnan(result),
  1696. "Cos(%f), expected %f, got %f",
  1697. INFINITY, NAN, result);
  1698. result = SDL_cos(-INFINITY);
  1699. SDLTest_AssertCheck(isnan(result),
  1700. "Cos(%f), expected %f, got %f",
  1701. -INFINITY, NAN, result);
  1702. return TEST_COMPLETED;
  1703. }
  1704. /**
  1705. * Input: NAN.
  1706. * Expected: NAN is returned.
  1707. */
  1708. static int
  1709. cos_nanCase(void *args)
  1710. {
  1711. const double result = SDL_cos(NAN);
  1712. SDLTest_AssertCheck(isnan(result),
  1713. "Cos(%f), expected %f, got %f",
  1714. NAN, NAN, result);
  1715. return TEST_COMPLETED;
  1716. }
  1717. /**
  1718. * Inputs: +/-0.0 and +/-Pi.
  1719. * Expected: +1.0 and -1.0 respectively.
  1720. */
  1721. static int
  1722. cos_regularCases(void *args)
  1723. {
  1724. const d_to_d regular_cases[] = {
  1725. { -M_PI, -1.0 },
  1726. { -0.0, 1.0 },
  1727. { 0.0, 1.0 },
  1728. { M_PI, -1.0 }
  1729. };
  1730. return helper_dtod("Cos", SDL_cos, regular_cases, SDL_arraysize(regular_cases));
  1731. }
  1732. /**
  1733. * Inputs: Angles between 1/10 and 9/10 of Pi (positive and negative).
  1734. * Expected: The correct result is returned (+/-EPSILON).
  1735. */
  1736. static int
  1737. cos_precisionTest(void *args)
  1738. {
  1739. const d_to_d precision_cases[] = {
  1740. { M_PI * 1.0 / 10.0, 0.9510565162951535 },
  1741. { M_PI * 2.0 / 10.0, 0.8090169943749475 },
  1742. { M_PI * 3.0 / 10.0, 0.5877852522924731 },
  1743. { M_PI * 4.0 / 10.0, 0.30901699437494745 },
  1744. { M_PI * 5.0 / 10.0, 0.0 },
  1745. { M_PI * 6.0 / 10.0, -0.30901699437494734 },
  1746. { M_PI * 7.0 / 10.0, -0.587785252292473 },
  1747. { M_PI * 8.0 / 10.0, -0.8090169943749473 },
  1748. { M_PI * 9.0 / 10.0, -0.9510565162951535 },
  1749. { M_PI * -1.0 / 10.0, 0.9510565162951535 },
  1750. { M_PI * -2.0 / 10.0, 0.8090169943749475 },
  1751. { M_PI * -3.0 / 10.0, 0.5877852522924731 },
  1752. { M_PI * -4.0 / 10.0, 0.30901699437494745 },
  1753. { M_PI * -5.0 / 10.0, 0.0 },
  1754. { M_PI * -6.0 / 10.0, -0.30901699437494734 },
  1755. { M_PI * -7.0 / 10.0, -0.587785252292473 },
  1756. { M_PI * -8.0 / 10.0, -0.8090169943749473 },
  1757. { M_PI * -9.0 / 10.0, -0.9510565162951535 }
  1758. };
  1759. return helper_dtod_inexact("Cos", SDL_cos, precision_cases, SDL_arraysize(precision_cases));
  1760. }
  1761. /**
  1762. * Inputs: Values in the range [0, UINT32_MAX].
  1763. * Expected: A value between 0 and 1 is returned.
  1764. */
  1765. static int
  1766. cos_rangeTest(void *args)
  1767. {
  1768. Uint32 i;
  1769. double test_value = 0.0;
  1770. SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %" SDL_PRIu32,
  1771. RANGE_TEST_ITERATIONS,
  1772. RANGE_TEST_STEP);
  1773. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1774. double result;
  1775. /* These are tested elsewhere */
  1776. if (isnan(test_value) || isinf(test_value)) {
  1777. continue;
  1778. }
  1779. /* Only log failures to save performances */
  1780. result = SDL_cos(test_value);
  1781. if (result < -1.0 || result > 1.0) {
  1782. SDLTest_AssertCheck(SDL_FALSE,
  1783. "Cos(%.1f), expected [%.1f,%.1f], got %.1f",
  1784. test_value, -1.0, 1.0, result);
  1785. return TEST_ABORTED;
  1786. }
  1787. }
  1788. return TEST_COMPLETED;
  1789. }
  1790. /* SDL_sin tests functions */
  1791. /**
  1792. * Inputs: +/-Infinity.
  1793. * Expected: NAN is returned.
  1794. */
  1795. static int
  1796. sin_infCases(void *args)
  1797. {
  1798. double result;
  1799. result = SDL_sin(INFINITY);
  1800. SDLTest_AssertCheck(isnan(result),
  1801. "Sin(%f), expected %f, got %f",
  1802. INFINITY, NAN, result);
  1803. result = SDL_sin(-INFINITY);
  1804. SDLTest_AssertCheck(isnan(result),
  1805. "Sin(%f), expected %f, got %f",
  1806. -INFINITY, NAN, result);
  1807. return TEST_COMPLETED;
  1808. }
  1809. /**
  1810. * Input: NAN.
  1811. * Expected: NAN is returned.
  1812. */
  1813. static int
  1814. sin_nanCase(void *args)
  1815. {
  1816. const double result = SDL_sin(NAN);
  1817. SDLTest_AssertCheck(isnan(result),
  1818. "Sin(%f), expected %f, got %f",
  1819. NAN, NAN, result);
  1820. return TEST_COMPLETED;
  1821. }
  1822. /**
  1823. * Inputs: +/-0.0 and +/-Pi/2.
  1824. * Expected: +/-0.0 and +/-1.0 respectively.
  1825. */
  1826. static int
  1827. sin_regularCases(void *args)
  1828. {
  1829. const d_to_d regular_cases[] = {
  1830. { -M_PI / 2, -1.0 },
  1831. { -0.0, -0.0 },
  1832. { 0.0, 0.0 },
  1833. { M_PI / 2, 1.0 }
  1834. };
  1835. return helper_dtod("Sin", SDL_sin, regular_cases, SDL_arraysize(regular_cases));
  1836. }
  1837. /**
  1838. * Inputs: Angles between 1/10 and 10/10 of Pi (positive and negative).
  1839. * Expected: The correct result is returned (+/-EPSILON).
  1840. * NOTE: +/-Pi/2 is tested in the regular cases.
  1841. */
  1842. static int
  1843. sin_precisionTest(void *args)
  1844. {
  1845. const d_to_d precision_cases[] = {
  1846. { M_PI * 1.0 / 10.0, 0.3090169943749474 },
  1847. { M_PI * 2.0 / 10.0, 0.5877852522924731 },
  1848. { M_PI * 3.0 / 10.0, 0.8090169943749475 },
  1849. { M_PI * 4.0 / 10.0, 0.9510565162951535 },
  1850. { M_PI * 6.0 / 10.0, 0.9510565162951536 },
  1851. { M_PI * 7.0 / 10.0, 0.8090169943749475 },
  1852. { M_PI * 8.0 / 10.0, 0.5877852522924732 },
  1853. { M_PI * 9.0 / 10.0, 0.3090169943749475 },
  1854. { M_PI, 0.0 },
  1855. { M_PI * -1.0 / 10.0, -0.3090169943749474 },
  1856. { M_PI * -2.0 / 10.0, -0.5877852522924731 },
  1857. { M_PI * -3.0 / 10.0, -0.8090169943749475 },
  1858. { M_PI * -4.0 / 10.0, -0.9510565162951535 },
  1859. { M_PI * -6.0 / 10.0, -0.9510565162951536 },
  1860. { M_PI * -7.0 / 10.0, -0.8090169943749475 },
  1861. { M_PI * -8.0 / 10.0, -0.5877852522924732 },
  1862. { M_PI * -9.0 / 10.0, -0.3090169943749475 },
  1863. { -M_PI, 0.0 },
  1864. };
  1865. return helper_dtod_inexact("Sin", SDL_sin, precision_cases, SDL_arraysize(precision_cases));
  1866. }
  1867. /**
  1868. * Inputs: Values in the range [0, UINT32_MAX].
  1869. * Expected: A value between 0 and 1 is returned.
  1870. */
  1871. static int
  1872. sin_rangeTest(void *args)
  1873. {
  1874. Uint32 i;
  1875. double test_value = 0.0;
  1876. SDLTest_AssertPass("Sin: Testing a range of %u values with steps of %" SDL_PRIu32,
  1877. RANGE_TEST_ITERATIONS,
  1878. RANGE_TEST_STEP);
  1879. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1880. double result;
  1881. /* These are tested elsewhere */
  1882. if (isnan(test_value) || isinf(test_value)) {
  1883. continue;
  1884. }
  1885. /* Only log failures to save performances */
  1886. result = SDL_sin(test_value);
  1887. if (result < -1.0 || result > 1.0) {
  1888. SDLTest_AssertCheck(SDL_FALSE,
  1889. "Sin(%.1f), expected [%.1f,%.1f], got %.1f",
  1890. test_value, -1.0, 1.0, result);
  1891. return TEST_ABORTED;
  1892. }
  1893. }
  1894. return TEST_COMPLETED;
  1895. }
  1896. /* SDL_tan tests functions */
  1897. /**
  1898. * Inputs: +/-Infinity.
  1899. * Expected: NAN is returned.
  1900. */
  1901. static int
  1902. tan_infCases(void *args)
  1903. {
  1904. double result;
  1905. result = SDL_tan(INFINITY);
  1906. SDLTest_AssertCheck(isnan(result),
  1907. "Tan(%f), expected %f, got %f",
  1908. INFINITY, NAN, result);
  1909. result = SDL_tan(-INFINITY);
  1910. SDLTest_AssertCheck(isnan(result),
  1911. "Tan(%f), expected %f, got %f",
  1912. -INFINITY, NAN, result);
  1913. return TEST_COMPLETED;
  1914. }
  1915. /**
  1916. * Input: NAN.
  1917. * Expected: NAN is returned.
  1918. */
  1919. static int
  1920. tan_nanCase(void *args)
  1921. {
  1922. const double result = SDL_tan(NAN);
  1923. SDLTest_AssertCheck(isnan(result),
  1924. "Tan(%f), expected %f, got %f",
  1925. NAN, NAN, result);
  1926. return TEST_COMPLETED;
  1927. }
  1928. /**
  1929. * Inputs: +/-0.0.
  1930. * Expected: Zero is returned as-is.
  1931. */
  1932. static int
  1933. tan_zeroCases(void *args)
  1934. {
  1935. const d_to_d regular_cases[] = {
  1936. { -0.0, -0.0 },
  1937. { 0.0, 0.0 }
  1938. };
  1939. return helper_dtod("Tan", SDL_tan, regular_cases, SDL_arraysize(regular_cases));
  1940. }
  1941. /**
  1942. * Inputs: Angles between 1/11 and 10/11 of Pi (positive and negative).
  1943. * Expected: The correct result is returned (+/-EPSILON).
  1944. * NOTE: +/-Pi/2 is intentionally avoided as it returns garbage values.
  1945. */
  1946. static int
  1947. tan_precisionTest(void *args)
  1948. {
  1949. const d_to_d precision_cases[] = {
  1950. { M_PI * 1.0 / 11.0, 0.29362649293836673 },
  1951. { M_PI * 2.0 / 11.0, 0.642660977168331 },
  1952. { M_PI * 3.0 / 11.0, 1.1540615205330094 },
  1953. { M_PI * 4.0 / 11.0, 2.189694562989681 },
  1954. { M_PI * 5.0 / 11.0, 6.9551527717734745 },
  1955. { M_PI * 6.0 / 11.0, -6.955152771773481 },
  1956. { M_PI * 7.0 / 11.0, -2.189694562989682 },
  1957. { M_PI * 8.0 / 11.0, -1.1540615205330096 },
  1958. { M_PI * 9.0 / 11.0, -0.6426609771683314 },
  1959. { M_PI * 10.0 / 11.0, -0.2936264929383667 },
  1960. { M_PI * -1.0 / 11.0, -0.29362649293836673 },
  1961. { M_PI * -2.0 / 11.0, -0.642660977168331 },
  1962. { M_PI * -3.0 / 11.0, -1.1540615205330094 },
  1963. { M_PI * -4.0 / 11.0, -2.189694562989681 },
  1964. { M_PI * -5.0 / 11.0, -6.9551527717734745 },
  1965. { M_PI * -6.0 / 11.0, 6.955152771773481 },
  1966. { M_PI * -7.0 / 11.0, 2.189694562989682 },
  1967. { M_PI * -8.0 / 11.0, 1.1540615205330096 },
  1968. { M_PI * -9.0 / 11.0, 0.6426609771683314 },
  1969. { M_PI * -10.0 / 11.0, 0.2936264929383667 }
  1970. };
  1971. return helper_dtod_inexact("Tan", SDL_tan, precision_cases, SDL_arraysize(precision_cases));
  1972. }
  1973. /* SDL_acos tests functions */
  1974. /**
  1975. * Inputs: +/-1.0.
  1976. * Expected: 0.0 and Pi respectively.
  1977. */
  1978. static int
  1979. acos_limitCases(void *args)
  1980. {
  1981. double result;
  1982. result = SDL_acos(1.0);
  1983. SDLTest_AssertCheck(0.0 == result,
  1984. "Acos(%f), expected %f, got %f",
  1985. 1.0, 0.0, result);
  1986. result = SDL_acos(-1.0);
  1987. SDLTest_AssertCheck(SDL_fabs(M_PI - result) <= EPSILON,
  1988. "Acos(%f), expected %f, got %f",
  1989. -1.0, M_PI, result);
  1990. return TEST_COMPLETED;
  1991. }
  1992. /**
  1993. * Inputs: Values outside the domain of [-1, 1].
  1994. * Expected: NAN is returned.
  1995. */
  1996. static int
  1997. acos_outOfDomainCases(void *args)
  1998. {
  1999. double result;
  2000. result = SDL_acos(1.1);
  2001. SDLTest_AssertCheck(isnan(result),
  2002. "Acos(%f), expected %f, got %f",
  2003. 1.1, NAN, result);
  2004. result = SDL_acos(-1.1);
  2005. SDLTest_AssertCheck(isnan(result),
  2006. "Acos(%f), expected %f, got %f",
  2007. -1.1, NAN, result);
  2008. return TEST_COMPLETED;
  2009. }
  2010. /**
  2011. * Input: NAN.
  2012. * Expected: NAN is returned.
  2013. */
  2014. static int
  2015. acos_nanCase(void *args)
  2016. {
  2017. const double result = SDL_acos(NAN);
  2018. SDLTest_AssertCheck(isnan(result),
  2019. "Acos(%f), expected %f, got %f",
  2020. NAN, NAN, result);
  2021. return TEST_COMPLETED;
  2022. }
  2023. /**
  2024. * Inputs: Values between -0.9 and 0.9 with steps of 0.1.
  2025. * Expected: The correct result is returned (+/-EPSILON).
  2026. */
  2027. static int
  2028. acos_precisionTest(void *args)
  2029. {
  2030. const d_to_d precision_cases[] = {
  2031. { 0.9, 0.4510268117 },
  2032. { 0.8, 0.6435011087 },
  2033. { 0.7, 0.7953988301 },
  2034. { 0.6, 0.9272952180 },
  2035. { 0.5, 1.0471975511 },
  2036. { 0.4, 1.1592794807 },
  2037. { 0.3, 1.2661036727 },
  2038. { 0.2, 1.3694384060 },
  2039. { 0.1, 1.4706289056 },
  2040. { 0.0, 1.5707963267 },
  2041. { -0.0, 1.5707963267 },
  2042. { -0.1, 1.6709637479 },
  2043. { -0.2, 1.7721542475 },
  2044. { -0.3, 1.8754889808 },
  2045. { -0.4, 1.9823131728 },
  2046. { -0.5, 2.0943951023 },
  2047. { -0.6, 2.2142974355 },
  2048. { -0.7, 2.3461938234 },
  2049. { -0.8, 2.4980915447 },
  2050. { -0.9, 2.6905658417 },
  2051. };
  2052. return helper_dtod_inexact("Acos", SDL_acos, precision_cases, SDL_arraysize(precision_cases));
  2053. }
  2054. /* SDL_asin tests functions */
  2055. /**
  2056. * Inputs: +/-1.0.
  2057. * Expected: +/-Pi/2 is returned.
  2058. */
  2059. static int
  2060. asin_limitCases(void *args)
  2061. {
  2062. double result;
  2063. result = SDL_asin(1.0);
  2064. SDLTest_AssertCheck(SDL_fabs(M_PI / 2.0 - result) <= EPSILON,
  2065. "Asin(%f), expected %f, got %f",
  2066. 1.0, M_PI / 2.0, result);
  2067. result = SDL_asin(-1.0);
  2068. SDLTest_AssertCheck(SDL_fabs(-M_PI / 2.0 - result) <= EPSILON,
  2069. "Asin(%f), expected %f, got %f",
  2070. -1.0, -M_PI / 2.0, result);
  2071. return TEST_COMPLETED;
  2072. }
  2073. /**
  2074. * Inputs: Values outside the domain of [-1, 1].
  2075. * Expected: NAN is returned.
  2076. */
  2077. static int
  2078. asin_outOfDomainCases(void *args)
  2079. {
  2080. double result;
  2081. result = SDL_asin(1.1);
  2082. SDLTest_AssertCheck(isnan(result),
  2083. "Asin(%f), expected %f, got %f",
  2084. 1.1, NAN, result);
  2085. result = SDL_asin(-1.1);
  2086. SDLTest_AssertCheck(isnan(result),
  2087. "Asin(%f), expected %f, got %f",
  2088. -1.1, NAN, result);
  2089. return TEST_COMPLETED;
  2090. }
  2091. /**
  2092. * Input: NAN.
  2093. * Expected: NAN is returned.
  2094. */
  2095. static int
  2096. asin_nanCase(void *args)
  2097. {
  2098. const double result = SDL_asin(NAN);
  2099. SDLTest_AssertCheck(isnan(result),
  2100. "Asin(%f), expected %f, got %f",
  2101. NAN, NAN, result);
  2102. return TEST_COMPLETED;
  2103. }
  2104. /**
  2105. * Inputs: Values between -0.9 and 0.9 with steps of 0.1.
  2106. * Expected: The correct result is returned (+/-EPSILON).
  2107. */
  2108. static int
  2109. asin_precisionTest(void *args)
  2110. {
  2111. const d_to_d precision_cases[] = {
  2112. { 0.9, 1.1197695149986342 },
  2113. { 0.8, 0.9272952180016123 },
  2114. { 0.7, 0.775397496610753 },
  2115. { 0.6, 0.6435011087932844 },
  2116. { 0.5, 0.5235987755982989 },
  2117. { 0.4, 0.41151684606748806 },
  2118. { 0.3, 0.3046926540153976 },
  2119. { 0.2, 0.20135792079033074 },
  2120. { 0.1, 0.10016742116155977 },
  2121. { 0.0, 0.0 },
  2122. { -0.0, -0.0 },
  2123. { -0.1, -0.10016742116155977 },
  2124. { -0.2, -0.20135792079033074 },
  2125. { -0.3, -0.3046926540153976 },
  2126. { -0.4, -0.41151684606748806 },
  2127. { -0.5, -0.5235987755982989 },
  2128. { -0.6, -0.6435011087932844 },
  2129. { -0.7, -0.775397496610753 },
  2130. { -0.8, -0.9272952180016123 },
  2131. { -0.9, -1.1197695149986342 }
  2132. };
  2133. return helper_dtod_inexact("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases));
  2134. }
  2135. /* SDL_atan tests functions */
  2136. /**
  2137. * Inputs: +/-Infinity.
  2138. * Expected: +/-Pi/2 is returned.
  2139. */
  2140. static int
  2141. atan_limitCases(void *args)
  2142. {
  2143. double result;
  2144. result = SDL_atan(INFINITY);
  2145. SDLTest_AssertCheck((M_PI / 2.0) - EPSILON <= result &&
  2146. result <= (M_PI / 2.0) + EPSILON,
  2147. "Atan(%f), expected %f, got %f",
  2148. INFINITY, M_PI / 2.0, result);
  2149. result = SDL_atan(-INFINITY);
  2150. SDLTest_AssertCheck((-M_PI / 2.0) - EPSILON <= result &&
  2151. result <= (-M_PI / 2.0) + EPSILON,
  2152. "Atan(%f), expected %f, got %f",
  2153. -INFINITY, -M_PI / 2.0, result);
  2154. return TEST_COMPLETED;
  2155. }
  2156. /**
  2157. * Inputs: +/-0.0.
  2158. * Expected: Zero is returned as-is.
  2159. */
  2160. static int
  2161. atan_zeroCases(void *args)
  2162. {
  2163. double result;
  2164. result = SDL_atan(0.0);
  2165. SDLTest_AssertCheck(0.0 == result,
  2166. "Atan(%f), expected %f, got %f",
  2167. 0.0, 0.0, result);
  2168. result = SDL_atan(-0.0);
  2169. SDLTest_AssertCheck(-0.0 == result,
  2170. "Atan(%f), expected %f, got %f",
  2171. -0.0, -0.0, result);
  2172. return TEST_COMPLETED;
  2173. }
  2174. /**
  2175. * Input: NAN.
  2176. * Expected: NAN is returned.
  2177. */
  2178. static int
  2179. atan_nanCase(void *args)
  2180. {
  2181. const double result = SDL_atan(NAN);
  2182. SDLTest_AssertCheck(isnan(result),
  2183. "Atan(%f), expected %f, got %f",
  2184. NAN, NAN, result);
  2185. return TEST_COMPLETED;
  2186. }
  2187. /**
  2188. * Inputs: Values corresponding to angles between 9Pi/20 and -9Pi/20 with steps of Pi/20.
  2189. * Expected: The correct result is returned (+/-EPSILON).
  2190. */
  2191. static int
  2192. atan_precisionTest(void *args)
  2193. {
  2194. const d_to_d precision_cases[] = {
  2195. { 6.313751514675041, 1.413716694115407 },
  2196. { 3.0776835371752527, 1.2566370614359172 },
  2197. { 1.9626105055051504, 1.0995574287564276 },
  2198. { 1.3763819204711734, 0.9424777960769379 },
  2199. { 1.0, 0.7853981633974483 },
  2200. { 0.7265425280053609, 0.6283185307179586 },
  2201. { 0.5095254494944288, 0.47123889803846897 },
  2202. { 0.3249196962329063, 0.3141592653589793 },
  2203. { 0.15838444032453627, 0.15707963267948966 },
  2204. { -0.15838444032453627, -0.15707963267948966 },
  2205. { -0.3249196962329063, -0.3141592653589793 },
  2206. { -0.5095254494944288, -0.47123889803846897 },
  2207. { -0.7265425280053609, -0.6283185307179586 },
  2208. { -1.0, -0.7853981633974483 },
  2209. { -1.3763819204711734, -0.9424777960769379 },
  2210. { -1.9626105055051504, -1.0995574287564276 },
  2211. { -3.0776835371752527, -1.2566370614359172 },
  2212. { -6.313751514675041, -1.413716694115407 },
  2213. };
  2214. return helper_dtod_inexact("Atan", SDL_atan, precision_cases, SDL_arraysize(precision_cases));
  2215. }
  2216. /* SDL_atan2 tests functions */
  2217. /* Zero cases */
  2218. /**
  2219. * Inputs: (+/-0.0, +/-0.0).
  2220. * Expected:
  2221. * - Zero if the second argument is positive zero.
  2222. * - Pi if the second argument is negative zero.
  2223. * - The sign is inherited from the first argument.
  2224. */
  2225. static int
  2226. atan2_bothZeroCases(void *args)
  2227. {
  2228. const dd_to_d cases[] = {
  2229. { 0.0, 0.0, 0.0 },
  2230. { -0.0, 0.0, -0.0 },
  2231. { 0.0, -0.0, M_PI },
  2232. { -0.0, -0.0, -M_PI },
  2233. };
  2234. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
  2235. }
  2236. /**
  2237. * Inputs: (+/-0.0, +/-1.0).
  2238. * Expected:
  2239. * - Zero if the second argument is positive.
  2240. * - Pi if the second argument is negative.
  2241. * - The sign is inherited from the first argument.
  2242. */
  2243. static int
  2244. atan2_yZeroCases(void *args)
  2245. {
  2246. const dd_to_d cases[] = {
  2247. { 0.0, 1.0, 0.0 },
  2248. { 0.0, -1.0, M_PI },
  2249. { -0.0, 1.0, -0.0 },
  2250. { -0.0, -1.0, -M_PI }
  2251. };
  2252. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
  2253. }
  2254. /**
  2255. * Inputs: (+/-1.0, +/-0.0).
  2256. * Expected: Pi/2 with the sign of the first argument.
  2257. */
  2258. static int
  2259. atan2_xZeroCases(void *args)
  2260. {
  2261. const dd_to_d cases[] = {
  2262. { 1.0, 0.0, M_PI / 2.0 },
  2263. { -1.0, 0.0, -M_PI / 2.0 },
  2264. { 1.0, -0.0, M_PI / 2.0 },
  2265. { -1.0, -0.0, -M_PI / 2.0 }
  2266. };
  2267. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
  2268. }
  2269. /* Infinity cases */
  2270. /**
  2271. * Inputs: (+/-Infinity, +/-Infinity).
  2272. * Expected:
  2273. * - (+int, +inf) -> Pi/4,
  2274. * - (+int, -inf) -> 3Pi/4,
  2275. * - (-int, +inf) -> -Pi/4,
  2276. * - (-int, -inf) -> Pi.
  2277. */
  2278. static int
  2279. atan2_bothInfCases(void *args)
  2280. {
  2281. dd_to_d cases[4];
  2282. DD_TO_D_CASE(0, INFINITY, INFINITY, 1.0 * M_PI / 4.0);
  2283. DD_TO_D_CASE(1, INFINITY, -INFINITY, 3.0 * M_PI / 4.0);
  2284. DD_TO_D_CASE(2, -INFINITY, INFINITY, -1.0 * M_PI / 4.0);
  2285. DD_TO_D_CASE(3, -INFINITY, -INFINITY, -3.0 * M_PI / 4.0);
  2286. return helper_ddtod("SDL_atan2(bothInfCases)", SDL_atan2, cases, SDL_arraysize(cases));
  2287. }
  2288. /**
  2289. * Inputs: (+/-Infinity, +/-1.0).
  2290. * Expected: Pi/2 with the sign of the first argument.
  2291. */
  2292. static int
  2293. atan2_yInfCases(void *args)
  2294. {
  2295. dd_to_d cases[4];
  2296. DD_TO_D_CASE(0, INFINITY, 1.0, 1.0 * M_PI / 2.0);
  2297. DD_TO_D_CASE(1, INFINITY, -1.0, 1.0 * M_PI / 2.0);
  2298. DD_TO_D_CASE(2, -INFINITY, 1.0, -1.0 * M_PI / 2.0);
  2299. DD_TO_D_CASE(3, -INFINITY, -1.0, -1.0 * M_PI / 2.0);
  2300. return helper_ddtod("SDL_atan2(atan2_yInfCases)", SDL_atan2, cases, SDL_arraysize(cases));
  2301. }
  2302. /**
  2303. * Inputs: (+/-1.0, +/-Infinity).
  2304. * Expected:
  2305. * - (+/-1.0, +inf) -> +/-0.0
  2306. * - (+/-1.0, -inf) -> +/-Pi.
  2307. */
  2308. static int
  2309. atan2_xInfCases(void *args)
  2310. {
  2311. dd_to_d cases[4];
  2312. DD_TO_D_CASE(0, 1.0, INFINITY, 0.0);
  2313. DD_TO_D_CASE(1, -1.0, INFINITY, -0.0);
  2314. DD_TO_D_CASE(2, 1.0, -INFINITY, M_PI);
  2315. DD_TO_D_CASE(3, -1.0, -INFINITY, -M_PI);
  2316. return helper_ddtod("atan2_xInfCases(atan2_yInfCases)", SDL_atan2, cases, SDL_arraysize(cases));
  2317. }
  2318. /* Miscelanious cases */
  2319. /**
  2320. * Inputs: NAN as either or both of the arguments.
  2321. * Expected: NAN is returned.
  2322. */
  2323. static int
  2324. atan2_nanCases(void *args)
  2325. {
  2326. double result;
  2327. result = SDL_atan2(NAN, NAN);
  2328. SDLTest_AssertCheck(isnan(result),
  2329. "Atan2(%f,%f), expected %f, got %f",
  2330. NAN, NAN, NAN, result);
  2331. result = SDL_atan2(NAN, 1.0);
  2332. SDLTest_AssertCheck(isnan(result),
  2333. "Atan2(%f,%f), expected %f, got %f",
  2334. NAN, 1.0, NAN, result);
  2335. result = SDL_atan2(1.0, NAN);
  2336. SDLTest_AssertCheck(isnan(result),
  2337. "Atan2(%f,%f), expected %f, got %f",
  2338. 1.0, NAN, NAN, result);
  2339. return TEST_COMPLETED;
  2340. }
  2341. /**
  2342. * Inputs: (y, x) with x and y positive.
  2343. * Expected: Angle in the top right quadrant.
  2344. */
  2345. static int
  2346. atan2_topRightQuadrantTest(void *args)
  2347. {
  2348. const dd_to_d top_right_cases[] = {
  2349. { 1.0, 1.0, M_PI / 4.0 },
  2350. { SQRT3, 3.0, M_PI / 6.0 },
  2351. { SQRT3, 1.0, M_PI / 3.0 }
  2352. };
  2353. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_right_cases, SDL_arraysize(top_right_cases));
  2354. }
  2355. /**
  2356. * Inputs: (y, x) with x negative and y positive.
  2357. * Expected: Angle in the top left quadrant.
  2358. */
  2359. static int
  2360. atan2_topLeftQuadrantTest(void *args)
  2361. {
  2362. const dd_to_d top_left_cases[] = {
  2363. { 1.0, -1.0, 3.0 * M_PI / 4.0 },
  2364. { SQRT3, -3.0, 5.0 * M_PI / 6.0 },
  2365. { SQRT3, -1.0, 2.0 * M_PI / 3.0 }
  2366. };
  2367. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_left_cases, SDL_arraysize(top_left_cases));
  2368. }
  2369. /**
  2370. * Inputs: (y, x) with x positive and y negative.
  2371. * Expected: Angle in the bottom right quadrant.
  2372. */
  2373. static int
  2374. atan2_bottomRightQuadrantTest(void *args)
  2375. {
  2376. const dd_to_d bottom_right_cases[] = {
  2377. { -1.0, 1.0, -M_PI / 4 },
  2378. { -SQRT3, 3.0, -M_PI / 6.0 },
  2379. { -SQRT3, 1.0, -M_PI / 3.0 }
  2380. };
  2381. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_right_cases, SDL_arraysize(bottom_right_cases));
  2382. }
  2383. /**
  2384. * Inputs: (y, x) with x and y negative.
  2385. * Expected: Angle in the bottom left quadrant.
  2386. */
  2387. static int
  2388. atan2_bottomLeftQuadrantTest(void *args)
  2389. {
  2390. const dd_to_d bottom_left_cases[] = {
  2391. { -1.0, -1.0, -3.0 * M_PI / 4.0 },
  2392. { -SQRT3, -3.0, -5.0 * M_PI / 6.0 },
  2393. { -SQRT3, -1.0, -4.0 * M_PI / 6.0 }
  2394. };
  2395. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_left_cases, SDL_arraysize(bottom_left_cases));
  2396. }
  2397. /* ================= Test References ================== */
  2398. /* SDL_floor test cases */
  2399. static const SDLTest_TestCaseReference floorTestInf = {
  2400. (SDLTest_TestCaseFp)floor_infCases, "floor_infCases",
  2401. "Checks positive and negative infinity", TEST_ENABLED
  2402. };
  2403. static const SDLTest_TestCaseReference floorTestZero = {
  2404. (SDLTest_TestCaseFp)floor_zeroCases, "floor_zeroCases",
  2405. "Checks positive and negative zero", TEST_ENABLED
  2406. };
  2407. static const SDLTest_TestCaseReference floorTestNan = {
  2408. (SDLTest_TestCaseFp)floor_nanCase, "floor_nanCase",
  2409. "Checks NAN", TEST_ENABLED
  2410. };
  2411. static const SDLTest_TestCaseReference floorTestRound = {
  2412. (SDLTest_TestCaseFp)floor_roundNumbersCases, "floor_roundNumberCases",
  2413. "Checks a set of integral values", TEST_ENABLED
  2414. };
  2415. static const SDLTest_TestCaseReference floorTestFraction = {
  2416. (SDLTest_TestCaseFp)floor_fractionCases, "floor_fractionCases",
  2417. "Checks a set of fractions", TEST_ENABLED
  2418. };
  2419. static const SDLTest_TestCaseReference floorTestRange = {
  2420. (SDLTest_TestCaseFp)floor_rangeTest, "floor_rangeTest",
  2421. "Checks a range of positive integer", TEST_ENABLED
  2422. };
  2423. /* SDL_ceil test cases */
  2424. static const SDLTest_TestCaseReference ceilTestInf = {
  2425. (SDLTest_TestCaseFp)ceil_infCases, "ceil_infCases",
  2426. "Checks positive and negative infinity", TEST_ENABLED
  2427. };
  2428. static const SDLTest_TestCaseReference ceilTestZero = {
  2429. (SDLTest_TestCaseFp)ceil_zeroCases, "ceil_zeroCases",
  2430. "Checks positive and negative zero", TEST_ENABLED
  2431. };
  2432. static const SDLTest_TestCaseReference ceilTestNan = {
  2433. (SDLTest_TestCaseFp)ceil_nanCase, "ceil_nanCase",
  2434. "Checks NAN", TEST_ENABLED
  2435. };
  2436. static const SDLTest_TestCaseReference ceilTestRound = {
  2437. (SDLTest_TestCaseFp)ceil_roundNumbersCases, "ceil_roundNumberCases",
  2438. "Checks a set of integral values", TEST_ENABLED
  2439. };
  2440. static const SDLTest_TestCaseReference ceilTestFraction = {
  2441. (SDLTest_TestCaseFp)ceil_fractionCases, "ceil_fractionCases",
  2442. "Checks a set of fractions", TEST_ENABLED
  2443. };
  2444. static const SDLTest_TestCaseReference ceilTestRange = {
  2445. (SDLTest_TestCaseFp)ceil_rangeTest, "ceil_rangeTest",
  2446. "Checks a range of positive integer", TEST_ENABLED
  2447. };
  2448. /* SDL_trunc test cases */
  2449. static const SDLTest_TestCaseReference truncTestInf = {
  2450. (SDLTest_TestCaseFp)trunc_infCases, "trunc_infCases",
  2451. "Checks positive and negative infinity", TEST_ENABLED
  2452. };
  2453. static const SDLTest_TestCaseReference truncTestZero = {
  2454. (SDLTest_TestCaseFp)trunc_zeroCases, "trunc_zeroCases",
  2455. "Checks positive and negative zero", TEST_ENABLED
  2456. };
  2457. static const SDLTest_TestCaseReference truncTestNan = {
  2458. (SDLTest_TestCaseFp)trunc_nanCase, "trunc_nanCase",
  2459. "Checks NAN", TEST_ENABLED
  2460. };
  2461. static const SDLTest_TestCaseReference truncTestRound = {
  2462. (SDLTest_TestCaseFp)trunc_roundNumbersCases, "trunc_roundNumberCases",
  2463. "Checks a set of integral values", TEST_ENABLED
  2464. };
  2465. static const SDLTest_TestCaseReference truncTestFraction = {
  2466. (SDLTest_TestCaseFp)trunc_fractionCases, "trunc_fractionCases",
  2467. "Checks a set of fractions", TEST_ENABLED
  2468. };
  2469. static const SDLTest_TestCaseReference truncTestRange = {
  2470. (SDLTest_TestCaseFp)trunc_rangeTest, "trunc_rangeTest",
  2471. "Checks a range of positive integer", TEST_ENABLED
  2472. };
  2473. /* SDL_round test cases */
  2474. static const SDLTest_TestCaseReference roundTestInf = {
  2475. (SDLTest_TestCaseFp)round_infCases, "round_infCases",
  2476. "Checks positive and negative infinity", TEST_ENABLED
  2477. };
  2478. static const SDLTest_TestCaseReference roundTestZero = {
  2479. (SDLTest_TestCaseFp)round_zeroCases, "round_zeroCases",
  2480. "Checks positive and negative zero", TEST_ENABLED
  2481. };
  2482. static const SDLTest_TestCaseReference roundTestNan = {
  2483. (SDLTest_TestCaseFp)round_nanCase, "round_nanCase",
  2484. "Checks NAN", TEST_ENABLED
  2485. };
  2486. static const SDLTest_TestCaseReference roundTestRound = {
  2487. (SDLTest_TestCaseFp)round_roundNumbersCases, "round_roundNumberCases",
  2488. "Checks a set of integral values", TEST_ENABLED
  2489. };
  2490. static const SDLTest_TestCaseReference roundTestFraction = {
  2491. (SDLTest_TestCaseFp)round_fractionCases, "round_fractionCases",
  2492. "Checks a set of fractions", TEST_ENABLED
  2493. };
  2494. static const SDLTest_TestCaseReference roundTestRange = {
  2495. (SDLTest_TestCaseFp)round_rangeTest, "round_rangeTest",
  2496. "Checks a range of positive integer", TEST_ENABLED
  2497. };
  2498. /* SDL_fabs test cases */
  2499. static const SDLTest_TestCaseReference fabsTestInf = {
  2500. (SDLTest_TestCaseFp)fabs_infCases, "fabs_infCases",
  2501. "Checks positive and negative infinity", TEST_ENABLED
  2502. };
  2503. static const SDLTest_TestCaseReference fabsTestZero = {
  2504. (SDLTest_TestCaseFp)fabs_zeroCases, "fabs_zeroCases",
  2505. "Checks positive and negative zero", TEST_ENABLED
  2506. };
  2507. static const SDLTest_TestCaseReference fabsTestNan = {
  2508. (SDLTest_TestCaseFp)fabs_nanCase, "fabs_nanCase",
  2509. "Checks NAN", TEST_ENABLED
  2510. };
  2511. static const SDLTest_TestCaseReference fabsTestRange = {
  2512. (SDLTest_TestCaseFp)fabs_rangeTest, "fabs_rangeTest",
  2513. "Checks a range of positive integer", TEST_ENABLED
  2514. };
  2515. /* SDL_copysign test cases */
  2516. static const SDLTest_TestCaseReference copysignTestInf = {
  2517. (SDLTest_TestCaseFp)copysign_infCases, "copysign_infCases",
  2518. "Checks positive and negative infinity", TEST_ENABLED
  2519. };
  2520. static const SDLTest_TestCaseReference copysignTestZero = {
  2521. (SDLTest_TestCaseFp)copysign_zeroCases, "copysign_zeroCases",
  2522. "Checks positive and negative zero", TEST_ENABLED
  2523. };
  2524. static const SDLTest_TestCaseReference copysignTestNan = {
  2525. (SDLTest_TestCaseFp)copysign_nanCases, "copysign_nanCases",
  2526. "Checks NANs", TEST_ENABLED
  2527. };
  2528. static const SDLTest_TestCaseReference copysignTestRange = {
  2529. (SDLTest_TestCaseFp)copysign_rangeTest, "copysign_rangeTest",
  2530. "Checks a range of positive integer", TEST_ENABLED
  2531. };
  2532. /* SDL_fmod test cases */
  2533. static const SDLTest_TestCaseReference fmodTestDivOfInf = {
  2534. (SDLTest_TestCaseFp)fmod_divOfInfCases, "fmod_divOfInfCases",
  2535. "Checks division of positive and negative infinity", TEST_ENABLED
  2536. };
  2537. static const SDLTest_TestCaseReference fmodTestDivByInf = {
  2538. (SDLTest_TestCaseFp)fmod_divByInfCases, "fmod_divByInfCases",
  2539. "Checks division by positive and negative infinity", TEST_ENABLED
  2540. };
  2541. static const SDLTest_TestCaseReference fmodTestDivOfZero = {
  2542. (SDLTest_TestCaseFp)fmod_divOfZeroCases, "fmod_divOfZeroCases",
  2543. "Checks division of positive and negative zero", TEST_ENABLED
  2544. };
  2545. static const SDLTest_TestCaseReference fmodTestDivByZero = {
  2546. (SDLTest_TestCaseFp)fmod_divByZeroCases, "fmod_divByZeroCases",
  2547. "Checks division by positive and negative zero", TEST_ENABLED
  2548. };
  2549. static const SDLTest_TestCaseReference fmodTestNan = {
  2550. (SDLTest_TestCaseFp)fmod_nanCases, "fmod_nanCases",
  2551. "Checks NANs", TEST_ENABLED
  2552. };
  2553. static const SDLTest_TestCaseReference fmodTestRegular = {
  2554. (SDLTest_TestCaseFp)fmod_regularCases, "fmod_regularCases",
  2555. "Checks a set of regular values", TEST_ENABLED
  2556. };
  2557. static const SDLTest_TestCaseReference fmodTestRange = {
  2558. (SDLTest_TestCaseFp)fmod_rangeTest, "fmod_rangeTest",
  2559. "Checks a range of positive integer", TEST_ENABLED
  2560. };
  2561. /* SDL_exp test cases */
  2562. static const SDLTest_TestCaseReference expTestInf = {
  2563. (SDLTest_TestCaseFp)exp_infCases, "exp_infCases",
  2564. "Checks positive and negative infinity", TEST_ENABLED
  2565. };
  2566. static const SDLTest_TestCaseReference expTestZero = {
  2567. (SDLTest_TestCaseFp)exp_zeroCases, "exp_zeroCases",
  2568. "Checks for positive and negative zero", TEST_ENABLED
  2569. };
  2570. static const SDLTest_TestCaseReference expTestOverflow = {
  2571. (SDLTest_TestCaseFp)exp_overflowCase, "exp_overflowCase",
  2572. "Checks for overflow", TEST_ENABLED
  2573. };
  2574. static const SDLTest_TestCaseReference expTestBase = {
  2575. (SDLTest_TestCaseFp)exp_baseCase, "exp_baseCase",
  2576. "Checks the base case", TEST_ENABLED
  2577. };
  2578. static const SDLTest_TestCaseReference expTestRegular = {
  2579. (SDLTest_TestCaseFp)exp_regularCases, "exp_regularCases",
  2580. "Checks a set of regular values", TEST_ENABLED
  2581. };
  2582. /* SDL_log test cases */
  2583. static const SDLTest_TestCaseReference logTestLimit = {
  2584. (SDLTest_TestCaseFp)log_limitCases, "log_limitCases",
  2585. "Checks the domain limits", TEST_ENABLED
  2586. };
  2587. static const SDLTest_TestCaseReference logTestNan = {
  2588. (SDLTest_TestCaseFp)log_nanCases, "log_nanCases",
  2589. "Checks NAN and negative values", TEST_ENABLED
  2590. };
  2591. static const SDLTest_TestCaseReference logTestBase = {
  2592. (SDLTest_TestCaseFp)log_baseCases, "log_baseCases",
  2593. "Checks the base cases", TEST_ENABLED
  2594. };
  2595. static const SDLTest_TestCaseReference logTestRegular = {
  2596. (SDLTest_TestCaseFp)log_regularCases, "log_regularCases",
  2597. "Checks a set of regular values", TEST_ENABLED
  2598. };
  2599. /* SDL_log10 test cases */
  2600. static const SDLTest_TestCaseReference log10TestLimit = {
  2601. (SDLTest_TestCaseFp)log10_limitCases, "log10_limitCases",
  2602. "Checks the domain limits", TEST_ENABLED
  2603. };
  2604. static const SDLTest_TestCaseReference log10TestNan = {
  2605. (SDLTest_TestCaseFp)log10_nanCases, "log10_nanCases",
  2606. "Checks NAN and negative values", TEST_ENABLED
  2607. };
  2608. static const SDLTest_TestCaseReference log10TestBase = {
  2609. (SDLTest_TestCaseFp)log10_baseCases, "log10_baseCases",
  2610. "Checks the base cases", TEST_ENABLED
  2611. };
  2612. static const SDLTest_TestCaseReference log10TestRegular = {
  2613. (SDLTest_TestCaseFp)log10_regularCases, "log10_regularCases",
  2614. "Checks a set of regular values", TEST_ENABLED
  2615. };
  2616. /* SDL_pow test cases */
  2617. static const SDLTest_TestCaseReference powTestExpInf1 = {
  2618. (SDLTest_TestCaseFp)pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
  2619. "Checks for pow(-1, +/-inf)", TEST_ENABLED
  2620. };
  2621. static const SDLTest_TestCaseReference powTestExpInf2 = {
  2622. (SDLTest_TestCaseFp)pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
  2623. "Checks for pow(+/-0, -inf)", TEST_ENABLED
  2624. };
  2625. static const SDLTest_TestCaseReference powTestExpInf3 = {
  2626. (SDLTest_TestCaseFp)pow_expInfCases, "pow_expInfCases",
  2627. "Checks for pow(x, +/-inf)", TEST_ENABLED
  2628. };
  2629. static const SDLTest_TestCaseReference powTestBaseInf1 = {
  2630. (SDLTest_TestCaseFp)pow_basePInfCases, "pow_basePInfCases",
  2631. "Checks for pow(inf, x)", TEST_ENABLED
  2632. };
  2633. static const SDLTest_TestCaseReference powTestBaseInf2 = {
  2634. (SDLTest_TestCaseFp)pow_baseNInfCases, "pow_baseNInfCases",
  2635. "Checks for pow(-inf, x)", TEST_ENABLED
  2636. };
  2637. static const SDLTest_TestCaseReference powTestNan1 = {
  2638. (SDLTest_TestCaseFp)pow_badOperationCase, "pow_badOperationCase",
  2639. "Checks for negative finite base and non-integer finite exponent", TEST_ENABLED
  2640. };
  2641. static const SDLTest_TestCaseReference powTestNan2 = {
  2642. (SDLTest_TestCaseFp)pow_base1ExpNanCase, "pow_base1ExpNanCase",
  2643. "Checks for pow(1.0, NAN)", TEST_ENABLED
  2644. };
  2645. static const SDLTest_TestCaseReference powTestNan3 = {
  2646. (SDLTest_TestCaseFp)pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
  2647. "Checks for pow(NAN, +/-0)", TEST_ENABLED
  2648. };
  2649. static const SDLTest_TestCaseReference powTestNan4 = {
  2650. (SDLTest_TestCaseFp)pow_nanArgsCases, "pow_nanArgsCases",
  2651. "Checks for pow(x, y) with either x or y being NAN", TEST_ENABLED
  2652. };
  2653. static const SDLTest_TestCaseReference powTestZero1 = {
  2654. (SDLTest_TestCaseFp)pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
  2655. "Checks for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
  2656. };
  2657. static const SDLTest_TestCaseReference powTestZero2 = {
  2658. (SDLTest_TestCaseFp)pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
  2659. "Checks for pow(0.0, y), with y an odd integer.", TEST_ENABLED
  2660. };
  2661. static const SDLTest_TestCaseReference powTestZero3 = {
  2662. (SDLTest_TestCaseFp)pow_baseNZeroCases, "pow_baseNZeroCases",
  2663. "Checks for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2664. };
  2665. static const SDLTest_TestCaseReference powTestZero4 = {
  2666. (SDLTest_TestCaseFp)pow_basePZeroCases, "pow_basePZeroCases",
  2667. "Checks for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2668. };
  2669. static const SDLTest_TestCaseReference powTestRegular = {
  2670. (SDLTest_TestCaseFp)pow_regularCases, "pow_regularCases",
  2671. "Checks a set of regular values", TEST_ENABLED
  2672. };
  2673. static const SDLTest_TestCaseReference powTestPowOf2 = {
  2674. (SDLTest_TestCaseFp)pow_powerOfTwo, "pow_powerOfTwo",
  2675. "Checks the powers of two from 1 to 8", TEST_ENABLED
  2676. };
  2677. static const SDLTest_TestCaseReference powTestRange = {
  2678. (SDLTest_TestCaseFp)pow_rangeTest, "pow_rangeTest",
  2679. "Checks a range of positive integer to the power of 0", TEST_ENABLED
  2680. };
  2681. /* SDL_sqrt test cases */
  2682. static const SDLTest_TestCaseReference sqrtTestInf = {
  2683. (SDLTest_TestCaseFp)sqrt_infCase, "sqrt_infCase",
  2684. "Checks positive infinity", TEST_ENABLED
  2685. };
  2686. static const SDLTest_TestCaseReference sqrtTestNan = {
  2687. (SDLTest_TestCaseFp)sqrt_nanCase, "sqrt_nanCase",
  2688. "Checks NAN", TEST_ENABLED
  2689. };
  2690. static const SDLTest_TestCaseReference sqrtTestDomain = {
  2691. (SDLTest_TestCaseFp)sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
  2692. "Checks for values out of the domain", TEST_ENABLED
  2693. };
  2694. static const SDLTest_TestCaseReference sqrtTestBase = {
  2695. (SDLTest_TestCaseFp)sqrt_baseCases, "sqrt_baseCases",
  2696. "Checks the base cases", TEST_ENABLED
  2697. };
  2698. static const SDLTest_TestCaseReference sqrtTestRegular = {
  2699. (SDLTest_TestCaseFp)sqrt_regularCases, "sqrt_regularCases",
  2700. "Checks a set of regular values", TEST_ENABLED
  2701. };
  2702. /* SDL_scalbn test cases */
  2703. static const SDLTest_TestCaseReference scalbnTestInf = {
  2704. (SDLTest_TestCaseFp)scalbn_infCases, "scalbn_infCases",
  2705. "Checks positive and negative infinity arg", TEST_ENABLED
  2706. };
  2707. static const SDLTest_TestCaseReference scalbnTestBaseZero = {
  2708. (SDLTest_TestCaseFp)scalbn_baseZeroCases, "scalbn_baseZeroCases",
  2709. "Checks for positive and negative zero arg", TEST_ENABLED
  2710. };
  2711. static const SDLTest_TestCaseReference scalbnTestExpZero = {
  2712. (SDLTest_TestCaseFp)scalbn_expZeroCase, "scalbn_expZeroCase",
  2713. "Checks for zero exp", TEST_ENABLED
  2714. };
  2715. static const SDLTest_TestCaseReference scalbnTestNan = {
  2716. (SDLTest_TestCaseFp)scalbn_nanCase, "scalbn_nanCase",
  2717. "Checks NAN", TEST_ENABLED
  2718. };
  2719. static const SDLTest_TestCaseReference scalbnTestRegular = {
  2720. (SDLTest_TestCaseFp)scalbn_regularCases, "scalbn_regularCases",
  2721. "Checks a set of regular cases", TEST_ENABLED
  2722. };
  2723. /* SDL_cos test cases */
  2724. static const SDLTest_TestCaseReference cosTestInf = {
  2725. (SDLTest_TestCaseFp)cos_infCases, "cos_infCases",
  2726. "Checks for positive and negative infinity", TEST_ENABLED
  2727. };
  2728. static const SDLTest_TestCaseReference cosTestNan = {
  2729. (SDLTest_TestCaseFp)cos_nanCase, "cos_nanCase",
  2730. "Checks NAN", TEST_ENABLED
  2731. };
  2732. static const SDLTest_TestCaseReference cosTestRegular = {
  2733. (SDLTest_TestCaseFp)cos_regularCases, "cos_regularCases",
  2734. "Checks a set of regular cases", TEST_ENABLED
  2735. };
  2736. static const SDLTest_TestCaseReference cosTestPrecision = {
  2737. (SDLTest_TestCaseFp)cos_precisionTest, "cos_precisionTest",
  2738. "Checks cosine precision", TEST_ENABLED
  2739. };
  2740. static const SDLTest_TestCaseReference cosTestRange = {
  2741. (SDLTest_TestCaseFp)cos_rangeTest, "cos_rangeTest",
  2742. "Checks a range of positive integer", TEST_ENABLED
  2743. };
  2744. /* SDL_sin test cases */
  2745. static const SDLTest_TestCaseReference sinTestInf = {
  2746. (SDLTest_TestCaseFp)sin_infCases, "sin_infCases",
  2747. "Checks for positive and negative infinity", TEST_ENABLED
  2748. };
  2749. static const SDLTest_TestCaseReference sinTestNan = {
  2750. (SDLTest_TestCaseFp)sin_nanCase, "sin_nanCase",
  2751. "Checks NAN", TEST_ENABLED
  2752. };
  2753. static const SDLTest_TestCaseReference sinTestRegular = {
  2754. (SDLTest_TestCaseFp)sin_regularCases, "sin_regularCases",
  2755. "Checks a set of regular cases", TEST_ENABLED
  2756. };
  2757. static const SDLTest_TestCaseReference sinTestPrecision = {
  2758. (SDLTest_TestCaseFp)sin_precisionTest, "sin_precisionTest",
  2759. "Checks sine precision", TEST_ENABLED
  2760. };
  2761. static const SDLTest_TestCaseReference sinTestRange = {
  2762. (SDLTest_TestCaseFp)sin_rangeTest, "sin_rangeTest",
  2763. "Checks a range of positive integer", TEST_ENABLED
  2764. };
  2765. /* SDL_tan test cases */
  2766. static const SDLTest_TestCaseReference tanTestInf = {
  2767. (SDLTest_TestCaseFp)tan_infCases, "tan_infCases",
  2768. "Checks for positive and negative infinity", TEST_ENABLED
  2769. };
  2770. static const SDLTest_TestCaseReference tanTestNan = {
  2771. (SDLTest_TestCaseFp)tan_nanCase, "tan_nanCase",
  2772. "Checks NAN", TEST_ENABLED
  2773. };
  2774. static const SDLTest_TestCaseReference tanTestZero = {
  2775. (SDLTest_TestCaseFp)tan_zeroCases, "tan_zeroCases",
  2776. "Checks a set of regular cases", TEST_ENABLED
  2777. };
  2778. static const SDLTest_TestCaseReference tanTestPrecision = {
  2779. (SDLTest_TestCaseFp)tan_precisionTest, "tan_precisionTest",
  2780. "Checks tangent precision", TEST_ENABLED
  2781. };
  2782. /* SDL_acos test cases */
  2783. static const SDLTest_TestCaseReference acosTestLimit = {
  2784. (SDLTest_TestCaseFp)acos_limitCases, "acos_limitCases",
  2785. "Checks the edge of the domain (+/-1)", TEST_ENABLED
  2786. };
  2787. static const SDLTest_TestCaseReference acosTestOutOfDomain = {
  2788. (SDLTest_TestCaseFp)acos_outOfDomainCases, "acos_outOfDomainCases",
  2789. "Checks values outside the domain", TEST_ENABLED
  2790. };
  2791. static const SDLTest_TestCaseReference acosTestNan = {
  2792. (SDLTest_TestCaseFp)acos_nanCase, "acos_nanCase",
  2793. "Checks NAN", TEST_ENABLED
  2794. };
  2795. static const SDLTest_TestCaseReference acosTestPrecision = {
  2796. (SDLTest_TestCaseFp)acos_precisionTest, "acos_precisionTest",
  2797. "Checks acos precision", TEST_ENABLED
  2798. };
  2799. /* SDL_asin test cases */
  2800. static const SDLTest_TestCaseReference asinTestLimit = {
  2801. (SDLTest_TestCaseFp)asin_limitCases, "asin_limitCases",
  2802. "Checks the edge of the domain (+/-1)", TEST_ENABLED
  2803. };
  2804. static const SDLTest_TestCaseReference asinTestOutOfDomain = {
  2805. (SDLTest_TestCaseFp)asin_outOfDomainCases, "asin_outOfDomainCases",
  2806. "Checks values outside the domain", TEST_ENABLED
  2807. };
  2808. static const SDLTest_TestCaseReference asinTestNan = {
  2809. (SDLTest_TestCaseFp)asin_nanCase, "asin_nanCase",
  2810. "Checks NAN", TEST_ENABLED
  2811. };
  2812. static const SDLTest_TestCaseReference asinTestPrecision = {
  2813. (SDLTest_TestCaseFp)asin_precisionTest, "asin_precisionTest",
  2814. "Checks asin precision", TEST_ENABLED
  2815. };
  2816. /* SDL_atan test cases */
  2817. static const SDLTest_TestCaseReference atanTestLimit = {
  2818. (SDLTest_TestCaseFp)atan_limitCases, "atan_limitCases",
  2819. "Checks the edge of the domain (+/-Infinity)", TEST_ENABLED
  2820. };
  2821. static const SDLTest_TestCaseReference atanTestZero = {
  2822. (SDLTest_TestCaseFp)atan_zeroCases, "atan_zeroCases",
  2823. "Checks for positive and negative zero", TEST_ENABLED
  2824. };
  2825. static const SDLTest_TestCaseReference atanTestNan = {
  2826. (SDLTest_TestCaseFp)atan_nanCase, "atan_nanCase",
  2827. "Checks NAN", TEST_ENABLED
  2828. };
  2829. static const SDLTest_TestCaseReference atanTestPrecision = {
  2830. (SDLTest_TestCaseFp)atan_precisionTest, "atan_precisionTest",
  2831. "Checks atan precision", TEST_ENABLED
  2832. };
  2833. /* SDL_atan2 test cases */
  2834. static const SDLTest_TestCaseReference atan2TestZero1 = {
  2835. (SDLTest_TestCaseFp)atan2_bothZeroCases, "atan2_bothZeroCases",
  2836. "Checks for both arguments being zero", TEST_ENABLED
  2837. };
  2838. static const SDLTest_TestCaseReference atan2TestZero2 = {
  2839. (SDLTest_TestCaseFp)atan2_yZeroCases, "atan2_yZeroCases",
  2840. "Checks for y=0", TEST_ENABLED
  2841. };
  2842. static const SDLTest_TestCaseReference atan2TestZero3 = {
  2843. (SDLTest_TestCaseFp)atan2_xZeroCases, "atan2_xZeroCases",
  2844. "Checks for x=0", TEST_ENABLED
  2845. };
  2846. static const SDLTest_TestCaseReference atan2TestInf1 = {
  2847. (SDLTest_TestCaseFp)atan2_bothInfCases, "atan2_bothInfCases",
  2848. "Checks for both arguments being infinity", TEST_ENABLED
  2849. };
  2850. static const SDLTest_TestCaseReference atan2TestInf2 = {
  2851. (SDLTest_TestCaseFp)atan2_yInfCases, "atan2_yInfCases",
  2852. "Checks for y=0", TEST_ENABLED
  2853. };
  2854. static const SDLTest_TestCaseReference atan2TestInf3 = {
  2855. (SDLTest_TestCaseFp)atan2_xInfCases, "atan2_xInfCases",
  2856. "Checks for x=0", TEST_ENABLED
  2857. };
  2858. static const SDLTest_TestCaseReference atan2TestNan = {
  2859. (SDLTest_TestCaseFp)atan2_nanCases, "atan2_nanCases",
  2860. "Checks NANs", TEST_ENABLED
  2861. };
  2862. static const SDLTest_TestCaseReference atan2TestQuadrantTopRight = {
  2863. (SDLTest_TestCaseFp)atan2_topRightQuadrantTest, "atan2_topRightQuadrantTest",
  2864. "Checks values in the top right quadrant", TEST_ENABLED
  2865. };
  2866. static const SDLTest_TestCaseReference atan2TestQuadrantTopLeft = {
  2867. (SDLTest_TestCaseFp)atan2_topLeftQuadrantTest, "atan2_topLeftQuadrantTest",
  2868. "Checks values in the top left quadrant", TEST_ENABLED
  2869. };
  2870. static const SDLTest_TestCaseReference atan2TestQuadrantBottomRight = {
  2871. (SDLTest_TestCaseFp)atan2_bottomRightQuadrantTest, "atan2_bottomRightQuadrantTest",
  2872. "Checks values in the bottom right quadrant", TEST_ENABLED
  2873. };
  2874. static const SDLTest_TestCaseReference atan2TestQuadrantBottomLeft = {
  2875. (SDLTest_TestCaseFp)atan2_bottomLeftQuadrantTest, "atan2_bottomLeftQuadrantTest",
  2876. "Checks values in the bottom left quadrant", TEST_ENABLED
  2877. };
  2878. static const SDLTest_TestCaseReference *mathTests[] = {
  2879. &floorTestInf, &floorTestZero, &floorTestNan,
  2880. &floorTestRound, &floorTestFraction, &floorTestRange,
  2881. &ceilTestInf, &ceilTestZero, &ceilTestNan,
  2882. &ceilTestRound, &ceilTestFraction, &ceilTestRange,
  2883. &truncTestInf, &truncTestZero, &truncTestNan,
  2884. &truncTestRound, &truncTestFraction, &truncTestRange,
  2885. &roundTestInf, &roundTestZero, &roundTestNan,
  2886. &roundTestRound, &roundTestFraction, &roundTestRange,
  2887. &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
  2888. &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
  2889. &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
  2890. &fmodTestNan, &fmodTestRegular, &fmodTestRange,
  2891. &expTestInf, &expTestZero, &expTestOverflow,
  2892. &expTestBase, &expTestRegular,
  2893. &logTestLimit, &logTestNan,
  2894. &logTestBase, &logTestRegular,
  2895. &log10TestLimit, &log10TestNan,
  2896. &log10TestBase, &log10TestRegular,
  2897. &powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
  2898. &powTestBaseInf1, &powTestBaseInf2,
  2899. &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
  2900. &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
  2901. &powTestRegular, &powTestPowOf2, &powTestRange,
  2902. &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
  2903. &sqrtTestBase, &sqrtTestRegular,
  2904. &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
  2905. &scalbnTestNan, &scalbnTestRegular,
  2906. &cosTestInf, &cosTestNan, &cosTestRegular,
  2907. &cosTestPrecision, &cosTestRange,
  2908. &sinTestInf, &sinTestNan, &sinTestRegular,
  2909. &sinTestPrecision, &sinTestRange,
  2910. &tanTestInf, &tanTestNan, &tanTestZero, &tanTestPrecision,
  2911. &acosTestLimit, &acosTestOutOfDomain, &acosTestNan, &acosTestPrecision,
  2912. &asinTestLimit, &asinTestOutOfDomain, &asinTestNan, &asinTestPrecision,
  2913. &atanTestLimit, &atanTestZero, &atanTestNan, &atanTestPrecision,
  2914. &atan2TestZero1, &atan2TestZero2, &atan2TestZero3,
  2915. &atan2TestInf1, &atan2TestInf2, &atan2TestInf3,
  2916. &atan2TestNan, &atan2TestQuadrantTopRight, &atan2TestQuadrantTopLeft,
  2917. &atan2TestQuadrantBottomRight, &atan2TestQuadrantBottomLeft,
  2918. NULL
  2919. };
  2920. SDLTest_TestSuiteReference mathTestSuite = { "Math", NULL, mathTests, NULL };