testautomation_math.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384
  1. /**
  2. * Math test suite
  3. */
  4. #include <float.h>
  5. #include <math.h>
  6. #include <SDL3/SDL.h>
  7. #include <SDL3/SDL_test.h>
  8. /* ================= Test Constants ================== */
  9. /* Range tests parameters */
  10. #define RANGE_TEST_ITERATIONS 10000000
  11. #define RANGE_TEST_STEP ((Uint32)(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 %" SDL_PRIu32,
  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 %" SDL_PRIu32,
  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 %" SDL_PRIu32,
  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(result >= EULER - EPSILON &&
  935. result <= EULER + EPSILON,
  936. "Exp(%f), expected [%f,%f], got %f",
  937. 1.0, EULER - EPSILON, EULER + EPSILON, result);
  938. return TEST_COMPLETED;
  939. }
  940. /**
  941. * Inputs: values within the domain of the function.
  942. * Expected: the correct result is returned.
  943. */
  944. static int
  945. exp_regularCases(void *args)
  946. {
  947. /* Hexadecimal floating constants are not supported on C89 compilers */
  948. const d_to_d regular_cases[] = {
  949. { -101.0, 1.36853947117385291381565719268793547578002532127613087E-44 },
  950. { -15.73, 0.00000014741707833928422931856502906683425990763681 },
  951. { -1.0, 0.36787944117144233402427744294982403516769409179688 },
  952. { -0.5, 0.60653065971263342426311737654032185673713684082031 },
  953. { 0.5, 1.64872127070012819416433558217249810695648193359375 },
  954. { 2.25, 9.48773583635852624240669683786109089851379394531250 },
  955. { 34.125, 661148770968660.375 },
  956. { 112.89, 10653788283588960962604279261058893737879589093376.0 },
  957. { 539.483, 1970107755334319939701129934673541628417235942656909222826926175622435588279443011110464355295725187195188154768877850257012251677751742837992843520967922303961718983154427294786640886286983037548604937796221048661733679844353544028160.0 },
  958. };
  959. return helper_dtod("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases));
  960. }
  961. /* SDL_log tests functions */
  962. /**
  963. * Inputs: Positive Infinity and +/-0.0.
  964. * Expected: Positive and negative Infinity respectively.
  965. */
  966. static int
  967. log_limitCases(void *args)
  968. {
  969. double result;
  970. result = SDL_log(INFINITY);
  971. SDLTest_AssertCheck(INFINITY == result,
  972. "Log(%f), expected %f, got %f",
  973. INFINITY, INFINITY, result);
  974. result = SDL_log(0.0);
  975. SDLTest_AssertCheck(-INFINITY == result,
  976. "Log(%f), expected %f, got %f",
  977. 0.0, -INFINITY, result);
  978. result = SDL_log(-0.0);
  979. SDLTest_AssertCheck(-INFINITY == result,
  980. "Log(%f), expected %f, got %f",
  981. -0.0, -INFINITY, result);
  982. return TEST_COMPLETED;
  983. }
  984. /**
  985. * Inputs: 1.0 and the Euler constant.
  986. * Expected: 0.0 and 1.0 respectively.
  987. */
  988. static int
  989. log_baseCases(void *args)
  990. {
  991. double result;
  992. result = SDL_log(1.0);
  993. SDLTest_AssertCheck(0.0 == result,
  994. "Log(%f), expected %f, got %f",
  995. 1.0, 0.0, result);
  996. result = SDL_log(EULER);
  997. SDLTest_AssertCheck(1.0 == result,
  998. "Log(%f), expected %f, got %f",
  999. EULER, 1.0, result);
  1000. return TEST_COMPLETED;
  1001. }
  1002. /**
  1003. * Inputs: NAN and a negative value.
  1004. * Expected: NAN is returned.
  1005. */
  1006. static int
  1007. log_nanCases(void *args)
  1008. {
  1009. double result;
  1010. result = SDL_log(NAN);
  1011. SDLTest_AssertCheck(isnan(result),
  1012. "Log(%f), expected %f, got %f",
  1013. NAN, NAN, result);
  1014. result = SDL_log(-1234.5678);
  1015. SDLTest_AssertCheck(isnan(result),
  1016. "Log(%f), expected %f, got %f",
  1017. -1234.5678, NAN, result);
  1018. return TEST_COMPLETED;
  1019. }
  1020. /**
  1021. * Inputs: values within the domain of the function.
  1022. * Expected: the correct result is returned.
  1023. */
  1024. static int
  1025. log_regularCases(void *args)
  1026. {
  1027. const d_to_d regular_cases[] = {
  1028. { 5.0, 1.60943791243410028179994242236716672778129577636718750 },
  1029. { 10.0, 2.302585092994045901093613792909309267997741699218750 },
  1030. { 56.32, 4.031049711849786554296315443934872746467590332031250 },
  1031. { 789.123, 6.670922202231861497523368598194792866706848144531250 },
  1032. { 2734.876324, 7.91384149408957959792587644187733530998229980468750 }
  1033. };
  1034. return helper_dtod("Log", SDL_log, regular_cases, SDL_arraysize(regular_cases));
  1035. }
  1036. /* SDL_log10 tests functions */
  1037. /**
  1038. * Inputs: Positive Infinity and +/-0.0.
  1039. * Expected: Positive and negative Infinity respectively.
  1040. */
  1041. static int
  1042. log10_limitCases(void *args)
  1043. {
  1044. double result;
  1045. result = SDL_log10(INFINITY);
  1046. SDLTest_AssertCheck(INFINITY == result,
  1047. "Log10(%f), expected %f, got %f",
  1048. INFINITY, INFINITY, result);
  1049. result = SDL_log10(0.0);
  1050. SDLTest_AssertCheck(-INFINITY == result,
  1051. "Log10(%f), expected %f, got %f",
  1052. 0.0, -INFINITY, result);
  1053. result = SDL_log10(-0.0);
  1054. SDLTest_AssertCheck(-INFINITY == result,
  1055. "Log10(%f), expected %f, got %f",
  1056. -0.0, -INFINITY, result);
  1057. return TEST_COMPLETED;
  1058. }
  1059. /**
  1060. * Inputs: Powers of ten from 0 to 9.
  1061. * Expected: the exact power of ten is returned.
  1062. */
  1063. static int
  1064. log10_baseCases(void *args)
  1065. {
  1066. const d_to_d base_cases[] = {
  1067. { 1.0, 0.0 },
  1068. { 10.0, 1.0 },
  1069. { 100.0, 2.0 },
  1070. { 1000.0, 3.0 },
  1071. { 10000.0, 4.0 },
  1072. { 100000.0, 5.0 },
  1073. { 1000000.0, 6.0 },
  1074. { 10000000.0, 7.0 },
  1075. { 100000000.0, 8.0 },
  1076. { 1000000000.0, 9.0 },
  1077. };
  1078. return helper_dtod("Log10", SDL_log10, base_cases, SDL_arraysize(base_cases));
  1079. }
  1080. /**
  1081. * Inputs: NAN and a negative value.
  1082. * Expected: NAN is returned.
  1083. */
  1084. static int
  1085. log10_nanCases(void *args)
  1086. {
  1087. double result;
  1088. result = SDL_log10(NAN);
  1089. SDLTest_AssertCheck(isnan(result),
  1090. "Log10(%f), expected %f, got %f",
  1091. NAN, NAN, result);
  1092. result = SDL_log10(-1234.5678);
  1093. SDLTest_AssertCheck(isnan(result),
  1094. "Log10(%f), expected %f, got %f",
  1095. -1234.5678, NAN, result);
  1096. return TEST_COMPLETED;
  1097. }
  1098. /**
  1099. * Inputs: values within the domain of the function.
  1100. * Expected: the correct result is returned.
  1101. */
  1102. static int
  1103. log10_regularCases(void *args)
  1104. {
  1105. const d_to_d regular_cases[] = {
  1106. { 5.0, 0.698970004336018857493684208748163655400276184082031250 },
  1107. { 12.5, 1.09691001300805646145875016372883692383766174316406250 },
  1108. { 56.32, 1.750662646134055755453573510749265551567077636718750 },
  1109. { 789.123, 2.8971447016351858927407647570362314581871032714843750 },
  1110. { 2734.876324, 3.436937691540090433761633903486654162406921386718750 }
  1111. };
  1112. return helper_dtod_inexact("Log10", SDL_log10, regular_cases, SDL_arraysize(regular_cases));
  1113. }
  1114. /* SDL_modf tests functions */
  1115. static int
  1116. modf_baseCases(void *args)
  1117. {
  1118. double fractional, integral;
  1119. fractional = SDL_modf(1.25, &integral);
  1120. SDLTest_AssertCheck(integral == 1.0,
  1121. "modf(%f), expected integral %f, got %f",
  1122. 1.25, 1.0, integral);
  1123. SDLTest_AssertCheck(fractional == 0.25,
  1124. "modf(%f), expected fractional %f, got %f",
  1125. 1.25, 0.25, fractional);
  1126. return TEST_COMPLETED;
  1127. }
  1128. /* SDL_pow tests functions */
  1129. /* Tests with positive and negative infinities as exponents */
  1130. /**
  1131. * Inputs: (-1.0, +/-Infinity).
  1132. * Expected: 1.0 is returned.
  1133. */
  1134. static int
  1135. pow_baseNOneExpInfCases(void *args)
  1136. {
  1137. double result;
  1138. result = SDL_pow(-1.0, INFINITY);
  1139. SDLTest_AssertCheck(1.0 == result,
  1140. "Pow(%f,%f), expected %f, got %f",
  1141. -1.0, INFINITY, 1.0, result);
  1142. result = SDL_pow(-1.0, -INFINITY);
  1143. SDLTest_AssertCheck(1.0 == result,
  1144. "Pow(%f,%f), expected %f, got %f",
  1145. -1.0, -INFINITY, 1.0, result);
  1146. return TEST_COMPLETED;
  1147. }
  1148. /**
  1149. * Inputs: (+/-0.0, -Infinity).
  1150. * Expected: Infinity is returned.
  1151. */
  1152. static int
  1153. pow_baseZeroExpNInfCases(void *args)
  1154. {
  1155. double result;
  1156. result = SDL_pow(0.0, -INFINITY);
  1157. SDLTest_AssertCheck(INFINITY == result,
  1158. "Pow(%f,%f), expected %f, got %f",
  1159. 0.0, -INFINITY, INFINITY, result);
  1160. result = SDL_pow(-0.0, -INFINITY);
  1161. SDLTest_AssertCheck(INFINITY == result,
  1162. "Pow(%f,%f), expected %f, got %f",
  1163. -0.0, -INFINITY, INFINITY, result);
  1164. return TEST_COMPLETED;
  1165. }
  1166. /**
  1167. * Inputs: (x, +/-Infinity) where x is not +/-0.0.
  1168. * Expected: 0.0 when x < 1, Infinity when x > 1.
  1169. */
  1170. static int
  1171. pow_expInfCases(void *args)
  1172. {
  1173. double result;
  1174. result = SDL_pow(0.5, INFINITY);
  1175. SDLTest_AssertCheck(0.0 == result,
  1176. "Pow(%f,%f), expected %f, got %f",
  1177. 0.5, INFINITY, 0.0, result);
  1178. result = SDL_pow(1.5, INFINITY);
  1179. SDLTest_AssertCheck(INFINITY == result,
  1180. "Pow(%f,%f), expected %f, got %f",
  1181. 1.5, INFINITY, INFINITY, result);
  1182. result = SDL_pow(0.5, -INFINITY);
  1183. SDLTest_AssertCheck(INFINITY == result,
  1184. "Pow(%f,%f), expected %f, got %f",
  1185. 0.5, INFINITY, INFINITY, result);
  1186. result = SDL_pow(1.5, -INFINITY);
  1187. SDLTest_AssertCheck(0.0 == result,
  1188. "Pow(%f,%f), expected %f, got %f",
  1189. 1.5, -INFINITY, 0.0, result);
  1190. return TEST_COMPLETED;
  1191. }
  1192. /* Tests with positive and negative infinities as base */
  1193. /**
  1194. * Inputs: (Positive Infinity, x) where x is not +/-0.0.
  1195. * Expected: 0.0 when x is < 0, positive Infinity when x > 0.
  1196. */
  1197. static int
  1198. pow_basePInfCases(void *args)
  1199. {
  1200. double result;
  1201. result = SDL_pow(INFINITY, -3.0);
  1202. SDLTest_AssertCheck(0.0 == result,
  1203. "Pow(%f,%f), expected %f, got %f",
  1204. INFINITY, -3.0, 0.0, result);
  1205. result = SDL_pow(INFINITY, 2.0);
  1206. SDLTest_AssertCheck(INFINITY == result,
  1207. "Pow(%f,%f), expected %f, got %f",
  1208. INFINITY, 2.0, INFINITY, result);
  1209. result = SDL_pow(INFINITY, -2.12345);
  1210. SDLTest_AssertCheck(0.0 == result,
  1211. "Pow(%f,%f), expected %f, got %f",
  1212. INFINITY, -2.12345, 0.0, result);
  1213. result = SDL_pow(INFINITY, 3.1345);
  1214. SDLTest_AssertCheck(INFINITY == result,
  1215. "Pow(%f,%f), expected %f, got %f",
  1216. INFINITY, 3.12345, INFINITY, result);
  1217. return TEST_COMPLETED;
  1218. }
  1219. /**
  1220. * Inputs: (Negative Infinity, x) where x is not +/-0.0.
  1221. * Expected:
  1222. * - -0.0 when x is a negative odd integer,
  1223. * - 0.0 when x is a negative even integer or negative non-integer,
  1224. * - Negative Infinity when x is a positive odd integer,
  1225. * - Positive Infinity when x is a positive even integer or positive non-integer.
  1226. */
  1227. static int
  1228. pow_baseNInfCases(void *args)
  1229. {
  1230. double result;
  1231. result = SDL_pow(-INFINITY, -3.0);
  1232. SDLTest_AssertCheck(-0.0 == result,
  1233. "Pow(%f,%f), expected %f, got %f",
  1234. -INFINITY, -3.0, -0.0, result);
  1235. result = SDL_pow(-INFINITY, -2.0);
  1236. SDLTest_AssertCheck(0.0 == result,
  1237. "Pow(%f,%f), expected %f, got %f",
  1238. -INFINITY, -2.0, 0.0, result);
  1239. result = SDL_pow(-INFINITY, -5.5);
  1240. SDLTest_AssertCheck(0.0 == result,
  1241. "Pow(%f,%f), expected %f, got %f",
  1242. -INFINITY, -5.5, 0.0, result);
  1243. result = SDL_pow(-INFINITY, 3.0);
  1244. SDLTest_AssertCheck(-INFINITY == result,
  1245. "Pow(%f,%f), expected %f, got %f",
  1246. -INFINITY, 3.0, -INFINITY, result);
  1247. result = SDL_pow(-INFINITY, 2.0);
  1248. SDLTest_AssertCheck(INFINITY == result,
  1249. "Pow(%f,%f), expected %f, got %f",
  1250. -INFINITY, 2.0, INFINITY, result);
  1251. result = SDL_pow(-INFINITY, 5.5);
  1252. SDLTest_AssertCheck(INFINITY == result,
  1253. "Pow(%f,%f), expected %f, got %f",
  1254. -INFINITY, 5.5, INFINITY, result);
  1255. return TEST_COMPLETED;
  1256. }
  1257. /* Tests related to NAN */
  1258. /**
  1259. * Inputs:
  1260. * - finite and negative base,
  1261. * - finite and non-integer exponent.
  1262. * Expected: NAN is returned.
  1263. */
  1264. static int
  1265. pow_badOperationCase(void *args)
  1266. {
  1267. const double result = SDL_pow(-2.0, 4.2);
  1268. SDLTest_AssertCheck(isnan(result),
  1269. "Pow(%f,%f), expected %f, got %f",
  1270. -2.0, 4.2, NAN, result);
  1271. return TEST_COMPLETED;
  1272. }
  1273. /**
  1274. * Inputs: (1.0, NAN)
  1275. * Expected: 1.0 is returned.
  1276. */
  1277. static int
  1278. pow_base1ExpNanCase(void *args)
  1279. {
  1280. const double result = SDL_pow(1.0, NAN);
  1281. SDLTest_AssertCheck(1.0 == result,
  1282. "Pow(%f,%f), expected %f, got %f",
  1283. 1.0, NAN, 1.0, result);
  1284. return TEST_COMPLETED;
  1285. }
  1286. /**
  1287. * Inputs: (NAN, +/-0.0)
  1288. * Expected: 1.0 is returned.
  1289. */
  1290. static int
  1291. pow_baseNanExp0Cases(void *args)
  1292. {
  1293. double result;
  1294. result = SDL_pow(NAN, 0.0);
  1295. SDLTest_AssertCheck(1.0 == result,
  1296. "Pow(%f,%f), expected %f, got %f",
  1297. NAN, 0.0, 1.0, result);
  1298. result = SDL_pow(NAN, -0.0);
  1299. SDLTest_AssertCheck(1.0 == result,
  1300. "Pow(%f,%f), expected %f, got %f",
  1301. NAN, -0.0, 1.0, result);
  1302. return TEST_COMPLETED;
  1303. }
  1304. /**
  1305. * Inputs: NAN as base, exponent or both.
  1306. * Expected: NAN is returned.
  1307. */
  1308. static int
  1309. pow_nanArgsCases(void *args)
  1310. {
  1311. double result;
  1312. result = SDL_pow(7.8, NAN);
  1313. SDLTest_AssertCheck(isnan(result),
  1314. "Pow(%f,%f), expected %f, got %f",
  1315. 7.8, NAN, NAN, result);
  1316. result = SDL_pow(NAN, 10.0);
  1317. SDLTest_AssertCheck(isnan(result),
  1318. "Pow(%f,%f), expected %f, got %f",
  1319. NAN, 10.0, NAN, result);
  1320. result = SDL_pow(NAN, NAN);
  1321. SDLTest_AssertCheck(isnan(result),
  1322. "Pow(%f,%f), expected %f, got %f",
  1323. NAN, NAN, NAN, result);
  1324. return TEST_COMPLETED;
  1325. }
  1326. /* Tests with positive and negative zeros as base */
  1327. /**
  1328. * Inputs: (-0.0, x) where x is an odd integer.
  1329. * Expected:
  1330. * - Negative Infinity with a negative exponent,
  1331. * - -0.0 with a positive exponent.
  1332. */
  1333. static int
  1334. pow_baseNZeroExpOddCases(void *args)
  1335. {
  1336. double result;
  1337. result = SDL_pow(-0.0, -3.0);
  1338. SDLTest_AssertCheck(-INFINITY == result,
  1339. "Pow(%f,%f), expected %f, got %f",
  1340. -0.0, -3.0, -INFINITY, result);
  1341. result = SDL_pow(-0.0, 3.0);
  1342. SDLTest_AssertCheck(-0.0 == result,
  1343. "Pow(%f,%f), expected %f, got %f",
  1344. -0.0, 3.0, -0.0, result);
  1345. return TEST_COMPLETED;
  1346. }
  1347. /**
  1348. * Inputs: (0.0, x) where x is an odd integer.
  1349. * Expected:
  1350. * - 0.0 with a positive exponent,
  1351. * - Positive Infinity with a negative exponent.
  1352. */
  1353. static int
  1354. pow_basePZeroExpOddCases(void *args)
  1355. {
  1356. double result;
  1357. result = SDL_pow(0.0, -5.0);
  1358. SDLTest_AssertCheck(INFINITY == result,
  1359. "Pow(%f,%f), expected %f, got %f",
  1360. 0.0, -5.0, INFINITY, result);
  1361. result = SDL_pow(0.0, 5.0);
  1362. SDLTest_AssertCheck(0.0 == result,
  1363. "Pow(%f,%f), expected %f, got %f",
  1364. 0.0, 5.0, 0.0, result);
  1365. return TEST_COMPLETED;
  1366. }
  1367. /**
  1368. * Inputs: (-0.0, x), with x either:
  1369. * - finite and even,
  1370. * - finite and non-integer.
  1371. * Expected:
  1372. * - Positive Infinity if the exponent is negative,
  1373. * - 0.0 if the exponent is positive.
  1374. */
  1375. static int
  1376. pow_baseNZeroCases(void *args)
  1377. {
  1378. double result;
  1379. result = SDL_pow(-0.0, -3.5);
  1380. SDLTest_AssertCheck(INFINITY == result,
  1381. "Pow(%f,%f), expected %f, got %f",
  1382. -0.0, -3.5, INFINITY, result);
  1383. result = SDL_pow(-0.0, -4.0);
  1384. SDLTest_AssertCheck(INFINITY == result,
  1385. "Pow(%f,%f), expected %f, got %f",
  1386. -0.0, -4.0, INFINITY, result);
  1387. result = SDL_pow(-0.0, 3.5);
  1388. SDLTest_AssertCheck(0.0 == result,
  1389. "Pow(%f,%f), expected %f, got %f",
  1390. -0.0, 3.5, 0.0, result);
  1391. result = SDL_pow(-0.0, 4.0);
  1392. SDLTest_AssertCheck(0.0 == result,
  1393. "Pow(%f,%f), expected %f, got %f",
  1394. -0.0, 4.0, 0.0, result);
  1395. return TEST_COMPLETED;
  1396. }
  1397. /**
  1398. * Inputs: (0.0, x), with x either:
  1399. * - finite and even,
  1400. * - finite and non-integer.
  1401. * Expected:
  1402. * - Positive Infinity if the exponent is negative,
  1403. * - 0.0 if the exponent is positive.
  1404. */
  1405. static int
  1406. pow_basePZeroCases(void *args)
  1407. {
  1408. double result;
  1409. result = SDL_pow(0.0, -3.5);
  1410. SDLTest_AssertCheck(INFINITY == result,
  1411. "Pow(%f,%f), expected %f, got %f",
  1412. 0.0, -3.5, INFINITY, result);
  1413. result = SDL_pow(0.0, -4.0);
  1414. SDLTest_AssertCheck(INFINITY == result,
  1415. "Pow(%f,%f), expected %f, got %f",
  1416. 0.0, -4.0, INFINITY, result);
  1417. result = SDL_pow(0.0, 3.5);
  1418. SDLTest_AssertCheck(0.0 == result,
  1419. "Pow(%f,%f), expected %f, got %f",
  1420. 0.0, 3.5, 0.0, result);
  1421. result = SDL_pow(0.0, 4.0);
  1422. SDLTest_AssertCheck(0.0 == result,
  1423. "Pow(%f,%f), expected %f, got %f",
  1424. 0.0, 4.0, 0.0, result);
  1425. return TEST_COMPLETED;
  1426. }
  1427. /* Remaining tests */
  1428. /**
  1429. * Inputs: values within the domain of the function.
  1430. * Expected: the correct result is returned.
  1431. */
  1432. static int
  1433. pow_regularCases(void *args)
  1434. {
  1435. const dd_to_d regular_cases[] = {
  1436. { -391.25, -2.0, 0.00000653267870448815438463212659780943170062528224661946296691894531250 },
  1437. { -72.3, 12.0, 20401381050275984310272.0 },
  1438. { -5.0, 3.0, -125.0 },
  1439. { 3.0, 2.5, 15.58845726811989607085706666111946105957031250 },
  1440. { 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 },
  1441. { 478.972, 12.125, 315326359630449587856007411793920.0 }
  1442. };
  1443. return helper_ddtod("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases));
  1444. }
  1445. /**
  1446. * Inputs: (2.0, x), with x in range [0, 8].
  1447. * Expected: the correct result is returned.
  1448. */
  1449. static int
  1450. pow_powerOfTwo(void *args)
  1451. {
  1452. const dd_to_d power_of_two_cases[] = {
  1453. { 2.0, 1.0, 2.0 },
  1454. { 2.0, 2.0, 4.0 },
  1455. { 2.0, 3.0, 8.0 },
  1456. { 2.0, 4.0, 16.0 },
  1457. { 2.0, 5.0, 32.0 },
  1458. { 2.0, 6.0, 64.0 },
  1459. { 2.0, 7.0, 128.0 },
  1460. { 2.0, 8.0, 256.0 },
  1461. };
  1462. return helper_ddtod("Pow", SDL_pow, power_of_two_cases, SDL_arraysize(power_of_two_cases));
  1463. }
  1464. /**
  1465. * Inputs: values in the range [0, UINT32_MAX] to the power of +/-0.0.
  1466. * Expected: 1.0 is always returned.
  1467. */
  1468. static int
  1469. pow_rangeTest(void *args)
  1470. {
  1471. Uint32 i;
  1472. double test_value = 0.0;
  1473. SDLTest_AssertPass("Pow: Testing a range of %u values with steps of %" SDL_PRIu32,
  1474. RANGE_TEST_ITERATIONS,
  1475. RANGE_TEST_STEP);
  1476. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1477. double result;
  1478. /* These are tested elsewhere */
  1479. if (isnan(test_value) || isinf(test_value)) {
  1480. continue;
  1481. }
  1482. /* Only log failures to save performances */
  1483. result = SDL_pow(test_value, 0.0);
  1484. if (result != 1.0) {
  1485. SDLTest_AssertCheck(SDL_FALSE,
  1486. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1487. test_value, 1.0, 1.0, result);
  1488. return TEST_ABORTED;
  1489. }
  1490. result = SDL_pow(test_value, -0.0);
  1491. if (result != 1.0) {
  1492. SDLTest_AssertCheck(SDL_FALSE,
  1493. "Pow(%.1f,%.1f), expected %.1f, got %.1f",
  1494. test_value, -0.0, 1.0, result);
  1495. return TEST_ABORTED;
  1496. }
  1497. }
  1498. return TEST_COMPLETED;
  1499. }
  1500. /* SDL_sqrt tests functions */
  1501. /**
  1502. * Input: Positive Infinity.
  1503. * Expected: Positive Infinity is returned.
  1504. */
  1505. static int
  1506. sqrt_infCase(void *args)
  1507. {
  1508. const double result = SDL_sqrt(INFINITY);
  1509. SDLTest_AssertCheck(INFINITY == result,
  1510. "Sqrt(%f), expected %f, got %f",
  1511. INFINITY, INFINITY, result);
  1512. return TEST_COMPLETED;
  1513. }
  1514. /**
  1515. * Input: NAN.
  1516. * Expected: NAN is returned.
  1517. */
  1518. static int
  1519. sqrt_nanCase(void *args)
  1520. {
  1521. const double result = SDL_sqrt(NAN);
  1522. SDLTest_AssertCheck(isnan(result),
  1523. "Sqrt(%f), expected %f, got %f",
  1524. NAN, NAN, result);
  1525. return TEST_COMPLETED;
  1526. }
  1527. /**
  1528. * Inputs: values outside the domain of the function.
  1529. * Expected: NAN is returned.
  1530. */
  1531. static int
  1532. sqrt_outOfDomainCases(void *args)
  1533. {
  1534. double result;
  1535. result = SDL_sqrt(-1.0);
  1536. SDLTest_AssertCheck(isnan(result),
  1537. "Sqrt(%f), expected %f, got %f",
  1538. -1.0, NAN, result);
  1539. result = SDL_sqrt(-12345.6789);
  1540. SDLTest_AssertCheck(isnan(result),
  1541. "Sqrt(%f), expected %f, got %f",
  1542. -12345.6789, NAN, result);
  1543. result = SDL_sqrt(-INFINITY);
  1544. SDLTest_AssertCheck(isnan(result),
  1545. "Sqrt(%f), expected %f, got %f",
  1546. -INFINITY, NAN, result);
  1547. return TEST_COMPLETED;
  1548. }
  1549. /**
  1550. * Inputs: +/-0.0 and 1.0.
  1551. * Expected: the input value is returned as-is.
  1552. */
  1553. static int
  1554. sqrt_baseCases(void *args)
  1555. {
  1556. const d_to_d base_cases[] = {
  1557. { -0.0, -0.0 },
  1558. { 0.0, 0.0 },
  1559. { 1.0, 1.0 }
  1560. };
  1561. return helper_dtod("Sqrt", SDL_sqrt, base_cases, SDL_arraysize(base_cases));
  1562. }
  1563. /**
  1564. * Inputs: values within the domain of the function.
  1565. * Expected: the correct result is returned.
  1566. */
  1567. static int
  1568. sqrt_regularCases(void *args)
  1569. {
  1570. const d_to_d regular_cases[] = {
  1571. { 4.0, 2.0 },
  1572. { 9.0, 3.0 },
  1573. { 27.2, 5.21536192416211896727418206864967942237854003906250 },
  1574. { 240.250, 15.5 },
  1575. { 1337.0, 36.565010597564445049556525191292166709899902343750 },
  1576. { 2887.12782400000014604302123188972473144531250, 53.732 },
  1577. { 65600.0156250, 256.125 }
  1578. };
  1579. return helper_dtod_inexact("Sqrt", SDL_sqrt, regular_cases, SDL_arraysize(regular_cases));
  1580. }
  1581. /* SDL_scalbn tests functions */
  1582. /**
  1583. * Input: (+/-Infinity, 1).
  1584. * Expected: Infinity is returned as-is.
  1585. */
  1586. static int
  1587. scalbn_infCases(void *args)
  1588. {
  1589. double result;
  1590. result = SDL_scalbn(INFINITY, 1);
  1591. SDLTest_AssertCheck(INFINITY == result,
  1592. "Scalbn(%f,%d), expected %f, got %f",
  1593. INFINITY, 1, INFINITY, result);
  1594. result = SDL_scalbn(-INFINITY, 1);
  1595. SDLTest_AssertCheck(-INFINITY == result,
  1596. "Scalbn(%f,%d), expected %f, got %f",
  1597. -INFINITY, 1, -INFINITY, result);
  1598. return TEST_COMPLETED;
  1599. }
  1600. /**
  1601. * Inputs: (+/-0.0, 1).
  1602. * Expected: Zero is returned as-is.
  1603. */
  1604. static int
  1605. scalbn_baseZeroCases(void *args)
  1606. {
  1607. double result;
  1608. result = SDL_scalbn(0.0, 1);
  1609. SDLTest_AssertCheck(0.0 == result,
  1610. "Scalbn(%f,%d), expected %f, got %f",
  1611. 0.0, 1, 0.0, result);
  1612. result = SDL_scalbn(-0.0, 1);
  1613. SDLTest_AssertCheck(-0.0 == result,
  1614. "Scalbn(%f,%d), expected %f, got %f",
  1615. -0.0, 1, -0.0, result);
  1616. return TEST_COMPLETED;
  1617. }
  1618. /**
  1619. * Input: (x, 0)
  1620. * Expected: x is returned as-is.
  1621. */
  1622. static int
  1623. scalbn_expZeroCase(void *args)
  1624. {
  1625. const double result = SDL_scalbn(42.0, 0);
  1626. SDLTest_AssertCheck(42.0 == result,
  1627. "Scalbn(%f,%d), expected %f, got %f",
  1628. 42.0, 0, 42.0, result);
  1629. return TEST_COMPLETED;
  1630. }
  1631. /**
  1632. * Input: (NAN, x).
  1633. * Expected: NAN is returned.
  1634. */
  1635. static int
  1636. scalbn_nanCase(void *args)
  1637. {
  1638. const double result = SDL_scalbn(NAN, 2);
  1639. SDLTest_AssertCheck(isnan(result),
  1640. "Scalbn(%f,%d), expected %f, got %f",
  1641. NAN, 2, NAN, result);
  1642. return TEST_COMPLETED;
  1643. }
  1644. /**
  1645. * Inputs: values inside the domain of the function.
  1646. * Expected: the correct result is returned.
  1647. * NOTE: This test depends on SDL_pow and FLT_RADIX.
  1648. */
  1649. static int
  1650. scalbn_regularCases(void *args)
  1651. {
  1652. double result, expected;
  1653. result = SDL_scalbn(2.0, 2);
  1654. expected = 2.0 * SDL_pow(FLT_RADIX, 2);
  1655. SDLTest_AssertCheck(result == expected,
  1656. "Scalbn(%f,%d), expected %f, got %f",
  1657. 2.0, 2, expected, result);
  1658. result = SDL_scalbn(1.0, 13);
  1659. expected = 1.0 * SDL_pow(FLT_RADIX, 13);
  1660. SDLTest_AssertCheck(result == expected,
  1661. "Scalbn(%f,%d), expected %f, got %f",
  1662. 1.0, 13, expected, result);
  1663. result = SDL_scalbn(2.0, -5);
  1664. expected = 2.0 * SDL_pow(FLT_RADIX, -5);
  1665. SDLTest_AssertCheck(result == expected,
  1666. "Scalbn(%f,%d), expected %f, got %f",
  1667. 2.0, -5, expected, result);
  1668. result = SDL_scalbn(-1.0, -13);
  1669. expected = -1.0 * SDL_pow(FLT_RADIX, -13);
  1670. SDLTest_AssertCheck(result == expected,
  1671. "Scalbn(%f,%d), expected %f, got %f",
  1672. -1.0, -13, expected, result);
  1673. return TEST_COMPLETED;
  1674. }
  1675. /* SDL_cos tests functions */
  1676. /**
  1677. * Inputs: +/-Infinity.
  1678. * Expected: NAN is returned.
  1679. */
  1680. static int
  1681. cos_infCases(void *args)
  1682. {
  1683. double result;
  1684. result = SDL_cos(INFINITY);
  1685. SDLTest_AssertCheck(isnan(result),
  1686. "Cos(%f), expected %f, got %f",
  1687. INFINITY, NAN, result);
  1688. result = SDL_cos(-INFINITY);
  1689. SDLTest_AssertCheck(isnan(result),
  1690. "Cos(%f), expected %f, got %f",
  1691. -INFINITY, NAN, result);
  1692. return TEST_COMPLETED;
  1693. }
  1694. /**
  1695. * Input: NAN.
  1696. * Expected: NAN is returned.
  1697. */
  1698. static int
  1699. cos_nanCase(void *args)
  1700. {
  1701. const double result = SDL_cos(NAN);
  1702. SDLTest_AssertCheck(isnan(result),
  1703. "Cos(%f), expected %f, got %f",
  1704. NAN, NAN, result);
  1705. return TEST_COMPLETED;
  1706. }
  1707. /**
  1708. * Inputs: +/-0.0 and +/-Pi.
  1709. * Expected: +1.0 and -1.0 respectively.
  1710. */
  1711. static int
  1712. cos_regularCases(void *args)
  1713. {
  1714. const d_to_d regular_cases[] = {
  1715. { -SDL_PI_D, -1.0 },
  1716. { -0.0, 1.0 },
  1717. { 0.0, 1.0 },
  1718. { SDL_PI_D, -1.0 }
  1719. };
  1720. return helper_dtod("Cos", SDL_cos, regular_cases, SDL_arraysize(regular_cases));
  1721. }
  1722. /**
  1723. * Inputs: Angles between 1/10 and 9/10 of Pi (positive and negative).
  1724. * Expected: The correct result is returned (+/-EPSILON).
  1725. */
  1726. static int
  1727. cos_precisionTest(void *args)
  1728. {
  1729. const d_to_d precision_cases[] = {
  1730. { SDL_PI_D * 1.0 / 10.0, 0.9510565162 },
  1731. { SDL_PI_D * 2.0 / 10.0, 0.8090169943 },
  1732. { SDL_PI_D * 3.0 / 10.0, 0.5877852522 },
  1733. { SDL_PI_D * 4.0 / 10.0, 0.3090169943 },
  1734. { SDL_PI_D * 5.0 / 10.0, 0.0 },
  1735. { SDL_PI_D * 6.0 / 10.0, -0.3090169943 },
  1736. { SDL_PI_D * 7.0 / 10.0, -0.5877852522 },
  1737. { SDL_PI_D * 8.0 / 10.0, -0.8090169943 },
  1738. { SDL_PI_D * 9.0 / 10.0, -0.9510565162 },
  1739. { SDL_PI_D * -1.0 / 10.0, 0.9510565162 },
  1740. { SDL_PI_D * -2.0 / 10.0, 0.8090169943 },
  1741. { SDL_PI_D * -3.0 / 10.0, 0.5877852522 },
  1742. { SDL_PI_D * -4.0 / 10.0, 0.3090169943 },
  1743. { SDL_PI_D * -5.0 / 10.0, 0.0 },
  1744. { SDL_PI_D * -6.0 / 10.0, -0.3090169943 },
  1745. { SDL_PI_D * -7.0 / 10.0, -0.5877852522 },
  1746. { SDL_PI_D * -8.0 / 10.0, -0.8090169943 },
  1747. { SDL_PI_D * -9.0 / 10.0, -0.9510565162 }
  1748. };
  1749. return helper_dtod_inexact("Cos", SDL_cos, precision_cases, SDL_arraysize(precision_cases));
  1750. }
  1751. /**
  1752. * Inputs: Values in the range [0, UINT32_MAX].
  1753. * Expected: A value between 0 and 1 is returned.
  1754. */
  1755. static int
  1756. cos_rangeTest(void *args)
  1757. {
  1758. Uint32 i;
  1759. double test_value = 0.0;
  1760. SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %" SDL_PRIu32,
  1761. RANGE_TEST_ITERATIONS,
  1762. RANGE_TEST_STEP);
  1763. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1764. double result;
  1765. /* These are tested elsewhere */
  1766. if (isnan(test_value) || isinf(test_value)) {
  1767. continue;
  1768. }
  1769. /* Only log failures to save performances */
  1770. result = SDL_cos(test_value);
  1771. if (result < -1.0 || result > 1.0) {
  1772. SDLTest_AssertCheck(SDL_FALSE,
  1773. "Cos(%.1f), expected [%.1f,%.1f], got %.1f",
  1774. test_value, -1.0, 1.0, result);
  1775. return TEST_ABORTED;
  1776. }
  1777. }
  1778. return TEST_COMPLETED;
  1779. }
  1780. /* SDL_sin tests functions */
  1781. /**
  1782. * Inputs: +/-Infinity.
  1783. * Expected: NAN is returned.
  1784. */
  1785. static int
  1786. sin_infCases(void *args)
  1787. {
  1788. double result;
  1789. result = SDL_sin(INFINITY);
  1790. SDLTest_AssertCheck(isnan(result),
  1791. "Sin(%f), expected %f, got %f",
  1792. INFINITY, NAN, result);
  1793. result = SDL_sin(-INFINITY);
  1794. SDLTest_AssertCheck(isnan(result),
  1795. "Sin(%f), expected %f, got %f",
  1796. -INFINITY, NAN, result);
  1797. return TEST_COMPLETED;
  1798. }
  1799. /**
  1800. * Input: NAN.
  1801. * Expected: NAN is returned.
  1802. */
  1803. static int
  1804. sin_nanCase(void *args)
  1805. {
  1806. const double result = SDL_sin(NAN);
  1807. SDLTest_AssertCheck(isnan(result),
  1808. "Sin(%f), expected %f, got %f",
  1809. NAN, NAN, result);
  1810. return TEST_COMPLETED;
  1811. }
  1812. /**
  1813. * Inputs: +/-0.0 and +/-Pi/2.
  1814. * Expected: +/-0.0 and +/-1.0 respectively.
  1815. */
  1816. static int
  1817. sin_regularCases(void *args)
  1818. {
  1819. const d_to_d regular_cases[] = {
  1820. { -SDL_PI_D / 2, -1.0 },
  1821. { -0.0, -0.0 },
  1822. { 0.0, 0.0 },
  1823. { SDL_PI_D / 2, 1.0 }
  1824. };
  1825. return helper_dtod("Sin", SDL_sin, regular_cases, SDL_arraysize(regular_cases));
  1826. }
  1827. /**
  1828. * Inputs: Angles between 1/10 and 10/10 of Pi (positive and negative).
  1829. * Expected: The correct result is returned (+/-EPSILON).
  1830. * NOTE: +/-Pi/2 is tested in the regular cases.
  1831. */
  1832. static int
  1833. sin_precisionTest(void *args)
  1834. {
  1835. const d_to_d precision_cases[] = {
  1836. { SDL_PI_D * 1.0 / 10.0, 0.3090169943 },
  1837. { SDL_PI_D * 2.0 / 10.0, 0.5877852522 },
  1838. { SDL_PI_D * 3.0 / 10.0, 0.8090169943 },
  1839. { SDL_PI_D * 4.0 / 10.0, 0.9510565162 },
  1840. { SDL_PI_D * 6.0 / 10.0, 0.9510565162 },
  1841. { SDL_PI_D * 7.0 / 10.0, 0.8090169943 },
  1842. { SDL_PI_D * 8.0 / 10.0, 0.5877852522 },
  1843. { SDL_PI_D * 9.0 / 10.0, 0.3090169943 },
  1844. { SDL_PI_D, 0.0 },
  1845. { SDL_PI_D * -1.0 / 10.0, -0.3090169943 },
  1846. { SDL_PI_D * -2.0 / 10.0, -0.5877852522 },
  1847. { SDL_PI_D * -3.0 / 10.0, -0.8090169943 },
  1848. { SDL_PI_D * -4.0 / 10.0, -0.9510565162 },
  1849. { SDL_PI_D * -6.0 / 10.0, -0.9510565162 },
  1850. { SDL_PI_D * -7.0 / 10.0, -0.8090169943 },
  1851. { SDL_PI_D * -8.0 / 10.0, -0.5877852522 },
  1852. { SDL_PI_D * -9.0 / 10.0, -0.3090169943 },
  1853. { -SDL_PI_D, 0.0 },
  1854. };
  1855. return helper_dtod_inexact("Sin", SDL_sin, precision_cases, SDL_arraysize(precision_cases));
  1856. }
  1857. /**
  1858. * Inputs: Values in the range [0, UINT32_MAX].
  1859. * Expected: A value between 0 and 1 is returned.
  1860. */
  1861. static int
  1862. sin_rangeTest(void *args)
  1863. {
  1864. Uint32 i;
  1865. double test_value = 0.0;
  1866. SDLTest_AssertPass("Sin: Testing a range of %u values with steps of %" SDL_PRIu32,
  1867. RANGE_TEST_ITERATIONS,
  1868. RANGE_TEST_STEP);
  1869. for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
  1870. double result;
  1871. /* These are tested elsewhere */
  1872. if (isnan(test_value) || isinf(test_value)) {
  1873. continue;
  1874. }
  1875. /* Only log failures to save performances */
  1876. result = SDL_sin(test_value);
  1877. if (result < -1.0 || result > 1.0) {
  1878. SDLTest_AssertCheck(SDL_FALSE,
  1879. "Sin(%.1f), expected [%.1f,%.1f], got %.1f",
  1880. test_value, -1.0, 1.0, result);
  1881. return TEST_ABORTED;
  1882. }
  1883. }
  1884. return TEST_COMPLETED;
  1885. }
  1886. /* SDL_tan tests functions */
  1887. /**
  1888. * Inputs: +/-Infinity.
  1889. * Expected: NAN is returned.
  1890. */
  1891. static int
  1892. tan_infCases(void *args)
  1893. {
  1894. double result;
  1895. result = SDL_tan(INFINITY);
  1896. SDLTest_AssertCheck(isnan(result),
  1897. "Tan(%f), expected %f, got %f",
  1898. INFINITY, NAN, result);
  1899. result = SDL_tan(-INFINITY);
  1900. SDLTest_AssertCheck(isnan(result),
  1901. "Tan(%f), expected %f, got %f",
  1902. -INFINITY, NAN, result);
  1903. return TEST_COMPLETED;
  1904. }
  1905. /**
  1906. * Input: NAN.
  1907. * Expected: NAN is returned.
  1908. */
  1909. static int
  1910. tan_nanCase(void *args)
  1911. {
  1912. const double result = SDL_tan(NAN);
  1913. SDLTest_AssertCheck(isnan(result),
  1914. "Tan(%f), expected %f, got %f",
  1915. NAN, NAN, result);
  1916. return TEST_COMPLETED;
  1917. }
  1918. /**
  1919. * Inputs: +/-0.0.
  1920. * Expected: Zero is returned as-is.
  1921. */
  1922. static int
  1923. tan_zeroCases(void *args)
  1924. {
  1925. const d_to_d regular_cases[] = {
  1926. { -0.0, -0.0 },
  1927. { 0.0, 0.0 }
  1928. };
  1929. return helper_dtod("Tan", SDL_tan, regular_cases, SDL_arraysize(regular_cases));
  1930. }
  1931. /**
  1932. * Inputs: Angles between 1/11 and 10/11 of Pi (positive and negative).
  1933. * Expected: The correct result is returned (+/-EPSILON).
  1934. * NOTE: +/-Pi/2 is intentionally avoided as it returns garbage values.
  1935. */
  1936. static int
  1937. tan_precisionTest(void *args)
  1938. {
  1939. const d_to_d precision_cases[] = {
  1940. { SDL_PI_D * 1.0 / 11.0, 0.2936264929 },
  1941. { SDL_PI_D * 2.0 / 11.0, 0.6426609771 },
  1942. { SDL_PI_D * 3.0 / 11.0, 1.1540615205 },
  1943. { SDL_PI_D * 4.0 / 11.0, 2.1896945629 },
  1944. { SDL_PI_D * 5.0 / 11.0, 6.9551527717 },
  1945. { SDL_PI_D * 6.0 / 11.0, -6.9551527717 },
  1946. { SDL_PI_D * 7.0 / 11.0, -2.1896945629 },
  1947. { SDL_PI_D * 8.0 / 11.0, -1.1540615205 },
  1948. { SDL_PI_D * 9.0 / 11.0, -0.6426609771 },
  1949. { SDL_PI_D * 10.0 / 11.0, -0.2936264929 },
  1950. { SDL_PI_D * -1.0 / 11.0, -0.2936264929 },
  1951. { SDL_PI_D * -2.0 / 11.0, -0.6426609771 },
  1952. { SDL_PI_D * -3.0 / 11.0, -1.1540615205 },
  1953. { SDL_PI_D * -4.0 / 11.0, -2.1896945629 },
  1954. { SDL_PI_D * -5.0 / 11.0, -6.9551527717 },
  1955. { SDL_PI_D * -6.0 / 11.0, 6.9551527717 },
  1956. { SDL_PI_D * -7.0 / 11.0, 2.1896945629 },
  1957. { SDL_PI_D * -8.0 / 11.0, 1.1540615205 },
  1958. { SDL_PI_D * -9.0 / 11.0, 0.6426609771 },
  1959. { SDL_PI_D * -10.0 / 11.0, 0.2936264929 }
  1960. };
  1961. return helper_dtod_inexact("Tan", SDL_tan, precision_cases, SDL_arraysize(precision_cases));
  1962. }
  1963. /* SDL_acos tests functions */
  1964. /**
  1965. * Inputs: +/-1.0.
  1966. * Expected: 0.0 and Pi respectively.
  1967. */
  1968. static int
  1969. acos_limitCases(void *args)
  1970. {
  1971. double result;
  1972. result = SDL_acos(1.0);
  1973. SDLTest_AssertCheck(0.0 == result,
  1974. "Acos(%f), expected %f, got %f",
  1975. 1.0, 0.0, result);
  1976. result = SDL_acos(-1.0);
  1977. SDLTest_AssertCheck(SDL_PI_D == result,
  1978. "Acos(%f), expected %f, got %f",
  1979. -1.0, SDL_PI_D, result);
  1980. return TEST_COMPLETED;
  1981. }
  1982. /**
  1983. * Inputs: Values outside the domain of [-1, 1].
  1984. * Expected: NAN is returned.
  1985. */
  1986. static int
  1987. acos_outOfDomainCases(void *args)
  1988. {
  1989. double result;
  1990. result = SDL_acos(1.1);
  1991. SDLTest_AssertCheck(isnan(result),
  1992. "Acos(%f), expected %f, got %f",
  1993. 1.1, NAN, result);
  1994. result = SDL_acos(-1.1);
  1995. SDLTest_AssertCheck(isnan(result),
  1996. "Acos(%f), expected %f, got %f",
  1997. -1.1, NAN, result);
  1998. return TEST_COMPLETED;
  1999. }
  2000. /**
  2001. * Input: NAN.
  2002. * Expected: NAN is returned.
  2003. */
  2004. static int
  2005. acos_nanCase(void *args)
  2006. {
  2007. const double result = SDL_acos(NAN);
  2008. SDLTest_AssertCheck(isnan(result),
  2009. "Acos(%f), expected %f, got %f",
  2010. NAN, NAN, result);
  2011. return TEST_COMPLETED;
  2012. }
  2013. /**
  2014. * Inputs: Values between -0.9 and 0.9 with steps of 0.1.
  2015. * Expected: The correct result is returned (+/-EPSILON).
  2016. */
  2017. static int
  2018. acos_precisionTest(void *args)
  2019. {
  2020. const d_to_d precision_cases[] = {
  2021. { 0.9, 0.4510268117 },
  2022. { 0.8, 0.6435011087 },
  2023. { 0.7, 0.7953988301 },
  2024. { 0.6, 0.9272952180 },
  2025. { 0.5, 1.0471975511 },
  2026. { 0.4, 1.1592794807 },
  2027. { 0.3, 1.2661036727 },
  2028. { 0.2, 1.3694384060 },
  2029. { 0.1, 1.4706289056 },
  2030. { 0.0, 1.5707963267 },
  2031. { -0.0, 1.5707963267 },
  2032. { -0.1, 1.6709637479 },
  2033. { -0.2, 1.7721542475 },
  2034. { -0.3, 1.8754889808 },
  2035. { -0.4, 1.9823131728 },
  2036. { -0.5, 2.0943951023 },
  2037. { -0.6, 2.2142974355 },
  2038. { -0.7, 2.3461938234 },
  2039. { -0.8, 2.4980915447 },
  2040. { -0.9, 2.6905658417 },
  2041. };
  2042. return helper_dtod_inexact("Acos", SDL_acos, precision_cases, SDL_arraysize(precision_cases));
  2043. }
  2044. /* SDL_asin tests functions */
  2045. /**
  2046. * Inputs: +/-1.0.
  2047. * Expected: +/-Pi/2 is returned.
  2048. */
  2049. static int
  2050. asin_limitCases(void *args)
  2051. {
  2052. double result;
  2053. result = SDL_asin(1.0);
  2054. SDLTest_AssertCheck(SDL_PI_D / 2.0 == result,
  2055. "Asin(%f), expected %f, got %f",
  2056. 1.0, SDL_PI_D / 2.0, result);
  2057. result = SDL_asin(-1.0);
  2058. SDLTest_AssertCheck(-SDL_PI_D / 2.0 == result,
  2059. "Asin(%f), expected %f, got %f",
  2060. -1.0, -SDL_PI_D / 2.0, result);
  2061. return TEST_COMPLETED;
  2062. }
  2063. /**
  2064. * Inputs: Values outside the domain of [-1, 1].
  2065. * Expected: NAN is returned.
  2066. */
  2067. static int
  2068. asin_outOfDomainCases(void *args)
  2069. {
  2070. double result;
  2071. result = SDL_asin(1.1);
  2072. SDLTest_AssertCheck(isnan(result),
  2073. "Asin(%f), expected %f, got %f",
  2074. 1.1, NAN, result);
  2075. result = SDL_asin(-1.1);
  2076. SDLTest_AssertCheck(isnan(result),
  2077. "Asin(%f), expected %f, got %f",
  2078. -1.1, NAN, result);
  2079. return TEST_COMPLETED;
  2080. }
  2081. /**
  2082. * Input: NAN.
  2083. * Expected: NAN is returned.
  2084. */
  2085. static int
  2086. asin_nanCase(void *args)
  2087. {
  2088. const double result = SDL_asin(NAN);
  2089. SDLTest_AssertCheck(isnan(result),
  2090. "Asin(%f), expected %f, got %f",
  2091. NAN, NAN, result);
  2092. return TEST_COMPLETED;
  2093. }
  2094. /**
  2095. * Inputs: Values between -0.9 and 0.9 with steps of 0.1.
  2096. * Expected: The correct result is returned (+/-EPSILON).
  2097. */
  2098. static int
  2099. asin_precisionTest(void *args)
  2100. {
  2101. const d_to_d precision_cases[] = {
  2102. { 0.9, 1.1197695149 },
  2103. { 0.8, 0.9272952180 },
  2104. { 0.7, 0.7753974966 },
  2105. { 0.6, 0.6435011087 },
  2106. { 0.5, 0.5235987755 },
  2107. { 0.4, 0.4115168460 },
  2108. { 0.3, 0.3046926540 },
  2109. { 0.2, 0.2013579207 },
  2110. { 0.1, 0.1001674211 },
  2111. { 0.0, 0.0 },
  2112. { -0.0, -0.0 },
  2113. { -0.1, -0.1001674211 },
  2114. { -0.2, -0.2013579207 },
  2115. { -0.3, -0.3046926540 },
  2116. { -0.4, -0.4115168460 },
  2117. { -0.5, -0.5235987755 },
  2118. { -0.6, -0.6435011087 },
  2119. { -0.7, -0.7753974966 },
  2120. { -0.8, -0.9272952180 },
  2121. { -0.9, -1.1197695149 }
  2122. };
  2123. return helper_dtod_inexact("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases));
  2124. }
  2125. /* SDL_atan tests functions */
  2126. /**
  2127. * Inputs: +/-Infinity.
  2128. * Expected: +/-Pi/2 is returned.
  2129. */
  2130. static int
  2131. atan_limitCases(void *args)
  2132. {
  2133. double result;
  2134. result = SDL_atan(INFINITY);
  2135. SDLTest_AssertCheck((SDL_PI_D / 2.0) - EPSILON <= result &&
  2136. result <= (SDL_PI_D / 2.0) + EPSILON,
  2137. "Atan(%f), expected %f, got %f",
  2138. INFINITY, SDL_PI_D / 2.0, result);
  2139. result = SDL_atan(-INFINITY);
  2140. SDLTest_AssertCheck((-SDL_PI_D / 2.0) - EPSILON <= result &&
  2141. result <= (-SDL_PI_D / 2.0) + EPSILON,
  2142. "Atan(%f), expected %f, got %f",
  2143. -INFINITY, -SDL_PI_D / 2.0, result);
  2144. return TEST_COMPLETED;
  2145. }
  2146. /**
  2147. * Inputs: +/-0.0.
  2148. * Expected: Zero is returned as-is.
  2149. */
  2150. static int
  2151. atan_zeroCases(void *args)
  2152. {
  2153. double result;
  2154. result = SDL_atan(0.0);
  2155. SDLTest_AssertCheck(0.0 == result,
  2156. "Atan(%f), expected %f, got %f",
  2157. 0.0, 0.0, result);
  2158. result = SDL_atan(-0.0);
  2159. SDLTest_AssertCheck(-0.0 == result,
  2160. "Atan(%f), expected %f, got %f",
  2161. -0.0, -0.0, result);
  2162. return TEST_COMPLETED;
  2163. }
  2164. /**
  2165. * Input: NAN.
  2166. * Expected: NAN is returned.
  2167. */
  2168. static int
  2169. atan_nanCase(void *args)
  2170. {
  2171. const double result = SDL_atan(NAN);
  2172. SDLTest_AssertCheck(isnan(result),
  2173. "Atan(%f), expected %f, got %f",
  2174. NAN, NAN, result);
  2175. return TEST_COMPLETED;
  2176. }
  2177. /**
  2178. * Inputs: Values corresponding to angles between 9Pi/20 and -9Pi/20 with steps of Pi/20.
  2179. * Expected: The correct result is returned (+/-EPSILON).
  2180. */
  2181. static int
  2182. atan_precisionTest(void *args)
  2183. {
  2184. const d_to_d precision_cases[] = {
  2185. { 6.313751514675041, 1.4137166941 },
  2186. { 3.0776835371752527, 1.2566370614 },
  2187. { 1.9626105055051504, 1.0995574287 },
  2188. { 1.3763819204711734, 0.9424777960 },
  2189. { 1.0, 0.7853981633 },
  2190. { 0.7265425280053609, 0.6283185307 },
  2191. { 0.5095254494944288, 0.4712388980 },
  2192. { 0.3249196962329063, 0.3141592653 },
  2193. { 0.15838444032453627, 0.1570796326 },
  2194. { -0.15838444032453627, -0.1570796326 },
  2195. { -0.3249196962329063, -0.3141592653 },
  2196. { -0.5095254494944288, -0.4712388980 },
  2197. { -0.7265425280053609, -0.6283185307 },
  2198. { -1.0, -0.7853981633 },
  2199. { -1.3763819204711734, -0.9424777960 },
  2200. { -1.9626105055051504, -1.0995574287 },
  2201. { -3.0776835371752527, -1.2566370614 },
  2202. { -6.313751514675041, -1.4137166941 },
  2203. };
  2204. return helper_dtod_inexact("Atan", SDL_atan, precision_cases, SDL_arraysize(precision_cases));
  2205. }
  2206. /* SDL_atan2 tests functions */
  2207. /* Zero cases */
  2208. /**
  2209. * Inputs: (+/-0.0, +/-0.0).
  2210. * Expected:
  2211. * - Zero if the second argument is positive zero.
  2212. * - Pi if the second argument is negative zero.
  2213. * - The sign is inherited from the first argument.
  2214. */
  2215. static int
  2216. atan2_bothZeroCases(void *args)
  2217. {
  2218. const dd_to_d cases[] = {
  2219. { 0.0, 0.0, 0.0 },
  2220. { -0.0, 0.0, -0.0 },
  2221. { 0.0, -0.0, SDL_PI_D },
  2222. { -0.0, -0.0, -SDL_PI_D },
  2223. };
  2224. return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
  2225. }
  2226. /**
  2227. * Inputs: (+/-0.0, +/-1.0).
  2228. * Expected:
  2229. * - Zero if the second argument is positive.
  2230. * - Pi if the second argument is negative.
  2231. * - The sign is inherited from the first argument.
  2232. */
  2233. static int
  2234. atan2_yZeroCases(void *args)
  2235. {
  2236. const dd_to_d cases[] = {
  2237. { 0.0, 1.0, 0.0 },
  2238. { 0.0, -1.0, SDL_PI_D },
  2239. { -0.0, 1.0, -0.0 },
  2240. { -0.0, -1.0, -SDL_PI_D }
  2241. };
  2242. return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
  2243. }
  2244. /**
  2245. * Inputs: (+/-1.0, +/-0.0).
  2246. * Expected: Pi/2 with the sign of the first argument.
  2247. */
  2248. static int
  2249. atan2_xZeroCases(void *args)
  2250. {
  2251. const dd_to_d cases[] = {
  2252. { 1.0, 0.0, SDL_PI_D / 2.0 },
  2253. { -1.0, 0.0, -SDL_PI_D / 2.0 },
  2254. { 1.0, -0.0, SDL_PI_D / 2.0 },
  2255. { -1.0, -0.0, -SDL_PI_D / 2.0 }
  2256. };
  2257. return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
  2258. }
  2259. /* Infinity cases */
  2260. /**
  2261. * Inputs: (+/-Infinity, +/-Infinity).
  2262. * Expected:
  2263. * - (+int, +inf) -> Pi/4,
  2264. * - (+int, -inf) -> 3Pi/4,
  2265. * - (-int, +inf) -> -Pi/4,
  2266. * - (-int, -inf) -> Pi.
  2267. */
  2268. static int
  2269. atan2_bothInfCases(void *args)
  2270. {
  2271. double result;
  2272. result = SDL_atan2(INFINITY, INFINITY);
  2273. SDLTest_AssertCheck(SDL_PI_D / 4.0 == result,
  2274. "Atan2(%f,%f), expected %f, got %f",
  2275. INFINITY, INFINITY, SDL_PI_D / 4.0, result);
  2276. result = SDL_atan2(INFINITY, -INFINITY);
  2277. SDLTest_AssertCheck(3.0 * SDL_PI_D / 4.0 == result,
  2278. "Atan2(%f,%f), expected %f, got %f",
  2279. INFINITY, -INFINITY, 3.0 * SDL_PI_D / 4.0, result);
  2280. result = SDL_atan2(-INFINITY, INFINITY);
  2281. SDLTest_AssertCheck(-SDL_PI_D / 4.0 == result,
  2282. "Atan2(%f,%f), expected %f, got %f",
  2283. -INFINITY, INFINITY, -SDL_PI_D / 4.0, result);
  2284. result = SDL_atan2(-INFINITY, -INFINITY);
  2285. SDLTest_AssertCheck(-3.0 * SDL_PI_D / 4.0 == result,
  2286. "Atan2(%f,%f), expected %f, got %f",
  2287. -INFINITY, -INFINITY, -3.0 * SDL_PI_D / 4.0, result);
  2288. return TEST_COMPLETED;
  2289. }
  2290. /**
  2291. * Inputs: (+/-Infinity, +/-1.0).
  2292. * Expected: Pi/2 with the sign of the first argument.
  2293. */
  2294. static int
  2295. atan2_yInfCases(void *args)
  2296. {
  2297. double result;
  2298. result = SDL_atan2(INFINITY, 1.0);
  2299. SDLTest_AssertCheck(SDL_PI_D / 2.0 == result,
  2300. "Atan2(%f,%f), expected %f, got %f",
  2301. INFINITY, 1.0, SDL_PI_D / 2.0, result);
  2302. result = SDL_atan2(INFINITY, -1.0);
  2303. SDLTest_AssertCheck(SDL_PI_D / 2.0 == result,
  2304. "Atan2(%f,%f), expected %f, got %f",
  2305. INFINITY, -1.0, SDL_PI_D / 2.0, result);
  2306. result = SDL_atan2(-INFINITY, 1.0);
  2307. SDLTest_AssertCheck(-SDL_PI_D / 2.0 == result,
  2308. "Atan2(%f,%f), expected %f, got %f",
  2309. -INFINITY, 1.0, -SDL_PI_D / 2.0, result);
  2310. result = SDL_atan2(-INFINITY, -1.0);
  2311. SDLTest_AssertCheck(-SDL_PI_D / 2.0 == result,
  2312. "Atan2(%f,%f), expected %f, got %f",
  2313. -INFINITY, -1.0, -SDL_PI_D / 2.0, result);
  2314. return TEST_COMPLETED;
  2315. }
  2316. /**
  2317. * Inputs: (+/-1.0, +/-Infinity).
  2318. * Expected:
  2319. * - (+/-1.0, +inf) -> +/-0.0
  2320. * - (+/-1.0, -inf) -> +/-Pi.
  2321. */
  2322. static int
  2323. atan2_xInfCases(void *args)
  2324. {
  2325. double result;
  2326. result = SDL_atan2(1.0, INFINITY);
  2327. SDLTest_AssertCheck(0.0 == result,
  2328. "Atan2(%f,%f), expected %f, got %f",
  2329. 1.0, INFINITY, 0.0, result);
  2330. result = SDL_atan2(-1.0, INFINITY);
  2331. SDLTest_AssertCheck(-0.0 == result,
  2332. "Atan2(%f,%f), expected %f, got %f",
  2333. -1.0, INFINITY, -0.0, result);
  2334. result = SDL_atan2(1.0, -INFINITY);
  2335. SDLTest_AssertCheck(SDL_PI_D == result,
  2336. "Atan2(%f,%f), expected %f, got %f",
  2337. 1.0, -INFINITY, SDL_PI_D, result);
  2338. result = SDL_atan2(-1.0, -INFINITY);
  2339. SDLTest_AssertCheck(-SDL_PI_D == result,
  2340. "Atan2(%f,%f), expected %f, got %f",
  2341. -1.0, -INFINITY, -SDL_PI_D, result);
  2342. return TEST_COMPLETED;
  2343. }
  2344. /* Miscelanious cases */
  2345. /**
  2346. * Inputs: NAN as either or both of the arguments.
  2347. * Expected: NAN is returned.
  2348. */
  2349. static int
  2350. atan2_nanCases(void *args)
  2351. {
  2352. double result;
  2353. result = SDL_atan2(NAN, NAN);
  2354. SDLTest_AssertCheck(isnan(result),
  2355. "Atan2(%f,%f), expected %f, got %f",
  2356. NAN, NAN, NAN, result);
  2357. result = SDL_atan2(NAN, 1.0);
  2358. SDLTest_AssertCheck(isnan(result),
  2359. "Atan2(%f,%f), expected %f, got %f",
  2360. NAN, 1.0, NAN, result);
  2361. result = SDL_atan2(1.0, NAN);
  2362. SDLTest_AssertCheck(isnan(result),
  2363. "Atan2(%f,%f), expected %f, got %f",
  2364. 1.0, NAN, NAN, result);
  2365. return TEST_COMPLETED;
  2366. }
  2367. /**
  2368. * Inputs: (y, x) with x and y positive.
  2369. * Expected: Angle in the top right quadrant.
  2370. */
  2371. static int
  2372. atan2_topRightQuadrantTest(void *args)
  2373. {
  2374. const dd_to_d top_right_cases[] = {
  2375. { 1.0, 1.0, SDL_PI_D / 4.0 },
  2376. { SQRT3, 3.0, SDL_PI_D / 6.0 },
  2377. { SQRT3, 1.0, SDL_PI_D / 3.0 }
  2378. };
  2379. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_right_cases, SDL_arraysize(top_right_cases));
  2380. }
  2381. /**
  2382. * Inputs: (y, x) with x negative and y positive.
  2383. * Expected: Angle in the top left quadrant.
  2384. */
  2385. static int
  2386. atan2_topLeftQuadrantTest(void *args)
  2387. {
  2388. const dd_to_d top_left_cases[] = {
  2389. { 1.0, -1.0, 3.0 * SDL_PI_D / 4.0 },
  2390. { SQRT3, -3.0, 5.0 * SDL_PI_D / 6.0 },
  2391. { SQRT3, -1.0, 2.0 * SDL_PI_D / 3.0 }
  2392. };
  2393. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_left_cases, SDL_arraysize(top_left_cases));
  2394. }
  2395. /**
  2396. * Inputs: (y, x) with x positive and y negative.
  2397. * Expected: Angle in the bottom right quadrant.
  2398. */
  2399. static int
  2400. atan2_bottomRightQuadrantTest(void *args)
  2401. {
  2402. const dd_to_d bottom_right_cases[] = {
  2403. { -1.0, 1.0, -SDL_PI_D / 4 },
  2404. { -SQRT3, 3.0, -SDL_PI_D / 6.0 },
  2405. { -SQRT3, 1.0, -SDL_PI_D / 3.0 }
  2406. };
  2407. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_right_cases, SDL_arraysize(bottom_right_cases));
  2408. }
  2409. /**
  2410. * Inputs: (y, x) with x and y negative.
  2411. * Expected: Angle in the bottom left quadrant.
  2412. */
  2413. static int
  2414. atan2_bottomLeftQuadrantTest(void *args)
  2415. {
  2416. const dd_to_d bottom_left_cases[] = {
  2417. { -1.0, -1.0, -3.0 * SDL_PI_D / 4.0 },
  2418. { -SQRT3, -3.0, -5.0 * SDL_PI_D / 6.0 },
  2419. { -SQRT3, -1.0, -4.0 * SDL_PI_D / 6.0 }
  2420. };
  2421. return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_left_cases, SDL_arraysize(bottom_left_cases));
  2422. }
  2423. /* ================= Test References ================== */
  2424. /* SDL_floor test cases */
  2425. static const SDLTest_TestCaseReference floorTestInf = {
  2426. (SDLTest_TestCaseFp)floor_infCases, "floor_infCases",
  2427. "Checks positive and negative infinity", TEST_ENABLED
  2428. };
  2429. static const SDLTest_TestCaseReference floorTestZero = {
  2430. (SDLTest_TestCaseFp)floor_zeroCases, "floor_zeroCases",
  2431. "Checks positive and negative zero", TEST_ENABLED
  2432. };
  2433. static const SDLTest_TestCaseReference floorTestNan = {
  2434. (SDLTest_TestCaseFp)floor_nanCase, "floor_nanCase",
  2435. "Checks NAN", TEST_ENABLED
  2436. };
  2437. static const SDLTest_TestCaseReference floorTestRound = {
  2438. (SDLTest_TestCaseFp)floor_roundNumbersCases, "floor_roundNumberCases",
  2439. "Checks a set of integral values", TEST_ENABLED
  2440. };
  2441. static const SDLTest_TestCaseReference floorTestFraction = {
  2442. (SDLTest_TestCaseFp)floor_fractionCases, "floor_fractionCases",
  2443. "Checks a set of fractions", TEST_ENABLED
  2444. };
  2445. static const SDLTest_TestCaseReference floorTestRange = {
  2446. (SDLTest_TestCaseFp)floor_rangeTest, "floor_rangeTest",
  2447. "Checks a range of positive integer", TEST_ENABLED
  2448. };
  2449. /* SDL_ceil test cases */
  2450. static const SDLTest_TestCaseReference ceilTestInf = {
  2451. (SDLTest_TestCaseFp)ceil_infCases, "ceil_infCases",
  2452. "Checks positive and negative infinity", TEST_ENABLED
  2453. };
  2454. static const SDLTest_TestCaseReference ceilTestZero = {
  2455. (SDLTest_TestCaseFp)ceil_zeroCases, "ceil_zeroCases",
  2456. "Checks positive and negative zero", TEST_ENABLED
  2457. };
  2458. static const SDLTest_TestCaseReference ceilTestNan = {
  2459. (SDLTest_TestCaseFp)ceil_nanCase, "ceil_nanCase",
  2460. "Checks NAN", TEST_ENABLED
  2461. };
  2462. static const SDLTest_TestCaseReference ceilTestRound = {
  2463. (SDLTest_TestCaseFp)ceil_roundNumbersCases, "ceil_roundNumberCases",
  2464. "Checks a set of integral values", TEST_ENABLED
  2465. };
  2466. static const SDLTest_TestCaseReference ceilTestFraction = {
  2467. (SDLTest_TestCaseFp)ceil_fractionCases, "ceil_fractionCases",
  2468. "Checks a set of fractions", TEST_ENABLED
  2469. };
  2470. static const SDLTest_TestCaseReference ceilTestRange = {
  2471. (SDLTest_TestCaseFp)ceil_rangeTest, "ceil_rangeTest",
  2472. "Checks a range of positive integer", TEST_ENABLED
  2473. };
  2474. /* SDL_trunc test cases */
  2475. static const SDLTest_TestCaseReference truncTestInf = {
  2476. (SDLTest_TestCaseFp)trunc_infCases, "trunc_infCases",
  2477. "Checks positive and negative infinity", TEST_ENABLED
  2478. };
  2479. static const SDLTest_TestCaseReference truncTestZero = {
  2480. (SDLTest_TestCaseFp)trunc_zeroCases, "trunc_zeroCases",
  2481. "Checks positive and negative zero", TEST_ENABLED
  2482. };
  2483. static const SDLTest_TestCaseReference truncTestNan = {
  2484. (SDLTest_TestCaseFp)trunc_nanCase, "trunc_nanCase",
  2485. "Checks NAN", TEST_ENABLED
  2486. };
  2487. static const SDLTest_TestCaseReference truncTestRound = {
  2488. (SDLTest_TestCaseFp)trunc_roundNumbersCases, "trunc_roundNumberCases",
  2489. "Checks a set of integral values", TEST_ENABLED
  2490. };
  2491. static const SDLTest_TestCaseReference truncTestFraction = {
  2492. (SDLTest_TestCaseFp)trunc_fractionCases, "trunc_fractionCases",
  2493. "Checks a set of fractions", TEST_ENABLED
  2494. };
  2495. static const SDLTest_TestCaseReference truncTestRange = {
  2496. (SDLTest_TestCaseFp)trunc_rangeTest, "trunc_rangeTest",
  2497. "Checks a range of positive integer", TEST_ENABLED
  2498. };
  2499. /* SDL_round test cases */
  2500. static const SDLTest_TestCaseReference roundTestInf = {
  2501. (SDLTest_TestCaseFp)round_infCases, "round_infCases",
  2502. "Checks positive and negative infinity", TEST_ENABLED
  2503. };
  2504. static const SDLTest_TestCaseReference roundTestZero = {
  2505. (SDLTest_TestCaseFp)round_zeroCases, "round_zeroCases",
  2506. "Checks positive and negative zero", TEST_ENABLED
  2507. };
  2508. static const SDLTest_TestCaseReference roundTestNan = {
  2509. (SDLTest_TestCaseFp)round_nanCase, "round_nanCase",
  2510. "Checks NAN", TEST_ENABLED
  2511. };
  2512. static const SDLTest_TestCaseReference roundTestRound = {
  2513. (SDLTest_TestCaseFp)round_roundNumbersCases, "round_roundNumberCases",
  2514. "Checks a set of integral values", TEST_ENABLED
  2515. };
  2516. static const SDLTest_TestCaseReference roundTestFraction = {
  2517. (SDLTest_TestCaseFp)round_fractionCases, "round_fractionCases",
  2518. "Checks a set of fractions", TEST_ENABLED
  2519. };
  2520. static const SDLTest_TestCaseReference roundTestRange = {
  2521. (SDLTest_TestCaseFp)round_rangeTest, "round_rangeTest",
  2522. "Checks a range of positive integer", TEST_ENABLED
  2523. };
  2524. /* SDL_fabs test cases */
  2525. static const SDLTest_TestCaseReference fabsTestInf = {
  2526. (SDLTest_TestCaseFp)fabs_infCases, "fabs_infCases",
  2527. "Checks positive and negative infinity", TEST_ENABLED
  2528. };
  2529. static const SDLTest_TestCaseReference fabsTestZero = {
  2530. (SDLTest_TestCaseFp)fabs_zeroCases, "fabs_zeroCases",
  2531. "Checks positive and negative zero", TEST_ENABLED
  2532. };
  2533. static const SDLTest_TestCaseReference fabsTestNan = {
  2534. (SDLTest_TestCaseFp)fabs_nanCase, "fabs_nanCase",
  2535. "Checks NAN", TEST_ENABLED
  2536. };
  2537. static const SDLTest_TestCaseReference fabsTestRange = {
  2538. (SDLTest_TestCaseFp)fabs_rangeTest, "fabs_rangeTest",
  2539. "Checks a range of positive integer", TEST_ENABLED
  2540. };
  2541. /* SDL_copysign test cases */
  2542. static const SDLTest_TestCaseReference copysignTestInf = {
  2543. (SDLTest_TestCaseFp)copysign_infCases, "copysign_infCases",
  2544. "Checks positive and negative infinity", TEST_ENABLED
  2545. };
  2546. static const SDLTest_TestCaseReference copysignTestZero = {
  2547. (SDLTest_TestCaseFp)copysign_zeroCases, "copysign_zeroCases",
  2548. "Checks positive and negative zero", TEST_ENABLED
  2549. };
  2550. static const SDLTest_TestCaseReference copysignTestNan = {
  2551. (SDLTest_TestCaseFp)copysign_nanCases, "copysign_nanCases",
  2552. "Checks NANs", TEST_ENABLED
  2553. };
  2554. static const SDLTest_TestCaseReference copysignTestRange = {
  2555. (SDLTest_TestCaseFp)copysign_rangeTest, "copysign_rangeTest",
  2556. "Checks a range of positive integer", TEST_ENABLED
  2557. };
  2558. /* SDL_fmod test cases */
  2559. static const SDLTest_TestCaseReference fmodTestDivOfInf = {
  2560. (SDLTest_TestCaseFp)fmod_divOfInfCases, "fmod_divOfInfCases",
  2561. "Checks division of positive and negative infinity", TEST_ENABLED
  2562. };
  2563. static const SDLTest_TestCaseReference fmodTestDivByInf = {
  2564. (SDLTest_TestCaseFp)fmod_divByInfCases, "fmod_divByInfCases",
  2565. "Checks division by positive and negative infinity", TEST_ENABLED
  2566. };
  2567. static const SDLTest_TestCaseReference fmodTestDivOfZero = {
  2568. (SDLTest_TestCaseFp)fmod_divOfZeroCases, "fmod_divOfZeroCases",
  2569. "Checks division of positive and negative zero", TEST_ENABLED
  2570. };
  2571. static const SDLTest_TestCaseReference fmodTestDivByZero = {
  2572. (SDLTest_TestCaseFp)fmod_divByZeroCases, "fmod_divByZeroCases",
  2573. "Checks division by positive and negative zero", TEST_ENABLED
  2574. };
  2575. static const SDLTest_TestCaseReference fmodTestNan = {
  2576. (SDLTest_TestCaseFp)fmod_nanCases, "fmod_nanCases",
  2577. "Checks NANs", TEST_ENABLED
  2578. };
  2579. static const SDLTest_TestCaseReference fmodTestRegular = {
  2580. (SDLTest_TestCaseFp)fmod_regularCases, "fmod_regularCases",
  2581. "Checks a set of regular values", TEST_ENABLED
  2582. };
  2583. static const SDLTest_TestCaseReference fmodTestRange = {
  2584. (SDLTest_TestCaseFp)fmod_rangeTest, "fmod_rangeTest",
  2585. "Checks a range of positive integer", TEST_ENABLED
  2586. };
  2587. /* SDL_exp test cases */
  2588. static const SDLTest_TestCaseReference expTestInf = {
  2589. (SDLTest_TestCaseFp)exp_infCases, "exp_infCases",
  2590. "Checks positive and negative infinity", TEST_ENABLED
  2591. };
  2592. static const SDLTest_TestCaseReference expTestZero = {
  2593. (SDLTest_TestCaseFp)exp_zeroCases, "exp_zeroCases",
  2594. "Checks for positive and negative zero", TEST_ENABLED
  2595. };
  2596. static const SDLTest_TestCaseReference expTestOverflow = {
  2597. (SDLTest_TestCaseFp)exp_overflowCase, "exp_overflowCase",
  2598. "Checks for overflow", TEST_ENABLED
  2599. };
  2600. static const SDLTest_TestCaseReference expTestBase = {
  2601. (SDLTest_TestCaseFp)exp_baseCase, "exp_baseCase",
  2602. "Checks the base case", TEST_ENABLED
  2603. };
  2604. static const SDLTest_TestCaseReference expTestRegular = {
  2605. (SDLTest_TestCaseFp)exp_regularCases, "exp_regularCases",
  2606. "Checks a set of regular values", TEST_ENABLED
  2607. };
  2608. /* SDL_log test cases */
  2609. static const SDLTest_TestCaseReference logTestLimit = {
  2610. (SDLTest_TestCaseFp)log_limitCases, "log_limitCases",
  2611. "Checks the domain limits", TEST_ENABLED
  2612. };
  2613. static const SDLTest_TestCaseReference logTestNan = {
  2614. (SDLTest_TestCaseFp)log_nanCases, "log_nanCases",
  2615. "Checks NAN and negative values", TEST_ENABLED
  2616. };
  2617. static const SDLTest_TestCaseReference logTestBase = {
  2618. (SDLTest_TestCaseFp)log_baseCases, "log_baseCases",
  2619. "Checks the base cases", TEST_ENABLED
  2620. };
  2621. static const SDLTest_TestCaseReference logTestRegular = {
  2622. (SDLTest_TestCaseFp)log_regularCases, "log_regularCases",
  2623. "Checks a set of regular values", TEST_ENABLED
  2624. };
  2625. /* SDL_log10 test cases */
  2626. static const SDLTest_TestCaseReference log10TestLimit = {
  2627. (SDLTest_TestCaseFp)log10_limitCases, "log10_limitCases",
  2628. "Checks the domain limits", TEST_ENABLED
  2629. };
  2630. static const SDLTest_TestCaseReference log10TestNan = {
  2631. (SDLTest_TestCaseFp)log10_nanCases, "log10_nanCases",
  2632. "Checks NAN and negative values", TEST_ENABLED
  2633. };
  2634. static const SDLTest_TestCaseReference log10TestBase = {
  2635. (SDLTest_TestCaseFp)log10_baseCases, "log10_baseCases",
  2636. "Checks the base cases", TEST_ENABLED
  2637. };
  2638. static const SDLTest_TestCaseReference log10TestRegular = {
  2639. (SDLTest_TestCaseFp)log10_regularCases, "log10_regularCases",
  2640. "Checks a set of regular values", TEST_ENABLED
  2641. };
  2642. /* SDL_modf test cases */
  2643. static const SDLTest_TestCaseReference modfTestBase = {
  2644. (SDLTest_TestCaseFp)modf_baseCases, "modf_baseCases",
  2645. "Checks the base cases", TEST_ENABLED
  2646. };
  2647. /* SDL_pow test cases */
  2648. static const SDLTest_TestCaseReference powTestExpInf1 = {
  2649. (SDLTest_TestCaseFp)pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
  2650. "Checks for pow(-1, +/-inf)", TEST_ENABLED
  2651. };
  2652. static const SDLTest_TestCaseReference powTestExpInf2 = {
  2653. (SDLTest_TestCaseFp)pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
  2654. "Checks for pow(+/-0, -inf)", TEST_ENABLED
  2655. };
  2656. static const SDLTest_TestCaseReference powTestExpInf3 = {
  2657. (SDLTest_TestCaseFp)pow_expInfCases, "pow_expInfCases",
  2658. "Checks for pow(x, +/-inf)", TEST_ENABLED
  2659. };
  2660. static const SDLTest_TestCaseReference powTestBaseInf1 = {
  2661. (SDLTest_TestCaseFp)pow_basePInfCases, "pow_basePInfCases",
  2662. "Checks for pow(inf, x)", TEST_ENABLED
  2663. };
  2664. static const SDLTest_TestCaseReference powTestBaseInf2 = {
  2665. (SDLTest_TestCaseFp)pow_baseNInfCases, "pow_baseNInfCases",
  2666. "Checks for pow(-inf, x)", TEST_ENABLED
  2667. };
  2668. static const SDLTest_TestCaseReference powTestNan1 = {
  2669. (SDLTest_TestCaseFp)pow_badOperationCase, "pow_badOperationCase",
  2670. "Checks for negative finite base and non-integer finite exponent", TEST_ENABLED
  2671. };
  2672. static const SDLTest_TestCaseReference powTestNan2 = {
  2673. (SDLTest_TestCaseFp)pow_base1ExpNanCase, "pow_base1ExpNanCase",
  2674. "Checks for pow(1.0, NAN)", TEST_ENABLED
  2675. };
  2676. static const SDLTest_TestCaseReference powTestNan3 = {
  2677. (SDLTest_TestCaseFp)pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
  2678. "Checks for pow(NAN, +/-0)", TEST_ENABLED
  2679. };
  2680. static const SDLTest_TestCaseReference powTestNan4 = {
  2681. (SDLTest_TestCaseFp)pow_nanArgsCases, "pow_nanArgsCases",
  2682. "Checks for pow(x, y) with either x or y being NAN", TEST_ENABLED
  2683. };
  2684. static const SDLTest_TestCaseReference powTestZero1 = {
  2685. (SDLTest_TestCaseFp)pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
  2686. "Checks for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
  2687. };
  2688. static const SDLTest_TestCaseReference powTestZero2 = {
  2689. (SDLTest_TestCaseFp)pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
  2690. "Checks for pow(0.0, y), with y an odd integer.", TEST_ENABLED
  2691. };
  2692. static const SDLTest_TestCaseReference powTestZero3 = {
  2693. (SDLTest_TestCaseFp)pow_baseNZeroCases, "pow_baseNZeroCases",
  2694. "Checks for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2695. };
  2696. static const SDLTest_TestCaseReference powTestZero4 = {
  2697. (SDLTest_TestCaseFp)pow_basePZeroCases, "pow_basePZeroCases",
  2698. "Checks for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
  2699. };
  2700. static const SDLTest_TestCaseReference powTestRegular = {
  2701. (SDLTest_TestCaseFp)pow_regularCases, "pow_regularCases",
  2702. "Checks a set of regular values", TEST_ENABLED
  2703. };
  2704. static const SDLTest_TestCaseReference powTestPowOf2 = {
  2705. (SDLTest_TestCaseFp)pow_powerOfTwo, "pow_powerOfTwo",
  2706. "Checks the powers of two from 1 to 8", TEST_ENABLED
  2707. };
  2708. static const SDLTest_TestCaseReference powTestRange = {
  2709. (SDLTest_TestCaseFp)pow_rangeTest, "pow_rangeTest",
  2710. "Checks a range of positive integer to the power of 0", TEST_ENABLED
  2711. };
  2712. /* SDL_sqrt test cases */
  2713. static const SDLTest_TestCaseReference sqrtTestInf = {
  2714. (SDLTest_TestCaseFp)sqrt_infCase, "sqrt_infCase",
  2715. "Checks positive infinity", TEST_ENABLED
  2716. };
  2717. static const SDLTest_TestCaseReference sqrtTestNan = {
  2718. (SDLTest_TestCaseFp)sqrt_nanCase, "sqrt_nanCase",
  2719. "Checks NAN", TEST_ENABLED
  2720. };
  2721. static const SDLTest_TestCaseReference sqrtTestDomain = {
  2722. (SDLTest_TestCaseFp)sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
  2723. "Checks for values out of the domain", TEST_ENABLED
  2724. };
  2725. static const SDLTest_TestCaseReference sqrtTestBase = {
  2726. (SDLTest_TestCaseFp)sqrt_baseCases, "sqrt_baseCases",
  2727. "Checks the base cases", TEST_ENABLED
  2728. };
  2729. static const SDLTest_TestCaseReference sqrtTestRegular = {
  2730. (SDLTest_TestCaseFp)sqrt_regularCases, "sqrt_regularCases",
  2731. "Checks a set of regular values", TEST_ENABLED
  2732. };
  2733. /* SDL_scalbn test cases */
  2734. static const SDLTest_TestCaseReference scalbnTestInf = {
  2735. (SDLTest_TestCaseFp)scalbn_infCases, "scalbn_infCases",
  2736. "Checks positive and negative infinity arg", TEST_ENABLED
  2737. };
  2738. static const SDLTest_TestCaseReference scalbnTestBaseZero = {
  2739. (SDLTest_TestCaseFp)scalbn_baseZeroCases, "scalbn_baseZeroCases",
  2740. "Checks for positive and negative zero arg", TEST_ENABLED
  2741. };
  2742. static const SDLTest_TestCaseReference scalbnTestExpZero = {
  2743. (SDLTest_TestCaseFp)scalbn_expZeroCase, "scalbn_expZeroCase",
  2744. "Checks for zero exp", TEST_ENABLED
  2745. };
  2746. static const SDLTest_TestCaseReference scalbnTestNan = {
  2747. (SDLTest_TestCaseFp)scalbn_nanCase, "scalbn_nanCase",
  2748. "Checks NAN", TEST_ENABLED
  2749. };
  2750. static const SDLTest_TestCaseReference scalbnTestRegular = {
  2751. (SDLTest_TestCaseFp)scalbn_regularCases, "scalbn_regularCases",
  2752. "Checks a set of regular cases", TEST_ENABLED
  2753. };
  2754. /* SDL_cos test cases */
  2755. static const SDLTest_TestCaseReference cosTestInf = {
  2756. (SDLTest_TestCaseFp)cos_infCases, "cos_infCases",
  2757. "Checks for positive and negative infinity", TEST_ENABLED
  2758. };
  2759. static const SDLTest_TestCaseReference cosTestNan = {
  2760. (SDLTest_TestCaseFp)cos_nanCase, "cos_nanCase",
  2761. "Checks NAN", TEST_ENABLED
  2762. };
  2763. static const SDLTest_TestCaseReference cosTestRegular = {
  2764. (SDLTest_TestCaseFp)cos_regularCases, "cos_regularCases",
  2765. "Checks a set of regular cases", TEST_ENABLED
  2766. };
  2767. static const SDLTest_TestCaseReference cosTestPrecision = {
  2768. (SDLTest_TestCaseFp)cos_precisionTest, "cos_precisionTest",
  2769. "Checks cosine precision", TEST_ENABLED
  2770. };
  2771. static const SDLTest_TestCaseReference cosTestRange = {
  2772. (SDLTest_TestCaseFp)cos_rangeTest, "cos_rangeTest",
  2773. "Checks a range of positive integer", TEST_ENABLED
  2774. };
  2775. /* SDL_sin test cases */
  2776. static const SDLTest_TestCaseReference sinTestInf = {
  2777. (SDLTest_TestCaseFp)sin_infCases, "sin_infCases",
  2778. "Checks for positive and negative infinity", TEST_ENABLED
  2779. };
  2780. static const SDLTest_TestCaseReference sinTestNan = {
  2781. (SDLTest_TestCaseFp)sin_nanCase, "sin_nanCase",
  2782. "Checks NAN", TEST_ENABLED
  2783. };
  2784. static const SDLTest_TestCaseReference sinTestRegular = {
  2785. (SDLTest_TestCaseFp)sin_regularCases, "sin_regularCases",
  2786. "Checks a set of regular cases", TEST_ENABLED
  2787. };
  2788. static const SDLTest_TestCaseReference sinTestPrecision = {
  2789. (SDLTest_TestCaseFp)sin_precisionTest, "sin_precisionTest",
  2790. "Checks sine precision", TEST_ENABLED
  2791. };
  2792. static const SDLTest_TestCaseReference sinTestRange = {
  2793. (SDLTest_TestCaseFp)sin_rangeTest, "sin_rangeTest",
  2794. "Checks a range of positive integer", TEST_ENABLED
  2795. };
  2796. /* SDL_tan test cases */
  2797. static const SDLTest_TestCaseReference tanTestInf = {
  2798. (SDLTest_TestCaseFp)tan_infCases, "tan_infCases",
  2799. "Checks for positive and negative infinity", TEST_ENABLED
  2800. };
  2801. static const SDLTest_TestCaseReference tanTestNan = {
  2802. (SDLTest_TestCaseFp)tan_nanCase, "tan_nanCase",
  2803. "Checks NAN", TEST_ENABLED
  2804. };
  2805. static const SDLTest_TestCaseReference tanTestZero = {
  2806. (SDLTest_TestCaseFp)tan_zeroCases, "tan_zeroCases",
  2807. "Checks a set of regular cases", TEST_ENABLED
  2808. };
  2809. static const SDLTest_TestCaseReference tanTestPrecision = {
  2810. (SDLTest_TestCaseFp)tan_precisionTest, "tan_precisionTest",
  2811. "Checks tangent precision", TEST_ENABLED
  2812. };
  2813. /* SDL_acos test cases */
  2814. static const SDLTest_TestCaseReference acosTestLimit = {
  2815. (SDLTest_TestCaseFp)acos_limitCases, "acos_limitCases",
  2816. "Checks the edge of the domain (+/-1)", TEST_ENABLED
  2817. };
  2818. static const SDLTest_TestCaseReference acosTestOutOfDomain = {
  2819. (SDLTest_TestCaseFp)acos_outOfDomainCases, "acos_outOfDomainCases",
  2820. "Checks values outside the domain", TEST_ENABLED
  2821. };
  2822. static const SDLTest_TestCaseReference acosTestNan = {
  2823. (SDLTest_TestCaseFp)acos_nanCase, "acos_nanCase",
  2824. "Checks NAN", TEST_ENABLED
  2825. };
  2826. static const SDLTest_TestCaseReference acosTestPrecision = {
  2827. (SDLTest_TestCaseFp)acos_precisionTest, "acos_precisionTest",
  2828. "Checks acos precision", TEST_ENABLED
  2829. };
  2830. /* SDL_asin test cases */
  2831. static const SDLTest_TestCaseReference asinTestLimit = {
  2832. (SDLTest_TestCaseFp)asin_limitCases, "asin_limitCases",
  2833. "Checks the edge of the domain (+/-1)", TEST_ENABLED
  2834. };
  2835. static const SDLTest_TestCaseReference asinTestOutOfDomain = {
  2836. (SDLTest_TestCaseFp)asin_outOfDomainCases, "asin_outOfDomainCases",
  2837. "Checks values outside the domain", TEST_ENABLED
  2838. };
  2839. static const SDLTest_TestCaseReference asinTestNan = {
  2840. (SDLTest_TestCaseFp)asin_nanCase, "asin_nanCase",
  2841. "Checks NAN", TEST_ENABLED
  2842. };
  2843. static const SDLTest_TestCaseReference asinTestPrecision = {
  2844. (SDLTest_TestCaseFp)asin_precisionTest, "asin_precisionTest",
  2845. "Checks asin precision", TEST_ENABLED
  2846. };
  2847. /* SDL_atan test cases */
  2848. static const SDLTest_TestCaseReference atanTestLimit = {
  2849. (SDLTest_TestCaseFp)atan_limitCases, "atan_limitCases",
  2850. "Checks the edge of the domain (+/-Infinity)", TEST_ENABLED
  2851. };
  2852. static const SDLTest_TestCaseReference atanTestZero = {
  2853. (SDLTest_TestCaseFp)atan_zeroCases, "atan_zeroCases",
  2854. "Checks for positive and negative zero", TEST_ENABLED
  2855. };
  2856. static const SDLTest_TestCaseReference atanTestNan = {
  2857. (SDLTest_TestCaseFp)atan_nanCase, "atan_nanCase",
  2858. "Checks NAN", TEST_ENABLED
  2859. };
  2860. static const SDLTest_TestCaseReference atanTestPrecision = {
  2861. (SDLTest_TestCaseFp)atan_precisionTest, "atan_precisionTest",
  2862. "Checks atan precision", TEST_ENABLED
  2863. };
  2864. /* SDL_atan2 test cases */
  2865. static const SDLTest_TestCaseReference atan2TestZero1 = {
  2866. (SDLTest_TestCaseFp)atan2_bothZeroCases, "atan2_bothZeroCases",
  2867. "Checks for both arguments being zero", TEST_ENABLED
  2868. };
  2869. static const SDLTest_TestCaseReference atan2TestZero2 = {
  2870. (SDLTest_TestCaseFp)atan2_yZeroCases, "atan2_yZeroCases",
  2871. "Checks for y=0", TEST_ENABLED
  2872. };
  2873. static const SDLTest_TestCaseReference atan2TestZero3 = {
  2874. (SDLTest_TestCaseFp)atan2_xZeroCases, "atan2_xZeroCases",
  2875. "Checks for x=0", TEST_ENABLED
  2876. };
  2877. static const SDLTest_TestCaseReference atan2TestInf1 = {
  2878. (SDLTest_TestCaseFp)atan2_bothInfCases, "atan2_bothInfCases",
  2879. "Checks for both arguments being infinity", TEST_ENABLED
  2880. };
  2881. static const SDLTest_TestCaseReference atan2TestInf2 = {
  2882. (SDLTest_TestCaseFp)atan2_yInfCases, "atan2_yInfCases",
  2883. "Checks for y=0", TEST_ENABLED
  2884. };
  2885. static const SDLTest_TestCaseReference atan2TestInf3 = {
  2886. (SDLTest_TestCaseFp)atan2_xInfCases, "atan2_xInfCases",
  2887. "Checks for x=0", TEST_ENABLED
  2888. };
  2889. static const SDLTest_TestCaseReference atan2TestNan = {
  2890. (SDLTest_TestCaseFp)atan2_nanCases, "atan2_nanCases",
  2891. "Checks NANs", TEST_ENABLED
  2892. };
  2893. static const SDLTest_TestCaseReference atan2TestQuadrantTopRight = {
  2894. (SDLTest_TestCaseFp)atan2_topRightQuadrantTest, "atan2_topRightQuadrantTest",
  2895. "Checks values in the top right quadrant", TEST_ENABLED
  2896. };
  2897. static const SDLTest_TestCaseReference atan2TestQuadrantTopLeft = {
  2898. (SDLTest_TestCaseFp)atan2_topLeftQuadrantTest, "atan2_topLeftQuadrantTest",
  2899. "Checks values in the top left quadrant", TEST_ENABLED
  2900. };
  2901. static const SDLTest_TestCaseReference atan2TestQuadrantBottomRight = {
  2902. (SDLTest_TestCaseFp)atan2_bottomRightQuadrantTest, "atan2_bottomRightQuadrantTest",
  2903. "Checks values in the bottom right quadrant", TEST_ENABLED
  2904. };
  2905. static const SDLTest_TestCaseReference atan2TestQuadrantBottomLeft = {
  2906. (SDLTest_TestCaseFp)atan2_bottomLeftQuadrantTest, "atan2_bottomLeftQuadrantTest",
  2907. "Checks values in the bottom left quadrant", TEST_ENABLED
  2908. };
  2909. static const SDLTest_TestCaseReference *mathTests[] = {
  2910. &floorTestInf, &floorTestZero, &floorTestNan,
  2911. &floorTestRound, &floorTestFraction, &floorTestRange,
  2912. &ceilTestInf, &ceilTestZero, &ceilTestNan,
  2913. &ceilTestRound, &ceilTestFraction, &ceilTestRange,
  2914. &truncTestInf, &truncTestZero, &truncTestNan,
  2915. &truncTestRound, &truncTestFraction, &truncTestRange,
  2916. &roundTestInf, &roundTestZero, &roundTestNan,
  2917. &roundTestRound, &roundTestFraction, &roundTestRange,
  2918. &fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
  2919. &copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
  2920. &fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
  2921. &fmodTestNan, &fmodTestRegular, &fmodTestRange,
  2922. &expTestInf, &expTestZero, &expTestOverflow,
  2923. &expTestBase, &expTestRegular,
  2924. &logTestLimit, &logTestNan,
  2925. &logTestBase, &logTestRegular,
  2926. &log10TestLimit, &log10TestNan,
  2927. &log10TestBase, &log10TestRegular,
  2928. &modfTestBase,
  2929. &powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
  2930. &powTestBaseInf1, &powTestBaseInf2,
  2931. &powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
  2932. &powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
  2933. &powTestRegular, &powTestPowOf2, &powTestRange,
  2934. &sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
  2935. &sqrtTestBase, &sqrtTestRegular,
  2936. &scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
  2937. &scalbnTestNan, &scalbnTestRegular,
  2938. &cosTestInf, &cosTestNan, &cosTestRegular,
  2939. &cosTestPrecision, &cosTestRange,
  2940. &sinTestInf, &sinTestNan, &sinTestRegular,
  2941. &sinTestPrecision, &sinTestRange,
  2942. &tanTestInf, &tanTestNan, &tanTestZero, &tanTestPrecision,
  2943. &acosTestLimit, &acosTestOutOfDomain, &acosTestNan, &acosTestPrecision,
  2944. &asinTestLimit, &asinTestOutOfDomain, &asinTestNan, &asinTestPrecision,
  2945. &atanTestLimit, &atanTestZero, &atanTestNan, &atanTestPrecision,
  2946. &atan2TestZero1, &atan2TestZero2, &atan2TestZero3,
  2947. &atan2TestInf1, &atan2TestInf2, &atan2TestInf3,
  2948. &atan2TestNan, &atan2TestQuadrantTopRight, &atan2TestQuadrantTopLeft,
  2949. &atan2TestQuadrantBottomRight, &atan2TestQuadrantBottomLeft,
  2950. NULL
  2951. };
  2952. SDLTest_TestSuiteReference mathTestSuite = {
  2953. "Math",
  2954. NULL,
  2955. mathTests,
  2956. NULL
  2957. };