1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1984-07-20 10:44:57 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
*
|
|
|
|
* This product is part of the Amsterdam Compiler Kit.
|
|
|
|
*
|
|
|
|
* Permission to use, sell, duplicate or disclose this software must be
|
|
|
|
* obtained in writing. Requests for such permissions may be sent to
|
|
|
|
*
|
|
|
|
* Dr. Andrew S. Tanenbaum
|
|
|
|
* Wiskundig Seminarium
|
|
|
|
* Vrije Universiteit
|
|
|
|
* Postbox 7161
|
|
|
|
* 1007 MC Amsterdam
|
|
|
|
* The Netherlands
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Author: J.W. Stevenson */
|
|
|
|
|
2018-06-17 14:11:29 +00:00
|
|
|
#include <pc_err.h>
|
|
|
|
#include <pc_file.h>
|
1984-07-20 10:44:57 +00:00
|
|
|
|
2018-06-17 14:11:29 +00:00
|
|
|
extern _wstrin();
|
|
|
|
extern char* _fcvt();
|
1984-07-20 10:44:57 +00:00
|
|
|
|
2018-06-17 14:11:29 +00:00
|
|
|
#define assert(x) /* nothing */
|
1984-07-20 10:44:57 +00:00
|
|
|
|
1991-03-20 11:30:35 +00:00
|
|
|
#if __STDC__
|
|
|
|
#include <float.h>
|
2018-06-17 14:11:29 +00:00
|
|
|
#define HUGE_DIG DBL_MAX_10_EXP /* log10(maxreal) */
|
1991-03-20 11:30:35 +00:00
|
|
|
#else
|
2018-06-17 14:11:29 +00:00
|
|
|
#define HUGE_DIG 400 /* log10(maxreal) */
|
1991-03-20 11:30:35 +00:00
|
|
|
#endif
|
2018-06-17 14:11:29 +00:00
|
|
|
#define PREC_DIG 80 /* the maximum digits returned by _fcvt() */
|
|
|
|
#define FILL_CHAR '0' /* char printed if all of _fcvt() used */
|
|
|
|
#define BUFSIZE HUGE_DIG + PREC_DIG + 3
|
1984-07-20 10:44:57 +00:00
|
|
|
|
2018-06-17 14:11:29 +00:00
|
|
|
_wrf(n, w, r, f) int n, w;
|
|
|
|
double r;
|
|
|
|
struct file* f;
|
|
|
|
{
|
|
|
|
char *p, *b;
|
|
|
|
int s, d;
|
|
|
|
char buf[BUFSIZE];
|
1984-07-20 10:44:57 +00:00
|
|
|
|
2018-06-17 14:11:29 +00:00
|
|
|
if (n < 0 || w < 0)
|
|
|
|
_trp(EWIDTH);
|
1984-07-20 10:44:57 +00:00
|
|
|
p = buf;
|
|
|
|
if (n > PREC_DIG)
|
|
|
|
n = PREC_DIG;
|
2018-06-17 14:11:29 +00:00
|
|
|
b = _fcvt(r, n, &d, &s);
|
1984-07-20 10:44:57 +00:00
|
|
|
assert(abs(d) <= HUGE_DIG);
|
|
|
|
if (s)
|
|
|
|
*p++ = '-';
|
2018-06-17 14:11:29 +00:00
|
|
|
if (d <= 0)
|
1984-07-20 10:44:57 +00:00
|
|
|
*p++ = '0';
|
|
|
|
else
|
|
|
|
do
|
|
|
|
*p++ = (*b ? *b++ : FILL_CHAR);
|
|
|
|
while (--d > 0);
|
|
|
|
if (n > 0)
|
|
|
|
*p++ = '.';
|
2018-06-17 14:11:29 +00:00
|
|
|
while (++d <= 0)
|
|
|
|
{
|
1984-07-20 10:44:57 +00:00
|
|
|
if (--n < 0)
|
|
|
|
break;
|
|
|
|
*p++ = '0';
|
|
|
|
}
|
2018-06-17 14:11:29 +00:00
|
|
|
while (--n >= 0)
|
|
|
|
{
|
1984-07-20 10:44:57 +00:00
|
|
|
*p++ = (*b ? *b++ : FILL_CHAR);
|
2018-06-17 14:11:29 +00:00
|
|
|
assert(p <= buf + BUFSIZE);
|
1984-07-20 10:44:57 +00:00
|
|
|
}
|
2018-06-17 14:11:29 +00:00
|
|
|
_wstrin(w, (int)(p - buf), buf, f);
|
1984-07-20 10:44:57 +00:00
|
|
|
}
|