Line | |
---|
1 | /* $Header: /cvsup/minix/src/lib/ack/libp/rdr.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_file.h>
|
---|
22 |
|
---|
23 | #define BIG 1e17
|
---|
24 |
|
---|
25 | extern _rf();
|
---|
26 | extern _incpt();
|
---|
27 | extern _skipsp();
|
---|
28 | extern int _getsig();
|
---|
29 | extern int _getint();
|
---|
30 | extern int _fstdig();
|
---|
31 | extern int _nxtdig();
|
---|
32 |
|
---|
33 | static double r;
|
---|
34 | static int pow10;
|
---|
35 |
|
---|
36 | static dig(ch) int ch; {
|
---|
37 |
|
---|
38 | if (r>BIG)
|
---|
39 | pow10++;
|
---|
40 | else
|
---|
41 | r = r*10.0 + ch;
|
---|
42 | }
|
---|
43 |
|
---|
44 | double _rdr(f) struct file *f; {
|
---|
45 | int i; double e; int is_signed,ch;
|
---|
46 |
|
---|
47 | r = 0;
|
---|
48 | pow10 = 0;
|
---|
49 | _rf(f);
|
---|
50 | _skipsp(f);
|
---|
51 | is_signed = _getsig(f);
|
---|
52 | ch = _fstdig(f);
|
---|
53 | do
|
---|
54 | dig(ch);
|
---|
55 | while ((ch = _nxtdig(f)) >= 0);
|
---|
56 | if (*f->ptr == '.') {
|
---|
57 | _incpt(f);
|
---|
58 | ch = _fstdig(f);
|
---|
59 | do {
|
---|
60 | dig(ch);
|
---|
61 | pow10--;
|
---|
62 | } while ((ch = _nxtdig(f)) >= 0);
|
---|
63 | }
|
---|
64 | if ((*f->ptr == 'e') || (*f->ptr == 'E')) {
|
---|
65 | _incpt(f);
|
---|
66 | pow10 += _getint(f);
|
---|
67 | }
|
---|
68 | if ((i = pow10) < 0)
|
---|
69 | i = -i;
|
---|
70 | e = 1.0;
|
---|
71 | while (--i >= 0)
|
---|
72 | e *= 10.0;
|
---|
73 | if (pow10<0)
|
---|
74 | r /= e;
|
---|
75 | else
|
---|
76 | r *= e;
|
---|
77 | return(is_signed? -r : r);
|
---|
78 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.