testautomation_math.c 98 KB

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