Uninitialized vector entry?
[minix3.git] / lib / ack / libp / wrf.c
blob5ee6e629adb03740d7d3ba5bd7d18ae4c45b31ff
1 /* $Header$ */
2 /*
3 * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
5 * This product is part of the Amsterdam Compiler Kit.
7 * Permission to use, sell, duplicate or disclose this software must be
8 * obtained in writing. Requests for such permissions may be sent to
10 * Dr. Andrew S. Tanenbaum
11 * Wiskundig Seminarium
12 * Vrije Universiteit
13 * Postbox 7161
14 * 1007 MC Amsterdam
15 * The Netherlands
19 /* Author: J.W. Stevenson */
21 #include <pc_err.h>
22 #include <pc_file.h>
24 extern _wstrin();
25 extern char *_fcvt();
27 #define assert(x) /* nothing */
29 #if __STDC__
30 #include <float.h>
31 #define HUGE_DIG DBL_MAX_10_EXP /* log10(maxreal) */
32 #else
33 #define HUGE_DIG 400 /* log10(maxreal) */
34 #endif
35 #define PREC_DIG 80 /* the maximum digits returned by _fcvt() */
36 #define FILL_CHAR '0' /* char printed if all of _fcvt() used */
37 #define BUFSIZE HUGE_DIG + PREC_DIG + 3
39 _wrf(n,w,r,f) int n,w; double r; struct file *f; {
40 char *p,*b; int s,d; char buf[BUFSIZE];
42 if ( n < 0 || w < 0) _trp(EWIDTH);
43 p = buf;
44 if (n > PREC_DIG)
45 n = PREC_DIG;
46 b = _fcvt(r,n,&d,&s);
47 assert(abs(d) <= HUGE_DIG);
48 if (s)
49 *p++ = '-';
50 if (d<=0)
51 *p++ = '0';
52 else
54 *p++ = (*b ? *b++ : FILL_CHAR);
55 while (--d > 0);
56 if (n > 0)
57 *p++ = '.';
58 while (++d <= 0) {
59 if (--n < 0)
60 break;
61 *p++ = '0';
63 while (--n >= 0) {
64 *p++ = (*b ? *b++ : FILL_CHAR);
65 assert(p <= buf+BUFSIZE);
67 _wstrin(w,(int)(p-buf),buf,f);