testautomation_math.c 96 KB

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