home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_07 / 9n07089a < prev    next >
Text File  |  1991-02-13  |  2KB  |  35 lines

  1.  
  2. main()
  3. {
  4. #include "float.h"
  5.     double atof();
  6.     static double x[] = {
  7.         (1 + DBL_EPSILON) * DBL_MIN, DBL_MIN * (FLT_RADIX - DBL_EPSILON), 1e-307,
  8. /* (nextafter(x) -x) cannot underflow from here on */
  9.         DBL_MIN * (FLT_RADIX / DBL_EPSILON - 1),
  10. /* many libraries don't do as well as they should with numbers around DBL_EPSILON */
  11.         DBL_EPSILON / FLT_RADIX * (1 - DBL_EPSILON / FLT_RADIX), DBL_EPSILON * (FLT_RADIX - DBL_EPSILON),
  12.  /* lower limit of IEEE standard exact conversion is between next two */ 
  13.         (1-DBL_EPSILON/FLT_RADIX)*1e-10,1e-10,
  14.         (1-DBL_EPSILON/FLT_RADIX)*.1,.1,
  15.         (1 - DBL_EPSILON / FLT_RADIX) / FLT_RADIX, 1 - DBL_EPSILON / FLT_RADIX,
  16.         1., FLT_RADIX - DBL_EPSILON,
  17.         (1-DBL_EPSILON/FLT_RADIX)*10,10.,
  18. /* range where nextafter(x) = x+1; conversion should always be exact */
  19.         1 / DBL_EPSILON + 1, FLT_RADIX / DBL_EPSILON - 1,
  20. /* %.17g formats should switch from f to e format without error between next two */
  21.         (1-DBL_EPSILON/FLT_RADIX)*1e17,1e17,
  22. /*  upper limit of exact conversion without long double table of powers of 10 */
  23.         (1-DBL_EPSILON/FLT_RADIX)*1e32,1e32,
  24.  /* upper limit of IEEE standard exact conversion is between next two */ 
  25.         (1-DBL_EPSILON/FLT_RADIX)*1e44,1e44,1e307,
  26.     DBL_MAX / FLT_RADIX * (1 - DBL_EPSILON / FLT_RADIX), 1e308,DBL_MAX * (1 - DBL_EPSILON / FLT_RADIX)};
  27.     char buf[80], *gcvt();
  28.     int i;
  29.     (void) printf("\tformatted value\t\tdouble conversion error\n");
  30.     for (i = 0; i <= 27; ++i) {
  31.         (void) gcvt(x[i], 17, buf);
  32.         (void) printf("       %s\t%g\n", buf, atof(buf) - x[i]);
  33.     }
  34. }
  35.