testautomation_math.c 96 KB

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