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