Update.
[glibc.git] / math / test-math.c
blobedd82a3d1e53d39ddc659b7cfdfaf72ab165d581
1 #include <stdio.h>
2 #include <math.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <string.h>
7 void print_trig_stuff __P ((void));
9 int
10 main (int argc, char *argv[])
12 const char str[] = "123.456";
13 double x,h,li,lr,a,lrr;
15 if (signbit (argc < 1 ? -0.0 : 0.0))
16 /* I don't make this an error for now. --drepper */
17 fputs ("\n*** Your compiler has a bug. Consider upgrading\n\n", stderr);
19 x = atof (str);
21 printf ("%g %g\n", x, pow (10.0, 3.0));
23 x = sinh(2.0);
25 printf("sinh(2.0) = %g\n", x);
27 x = sinh(3.0);
29 printf("sinh(3.0) = %g\n", x);
31 h = hypot(2.0,3.0);
33 printf("h=%g\n", h);
35 a = atan2(3.0, 2.0);
37 printf("atan2(3,2) = %g\n", a);
39 lr = pow(h,4.0);
41 printf("pow(%g,4.0) = %g\n", h, lr);
43 lrr = lr;
45 li = 4.0 * a;
47 lr = lr / exp(a*5.0);
49 printf("%g / exp(%g * 5) = %g\n", lrr, a, lr);
51 lrr = li;
53 li += 5.0 * log(h);
55 printf("%g + 5*log(%g) = %g\n", lrr, h, li);
57 printf("cos(%g) = %g, sin(%g) = %g\n", li, cos(li), li, sin(li));
59 x = drem(10.3435,6.2831852);
61 printf("drem(10.3435,6.2831852) = %g\n", x);
63 x = drem(-10.3435,6.2831852);
65 printf("drem(-10.3435,6.2831852) = %g\n", x);
67 x = drem(-10.3435,-6.2831852);
69 printf("drem(-10.3435,-6.2831852) = %g\n", x);
71 x = drem(10.3435,-6.2831852);
73 printf("drem(10.3435,-6.2831852) = %g\n", x);
76 printf("x%8.6gx\n", .5);
77 printf("x%-8.6gx\n", .5);
78 printf("x%6.6gx\n", .5);
81 double x = atof ("-1e-17-");
82 printf ("%g %c= %g %s!\n",
84 x == -1e-17 ? '=' : '!',
85 -1e-17,
86 x == -1e-17 ? "Worked" : "Failed");
89 print_trig_stuff ();
91 return 0;
95 const double RAD[5] = { 0, M_PI/2, M_PI, (3*M_PI)/2, 2*M_PI };
97 #define PRINT_IT_1_ARG(_func, _arg, _value) \
98 (_value) = (_func) ((_arg)); \
99 if (errno) { \
100 errno = 0; \
101 printf ("%s = ERROR %s\n", #_func, strerror (errno)); \
102 } else \
103 printf ("%s(%g) = %g\n", #_func, _arg, (_value)); \
105 #define PRINT_IT_2_ARG(_func, _arg1, _arg2, _value) \
106 (_value) = (_func) ((_arg1),(_arg2)); \
107 if (errno) { \
108 errno = 0; \
109 printf ("%s = ERROR %s\n", #_func, strerror (errno)); \
110 } else \
111 printf ("%s(%g, %g) = %g\n", #_func, _arg1, _arg2, (_value)); \
113 void
114 print_trig_stuff(void)
116 double value, arg1, arg2;
117 int i;
119 puts ("\n\nMath Test");
121 errno = 0; /* automatically reset on error condition */
122 for (i=0; i<4; i++)
124 PRINT_IT_1_ARG (sin, RAD[i], value);
125 PRINT_IT_1_ARG (cos, RAD[i], value);
126 PRINT_IT_1_ARG (tan, RAD[i], value);
127 PRINT_IT_1_ARG (asin, RAD[i], value);
128 PRINT_IT_1_ARG (acos, RAD[i], value);
129 PRINT_IT_1_ARG (atan, RAD[i], value);
130 PRINT_IT_2_ARG (atan2, RAD[i], -RAD[i % 4], value);
133 arg1 = 16;
134 arg2 = 3;
135 PRINT_IT_1_ARG (exp, arg1, value);
136 PRINT_IT_1_ARG (log, arg1, value);
137 PRINT_IT_1_ARG (log10, arg1, value);
138 PRINT_IT_2_ARG (pow, arg1, arg2, value);
139 PRINT_IT_1_ARG (sqrt, arg1, value);
140 PRINT_IT_1_ARG (cbrt, arg1, value);
141 PRINT_IT_2_ARG (hypot, arg1, arg2, value);
142 PRINT_IT_1_ARG (expm1, arg1, value);
143 PRINT_IT_1_ARG (log1p, arg1, value);
144 PRINT_IT_1_ARG (sinh, arg1, value);
145 PRINT_IT_1_ARG (cosh, arg1, value);
146 PRINT_IT_1_ARG (tanh, arg1, value);
147 PRINT_IT_1_ARG (asinh, arg1, value);
148 PRINT_IT_1_ARG (acosh, arg1, value);
149 PRINT_IT_1_ARG (atanh, arg1, value);