testautomation_math.c 99 KB

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