home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_06 / 2n06076b < prev    next >
Text File  |  1991-04-16  |  561b  |  23 lines

  1.  
  2.      double setsigdig(double x, unsigned int n)
  3.          {
  4.          double shift, result;
  5.      
  6.          if ((n == 0U) || (n > DBL_DIG))
  7.              result = x;
  8.          else
  9.              {
  10.              // adjust the number of significant digits
  11.              --n;
  12.      
  13.              // calculate the number of digits to be shifted
  14.              shift = pow(10.0,(double)n 
  15.                         - floor(log10(fabs(x))));
  16.      
  17.              result = tonearest(x * shift) / shift;
  18.              }
  19.      
  20.          return result;
  21.          }
  22.  
  23.