ack/lang/cem/libcc/stdio/fltpr.c

69 lines
1,012 B
C
Raw Permalink Normal View History

1994-06-24 14:02:31 +00:00
/* $Id$ */
1987-01-27 15:57:55 +00:00
#ifndef NOFLOAT
extern char *fcvt();
extern char *ecvt();
char *
_pfloat(r,s,n,b)
double r;
register char *s;
{
1987-05-25 09:13:12 +00:00
register char *s1;
int sign,dp;
register int i;
1987-01-27 15:57:55 +00:00
if (b == 0)
n = 6;
s1 = fcvt(r,n,&dp,&sign);
if (sign)
*s++ = '-';
if (dp<=0)
*s++ = '0';
for (i=dp; i>0; i--)
1987-10-22 15:26:36 +00:00
if (*s1) *s++ = *s1++;
else *s++ = '0';
1987-01-27 15:57:55 +00:00
if ((i=n) > 0)
*s++ = '.';
while (++dp <= 0) {
if (--i<0)
break;
*s++ = '0';
}
while (--i >= 0)
1987-10-22 15:26:36 +00:00
if (*s1) *s++ = *s1++;
else *s++ = '0';
1987-01-27 15:57:55 +00:00
return(s);
}
1987-05-25 09:13:12 +00:00
char *_pscien(r,s,n,b) float r; register char *s; {
int sign,dp;
register char *s1;
1987-01-27 15:57:55 +00:00
if (b == 0)
n = 7;
else n += 1;
s1 = ecvt(r,n,&dp,&sign);
if (sign)
*s++ = '-';
*s++ = *s1++;
*s++ = '.';
while (--n>0)
1987-10-22 15:26:36 +00:00
if (*s1) *s++ = *s1++;
else *s++ = '0';
1987-01-27 15:57:55 +00:00
*s++ = 'e';
if ( r ) --dp ;
if ( dp<0 ) {
*s++ = '-' ; dp= -dp ;
} else {
*s++ = '+' ;
}
1988-07-01 11:56:08 +00:00
if (dp >= 100) {
*s++ = '0' + (dp / 100);
dp %= 100;
}
1987-01-27 15:57:55 +00:00
*s++ = '0' + (dp/10);
*s++ = '0' + (dp%10);
return(s);
}
#endif