1: #if defined(LIBC_SCCS) && !defined(lint)
   2: static char sccsid[] = "@(#)gcvt.c	5.2 (Berkeley) 3/9/86";
   3: #endif LIBC_SCCS and not lint
   4: 
   5: /*
   6:  * gcvt  - Floating output conversion to
   7:  * minimal length string
   8:  */
   9: 
  10: char    *ecvt();
  11: 
  12: char *
  13: gcvt(number, ndigit, buf)
  14: double number;
  15: char *buf;
  16: {
  17:     int sign, decpt;
  18:     register char *p1, *p2;
  19:     register i;
  20: 
  21:     p1 = ecvt(number, ndigit, &decpt, &sign);
  22:     p2 = buf;
  23:     if (sign)
  24:         *p2++ = '-';
  25:     for (i=ndigit-1; i>0 && p1[i]=='0'; i--)
  26:         ndigit--;
  27:     if (decpt >= 0 && decpt-ndigit > 4
  28:      || decpt < 0 && decpt < -3) { /* use E-style */
  29:         decpt--;
  30:         *p2++ = *p1++;
  31:         *p2++ = '.';
  32:         for (i=1; i<ndigit; i++)
  33:             *p2++ = *p1++;
  34:         *p2++ = 'e';
  35:         if (decpt<0) {
  36:             decpt = -decpt;
  37:             *p2++ = '-';
  38:         } else
  39:             *p2++ = '+';
  40:         *p2++ = decpt/10 + '0';
  41:         *p2++ = decpt%10 + '0';
  42:     } else {
  43:         if (decpt<=0) {
  44:             if (*p1!='0')
  45:                 *p2++ = '.';
  46:             while (decpt<0) {
  47:                 decpt++;
  48:                 *p2++ = '0';
  49:             }
  50:         }
  51:         for (i=1; i<=ndigit; i++) {
  52:             *p2++ = *p1++;
  53:             if (i==decpt)
  54:                 *p2++ = '.';
  55:         }
  56:         if (ndigit<decpt) {
  57:             while (ndigit++<decpt)
  58:                 *p2++ = '0';
  59:             *p2++ = '.';
  60:         }
  61:     }
  62:     if (p2[-1]=='.')
  63:         p2--;
  64:     *p2 = '\0';
  65:     return(buf);
  66: }

Defined functions

gcvt defined in line 12; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1986-03-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1780
Valid CSS Valid XHTML 1.0 Strict