1: /*
   2:  * gcvt - Convert number to a string in buf.  If possible, ndigit significant
   3:  *  digits are produced, otherwise a form with an exponent is used.
   4:  */
   5: char   *ecvt();
   6: char *
   7: gcvt(number, ndigit, buf)
   8: double number;
   9: char *buf;
  10:    {
  11:    int sign, decpt;
  12:    register char *p1, *p2;
  13:    register i;
  14:    int junk;
  15: 
  16:    p1 = ecvt(number, ndigit, &decpt, &sign);
  17:    p2 = buf;
  18:    if (sign)
  19:       *p2++ = '-';
  20:    for (i=ndigit-1; i>0 && p1[i]=='0'; i--)
  21:       ndigit--;
  22:    if (decpt >= 0 && decpt-ndigit > 4
  23:       || decpt < 0 && decpt < -3) { /* use E-style */
  24:          decpt--;
  25:          *p2++ = *p1++;
  26:          *p2++ = '.';
  27:          for (i=1; i<ndigit; i++)
  28:             *p2++ = *p1++;
  29:          *p2++ = 'e';
  30:          if (decpt<0) {
  31:             decpt = -decpt;
  32:             *p2++ = '-';
  33:             }
  34:          if (decpt/10 > 0)
  35:             *p2++ = decpt/10 + '0';
  36:          *p2++ = decpt%10 + '0';
  37:       } else {
  38:          if (decpt<=0) {
  39:          /* if (*p1!='0') */
  40:          *p2++ = '0';
  41:          *p2++ = '.';
  42:          while (decpt<0) {
  43:             decpt++;
  44:             *p2++ = '0';
  45:             }
  46:          }
  47:          for (i=1; i<=ndigit; i++) {
  48:             *p2++ = *p1++;
  49:             if (i==decpt)
  50:                *p2++ = '.';
  51:             }
  52:       if (ndigit<decpt) {
  53:          while (ndigit++<decpt)
  54:             *p2++ = '0';
  55:          *p2++ = '.';
  56:          }
  57:    }
  58:    if (p2[-1]=='.')
  59:       *p2++ = '0';
  60:    *p2 = '\0';
  61:    return(buf);
  62:    }

Defined functions

gcvt defined in line 6; used 1 times
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 824
Valid CSS Valid XHTML 1.0 Strict