testautomation_math.c 97 KB

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