testautomation_math.c 98 KB

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