Fri Dec 8 13:04:51 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[glibc.git] / math / test-math.c
bloba82daed4e48d62c371398d0102be4cfe5a30193b
1 #include <ansidecl.h>
2 #include <stdio.h>
3 #include <math.h>
4 #include <stdlib.h>
6 void print_trig_stuff __P ((void));
8 int
9 DEFUN_VOID(main)
11 CONST char str[] = "123.456";
12 double x,h,li,lr,a,lrr;
14 x = atof (str);
16 printf ("%g %g\n", x, pow (10.0, 3.0));
18 x = sinh(2.0);
20 printf("sinh(2.0) = %g\n", x);
22 x = sinh(3.0);
24 printf("sinh(3.0) = %g\n", x);
26 h = hypot(2.0,3.0);
28 printf("h=%g\n", h);
30 a = atan2(3.0, 2.0);
32 printf("atan2(3,2) = %g\n", a);
34 lr = pow(h,4.0);
36 printf("pow(%g,4.0) = %g\n", h, lr);
38 lrr = lr;
40 li = 4.0 * a;
42 lr = lr / exp(a*5.0);
44 printf("%g / exp(%g * 5) = %g\n", lrr, a, lr);
46 lrr = li;
48 li += 5.0 * log(h);
50 printf("%g + 5*log(%g) = %g\n", lrr, h, li);
52 printf("cos(%g) = %g, sin(%g) = %g\n", li, cos(li), li, sin(li));
54 x = drem(10.3435,6.2831852);
56 printf("drem(10.3435,6.2831852) = %g\n", x);
58 x = drem(-10.3435,6.2831852);
60 printf("drem(-10.3435,6.2831852) = %g\n", x);
62 x = drem(-10.3435,-6.2831852);
64 printf("drem(-10.3435,-6.2831852) = %g\n", x);
66 x = drem(10.3435,-6.2831852);
68 printf("drem(10.3435,-6.2831852) = %g\n", x);
71 printf("x%8.6gx\n", .5);
72 printf("x%-8.6gx\n", .5);
73 printf("x%6.6gx\n", .5);
76 double x = atof ("-1e-17-");
77 printf ("%g %c= %g %s!\n",
79 x == -1e-17 ? '=' : '!',
80 -1e-17,
81 x == -1e-17 ? "Worked" : "Failed");
84 print_trig_stuff ();
86 return 0;
90 #define PI 3.14159265358979323846264338327
92 const double RAD[5] = { 0, PI/2, PI, (3*PI)/2, 2*PI };
93 const int DEG[5] = { 0, 90, 180, 360 };
95 #define PRINT_IT_1_ARG(_func, _arg, _value) \
96 (_value) = (_func)((_arg)); \
97 if (errno) { \
98 errno = 0; \
99 printf("%s = ERROR %s\n", #_func, strerror(errno)); \
100 } else \
101 printf("%s(%g) = %g\n", #_func, _arg, (_value)); \
103 #define PRINT_IT_2_ARG(_func, _arg1, _arg2, _value) \
104 (_value) = (_func)((_arg1),(_arg2)); \
105 if (errno) { \
106 errno = 0; \
107 printf("%s = ERROR %s\n", #_func, strerror(errno)); \
108 } else \
109 printf("%s(%g, %g) = %g\n", #_func, _arg1, _arg2, (_value)); \
111 void
112 DEFUN_VOID (print_trig_stuff)
114 double value, arg1, arg2;
115 int i;
117 puts ("\n\nMath Test");
119 errno = 0; /* automatically reset on error condition */
120 for (i=0; i<4; i++)
122 PRINT_IT_1_ARG (sin, RAD[i], value);
123 PRINT_IT_1_ARG (cos, RAD[i], value);
124 PRINT_IT_1_ARG (tan, RAD[i], value);
125 PRINT_IT_1_ARG (asin, RAD[i], value);
126 PRINT_IT_1_ARG (acos, RAD[i], value);
127 PRINT_IT_1_ARG (atan, RAD[i], value);
128 PRINT_IT_2_ARG (atan2, RAD[i], -RAD[i % 4], value);
131 arg1 = 16;
132 arg2 = 3;
133 PRINT_IT_1_ARG (exp, arg1, value);
134 PRINT_IT_1_ARG (log, arg1, value);
135 PRINT_IT_1_ARG (log10, arg1, value);
136 PRINT_IT_2_ARG (pow, arg1, arg2, value);
137 PRINT_IT_1_ARG (sqrt, arg1, value);
138 PRINT_IT_1_ARG (cbrt, arg1, value);
139 PRINT_IT_2_ARG (hypot, arg1, arg2, value);
140 PRINT_IT_1_ARG (expm1, arg1, value);
141 PRINT_IT_1_ARG (log1p, arg1, value);
142 PRINT_IT_1_ARG (sinh, arg1, value);
143 PRINT_IT_1_ARG (cosh, arg1, value);
144 PRINT_IT_1_ARG (tanh, arg1, value);
145 PRINT_IT_1_ARG (asinh, arg1, value);
146 PRINT_IT_1_ARG (acosh, arg1, value);
147 PRINT_IT_1_ARG (atanh, arg1, value);