home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / math.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-08  |  1.8 KB  |  50 lines

  1. /* math.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <float.h>
  7.  
  8. int main (void)
  9. {
  10.   double x, y;
  11.   volatile long n;
  12.   volatile unsigned long un;
  13.   int i;
  14.  
  15. #if defined (__EMX__)
  16.   if (!(_emx_env & 0x20))
  17.     {
  18.       printf ("This program requires a coprocessor.\n");
  19.       return (1);
  20.     }
  21. #endif
  22. #if defined (MSDOS)
  23.   _control87 (EM_OVERFLOW|EM_UNDERFLOW|EM_INEXACT, MCW_EM);
  24. #endif
  25.   while (scanf ("%lf", &x) == 1)
  26.     {
  27.       printf ("x=%g, floor(x)=%g, ceil(x)=%g\n",
  28.                     x, floor (x), ceil (x));
  29.       printf ("rint(x)=%g, trunc(x)=%g\n", rint (x), trunc (x));
  30.       printf ("fabs(x)=%g, sqrt(x)=%g\n", fabs (x), sqrt (x));
  31.       printf ("exp(x)=%g, log(x)=%g, log10(x)=%g\n", exp (x), log (x), log10 (x));
  32.       printf ("sinh(x)=%g, cosh(x)=%g, tanh(x)=%g\n", sinh (x), cosh (x), tanh (x));
  33.       printf ("sin(x)=%g, cos(x)=%g, tan(x)=%g\n", sin (x), cos (x), tan (x));
  34.       printf ("atan(x)=%g, asin(x)=%g, acos(x)=%g\n", atan (x), asin (x), acos (x));
  35.       printf ("atan2(x,1)=%g\n", atan2 (x, 1));
  36.       printf ("ldexp(x,0)=%g, ldexp(x,-2)=%g, ldexp(x,3)=%g\n", ldexp (x, 0), ldexp (x, -2), ldexp (x, 3));
  37.       printf ("pow(x,1.8)=%g pow(1.8,x)=%g\n", pow (x, 1.8), pow (1.8, x));
  38.       printf ("pow(x,3.8)=%g pow(3.8,x)=%g\n", pow (x, 3.8), pow (3.8, x));
  39.       printf ("pow(-2.0,x)=%g\n", pow (-2.0, x));
  40.       printf ("fmod(-200000,x)=%g fmod(x,-3)=%g\n", fmod (-200000.0, x), fmod (x, -3.0));
  41.       printf ("cbrt(x)=%g, hypot(x,4)=%g\n", cbrt (x), hypot (x, 4.0));
  42.       y = frexp (x, &i);
  43.       printf ("frexp: x=%g*2^%d\n", y, i);
  44.       n = (long)x; un = (unsigned long)x;
  45.       printf ("(long)x         =%ld -> %g\n", n, (double)n);
  46.       printf ("(unsigned long)x=%lu -> %g\n", un, (double)un);
  47.     }
  48.   return (0);
  49. }
  50.