testautomation_math.c 98 KB

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