1
0

testautomation_math.c 97 KB

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