1 /* Test corner case for IEEE expm1
2 *
3 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/expm1.html
4 *
5 */
6 #ifndef __USE_MINGW_ANSI_STDIO
7 #define __USE_MINGW_ANSI_STDIO 1
8 #endif
9 #include <math.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #define STR_VALUE(arg) #arg
14 #define MINUS_ZERO -0.
15 #define N_TESTS 5
16
17 int
main()18 main ()
19 {
20 int res = 0;
21
22 #define TEST(func, dtype, fmt) do { \
23 int i; \
24 char fmt_str[20]; \
25 dtype input, output, exp; \
26 dtype inp_out[N_TESTS][2] = { \
27 {0, 0}, \
28 {NAN, NAN}, \
29 {MINUS_ZERO, MINUS_ZERO}, \
30 {-INFINITY, -1}, \
31 {INFINITY, INFINITY}, \
32 }; \
33 sprintf(fmt_str, "%s(%s) = %s\n", STR_VALUE(func), fmt, fmt); \
34 for (i=0; i<N_TESTS; i++) { \
35 input = inp_out[i][0]; \
36 exp = inp_out[i][1]; \
37 output = func(input); \
38 printf(fmt_str, input, output); \
39 if ((output != exp && !isnan(exp)) \
40 || (isnan(output) ^ isnan(exp))) \
41 { \
42 res |= 1; \
43 printf("which is bogus!\n"); \
44 } \
45 } \
46 } while (0)
47
48 TEST (expm1, double, "%f");
49 TEST (expm1f, float, "%f");
50 TEST (expm1l, long double, "%lf");
51 return res;
52 }
53