rdr.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $Id$ */
  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. /* Author: J.W. Stevenson */
  19. #include <pc_file.h>
  20. #define BIG 1e17
  21. extern _rf();
  22. extern _incpt();
  23. extern _skipsp();
  24. extern int _getsig();
  25. extern int _getint();
  26. extern int _fstdig();
  27. extern int _nxtdig();
  28. static double r;
  29. static int pow10;
  30. static dig(ch) int ch; {
  31. if (r>BIG)
  32. pow10++;
  33. else
  34. r = r*10.0 + ch;
  35. }
  36. double _rdr(f) struct file *f; {
  37. int i; double e; int is_signed,ch;
  38. r = 0;
  39. pow10 = 0;
  40. _rf(f);
  41. _skipsp(f);
  42. is_signed = _getsig(f);
  43. ch = _fstdig(f);
  44. do
  45. dig(ch);
  46. while ((ch = _nxtdig(f)) >= 0);
  47. if (*f->ptr == '.') {
  48. _incpt(f);
  49. ch = _fstdig(f);
  50. do {
  51. dig(ch);
  52. pow10--;
  53. } while ((ch = _nxtdig(f)) >= 0);
  54. }
  55. if ((*f->ptr == 'e') || (*f->ptr == 'E')) {
  56. _incpt(f);
  57. pow10 += _getint(f);
  58. }
  59. if ((i = pow10) < 0)
  60. i = -i;
  61. e = 1.0;
  62. while (--i >= 0)
  63. e *= 10.0;
  64. if (pow10<0)
  65. r /= e;
  66. else
  67. r *= e;
  68. return(is_signed? -r : r);
  69. }