X-Git-Url: http://git.csclub.uwaterloo.ca/?p=kopensolaris-gnu%2Fglibc.git;a=blobdiff_plain;f=math%2Ftest-math.c;h=a82daed4e48d62c371398d0102be4cfe5a30193b;hp=21e873de477e783c18ad4692ae4e43059f1dfbb9;hb=5a97cf1ae1ee9bc7ae91066a7fff39dc5f8251be;hpb=9f934d0843e71dcaefa3dfcf68b079fe15dccb81 diff --git a/math/test-math.c b/math/test-math.c index 21e873de47..a82daed4e4 100644 --- a/math/test-math.c +++ b/math/test-math.c @@ -3,6 +3,8 @@ #include #include +void print_trig_stuff __P ((void)); + int DEFUN_VOID(main) { @@ -39,7 +41,7 @@ DEFUN_VOID(main) lr = lr / exp(a*5.0); - printf("%g / exp(%g * 5) = %g\n", lrr, exp(a*5.0), lr); + printf("%g / exp(%g * 5) = %g\n", lrr, a, lr); lrr = li; @@ -70,7 +72,77 @@ DEFUN_VOID(main) printf("x%-8.6gx\n", .5); printf("x%6.6gx\n", .5); - puts (atof ("-1e-17-") == -1e-17 ? "4 Worked!" : "4 Failed!"); + { + double x = atof ("-1e-17-"); + printf ("%g %c= %g %s!\n", + x, + x == -1e-17 ? '=' : '!', + -1e-17, + x == -1e-17 ? "Worked" : "Failed"); + } + + print_trig_stuff (); return 0; } + + +#define PI 3.14159265358979323846264338327 + +const double RAD[5] = { 0, PI/2, PI, (3*PI)/2, 2*PI }; +const int DEG[5] = { 0, 90, 180, 360 }; + +#define PRINT_IT_1_ARG(_func, _arg, _value) \ + (_value) = (_func)((_arg)); \ + if (errno) { \ + errno = 0; \ + printf("%s = ERROR %s\n", #_func, strerror(errno)); \ + } else \ + printf("%s(%g) = %g\n", #_func, _arg, (_value)); \ + +#define PRINT_IT_2_ARG(_func, _arg1, _arg2, _value) \ + (_value) = (_func)((_arg1),(_arg2)); \ + if (errno) { \ + errno = 0; \ + printf("%s = ERROR %s\n", #_func, strerror(errno)); \ + } else \ + printf("%s(%g, %g) = %g\n", #_func, _arg1, _arg2, (_value)); \ + +void +DEFUN_VOID (print_trig_stuff) +{ + double value, arg1, arg2; + int i; + + puts ("\n\nMath Test"); + + errno = 0; /* automatically reset on error condition */ + for (i=0; i<4; i++) + { + PRINT_IT_1_ARG (sin, RAD[i], value); + PRINT_IT_1_ARG (cos, RAD[i], value); + PRINT_IT_1_ARG (tan, RAD[i], value); + PRINT_IT_1_ARG (asin, RAD[i], value); + PRINT_IT_1_ARG (acos, RAD[i], value); + PRINT_IT_1_ARG (atan, RAD[i], value); + PRINT_IT_2_ARG (atan2, RAD[i], -RAD[i % 4], value); + } + + arg1 = 16; + arg2 = 3; + PRINT_IT_1_ARG (exp, arg1, value); + PRINT_IT_1_ARG (log, arg1, value); + PRINT_IT_1_ARG (log10, arg1, value); + PRINT_IT_2_ARG (pow, arg1, arg2, value); + PRINT_IT_1_ARG (sqrt, arg1, value); + PRINT_IT_1_ARG (cbrt, arg1, value); + PRINT_IT_2_ARG (hypot, arg1, arg2, value); + PRINT_IT_1_ARG (expm1, arg1, value); + PRINT_IT_1_ARG (log1p, arg1, value); + PRINT_IT_1_ARG (sinh, arg1, value); + PRINT_IT_1_ARG (cosh, arg1, value); + PRINT_IT_1_ARG (tanh, arg1, value); + PRINT_IT_1_ARG (asinh, arg1, value); + PRINT_IT_1_ARG (acosh, arg1, value); + PRINT_IT_1_ARG (atanh, arg1, value); +}