wrr.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_err.h>
  20. #include <pc_file.h>
  21. extern _wstrin();
  22. extern char *_ecvt();
  23. #define PREC_DIG 80 /* maximum digits produced by _ecvt() */
  24. _wsr(w,r,f) int w; double r; struct file *f; {
  25. char *p,*b; int s,d,i; char buf[PREC_DIG+7];
  26. if (w < 0) _trp(EWIDTH);
  27. p = buf;
  28. if ((i = w-6) < 2)
  29. i = 2;
  30. b = _ecvt(r,i,&d,&s);
  31. *p++ = s? '-' : ' ';
  32. if (*b == '0')
  33. d++;
  34. *p++ = *b++;
  35. *p++ = '.';
  36. while (--i > 0)
  37. *p++ = *b++;
  38. *p++ = 'e';
  39. d--;
  40. if (d < 0) {
  41. d = -d;
  42. *p++ = '-';
  43. } else
  44. *p++ = '+';
  45. if (d >= 1000) {
  46. *p++ = '*';
  47. *p++ = '*';
  48. *p++ = '*';
  49. }
  50. else {
  51. *p++ = '0' + d/100;
  52. *p++ = '0' + (d/10) % 10;
  53. *p++ = '0' + d%10;
  54. }
  55. _wstrin(w,(int)(p-buf),buf,f);
  56. }
  57. _wrr(r,f) double r; struct file *f; {
  58. _wsr(13,r,f);
  59. }