testautomation_math.c 98 KB

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