testautomation_math.c 98 KB

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