rdr.c

Go to the documentation of this file.
00001 /* $Header: /opt/proj/minix/cvsroot/src/lib/ack/libp/rdr.c,v 1.1 2005/10/10 15:27:47 beng Exp $ */
00002 /*
00003  * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
00004  *
00005  *          This product is part of the Amsterdam Compiler Kit.
00006  *
00007  * Permission to use, sell, duplicate or disclose this software must be
00008  * obtained in writing. Requests for such permissions may be sent to
00009  *
00010  *      Dr. Andrew S. Tanenbaum
00011  *      Wiskundig Seminarium
00012  *      Vrije Universiteit
00013  *      Postbox 7161
00014  *      1007 MC Amsterdam
00015  *      The Netherlands
00016  *
00017  */
00018 
00019 /* Author: J.W. Stevenson */
00020 
00021 #include        <pc_file.h>
00022 
00023 #define BIG     1e17
00024 
00025 extern          _rf();
00026 extern          _incpt();
00027 extern          _skipsp();
00028 extern int      _getsig();
00029 extern int      _getint();
00030 extern int      _fstdig();
00031 extern int      _nxtdig();
00032 
00033 static double           r;
00034 static int              pow10;
00035 
00036 static dig(ch) int ch; {
00037 
00038         if (r>BIG)
00039                 pow10++;
00040         else
00041                 r = r*10.0 + ch;
00042 }
00043 
00044 double _rdr(f) struct file *f; {
00045         int i; double e; int is_signed,ch;
00046 
00047         r = 0;
00048         pow10 = 0;
00049         _rf(f);
00050         _skipsp(f);
00051         is_signed = _getsig(f);
00052         ch = _fstdig(f);
00053         do
00054                 dig(ch);
00055         while ((ch = _nxtdig(f)) >= 0);
00056         if (*f->ptr == '.') {
00057                 _incpt(f);
00058                 ch = _fstdig(f);
00059                 do {
00060                         dig(ch);
00061                         pow10--;
00062                 } while ((ch = _nxtdig(f)) >= 0);
00063         }
00064         if ((*f->ptr == 'e') || (*f->ptr == 'E')) {
00065                 _incpt(f);
00066                 pow10 += _getint(f);
00067         }
00068         if ((i = pow10) < 0)
00069                 i = -i;
00070         e = 1.0;
00071         while (--i >= 0)
00072                 e *= 10.0;
00073         if (pow10<0)
00074                 r /= e;
00075         else
00076                 r *= e;
00077         return(is_signed? -r : r);
00078 }

Generated on Fri Apr 14 22:57:25 2006 for minix by  doxygen 1.4.6