source: trunk/minix/lib/ack/libp/wrf.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.5 KB
Line 
1/* $Header: /cvsup/minix/src/lib/ack/libp/wrf.c,v 1.1 2005/10/10 15:27:47 beng Exp $ */
2/*
3 * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 *
5 * This product is part of the Amsterdam Compiler Kit.
6 *
7 * Permission to use, sell, duplicate or disclose this software must be
8 * obtained in writing. Requests for such permissions may be sent to
9 *
10 * Dr. Andrew S. Tanenbaum
11 * Wiskundig Seminarium
12 * Vrije Universiteit
13 * Postbox 7161
14 * 1007 MC Amsterdam
15 * The Netherlands
16 *
17 */
18
19/* Author: J.W. Stevenson */
20
21#include <pc_err.h>
22#include <pc_file.h>
23
24extern _wstrin();
25extern char *_fcvt();
26
27#define assert(x) /* nothing */
28
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
38
39_wrf(n,w,r,f) int n,w; double r; struct file *f; {
40 char *p,*b; int s,d; char buf[BUFSIZE];
41
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
53 do
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';
62 }
63 while (--n >= 0) {
64 *p++ = (*b ? *b++ : FILL_CHAR);
65 assert(p <= buf+BUFSIZE);
66 }
67 _wstrin(w,(int)(p-buf),buf,f);
68}
Note: See TracBrowser for help on using the repository browser.