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

78 lines
1.2 KiB
C
Raw Normal View History

1989-05-30 13:34:25 +00:00
/*
* floatpr.c - print floating point numbers
*/
/* $Header$ */
#ifndef NOFLOAT
#include "loc_incl.h"
char *
1989-06-26 10:37:05 +00:00
_pfloat(long double r, register char *s, int n, int flags)
1989-05-30 13:34:25 +00:00
{
register char *s1;
int sign, dp;
register int i;
s1 = fcvt(r, n, &dp, &sign);
if (sign)
*s++ = '-';
else if (flags & FL_SIGN)
*s++ = '+';
else if (flags & FL_SPACE)
*s++ = ' ';
if (dp<=0)
*s++ = '0';
for (i=dp; i>0; i--)
if (*s1) *s++ = *s1++;
else *s++ = '0';
if (((i=n) > 0) || (flags & FL_ALT))
*s++ = '.';
while (++dp <= 0) {
if (--i<0)
break;
*s++ = '0';
}
while (--i >= 0)
if (*s1) *s++ = *s1++;
else *s++ = '0';
1989-06-26 10:37:05 +00:00
return s;
1989-05-30 13:34:25 +00:00
}
char *
1989-06-26 10:37:05 +00:00
_pscien(long double r, register char *s, int n, int flags)
1989-05-30 13:34:25 +00:00
{
int sign, dp;
register char *s1;
s1 = ecvt(r, n + 1, &dp, &sign);
if (sign)
*s++ = '-';
else if (flags & FL_SIGN)
*s++ = '+';
else if (flags & FL_SPACE)
*s++ = ' ';
*s++ = *s1++;
if ((n > 0) || (flags & FL_ALT))
*s++ = '.';
1989-12-18 15:04:14 +00:00
while (--n >= 0)
1989-05-30 13:34:25 +00:00
if (*s1) *s++ = *s1++;
else *s++ = '0';
*s++ = 'e';
if ( r != 0 ) --dp ;
if ( dp<0 ) {
*s++ = '-' ; dp= -dp ;
} else {
*s++ = '+' ;
}
if (dp >= 100) {
*s++ = '0' + (dp / 100);
dp %= 100;
}
*s++ = '0' + (dp/10);
*s++ = '0' + (dp%10);
1989-06-26 10:37:05 +00:00
return s;
1989-05-30 13:34:25 +00:00
}
#endif /* NOFLOAT */