home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / gcc / bug / 2812 < prev    next >
Encoding:
Text File  |  1992-11-21  |  1.6 KB  |  55 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!moonlite.CAlvacom.FR!local
  3. From: local@moonlite.CAlvacom.FR (Local Unix modifications)
  4. Subject: Floating point problems with gcc 2.3.1 on ISC Unix
  5. Message-ID: <9211210929.AA15389@moonlite.calvacom.fr>
  6. Sender: gnulists@ai.mit.edu
  7. Reply-To: JH10@calvacom.fr (John Hughes)
  8. Organization: GNUs Not Usenet
  9. Distribution: gnu
  10. Date: Sat, 21 Nov 1992 09:29:26 GMT
  11. Approved: bug-gcc@prep.ai.mit.edu
  12. Lines: 41
  13.  
  14. As I reported earlier the following little program, when compiled with
  15. gcc 2.3.1 gives a bad answer when run on Interactive Unix 2.2.  It
  16. works when compiled with gcc 2.1.  I can now also report that it works
  17. (even when compiled with gcc 2.3.1) when run on a machine with a FPU.
  18. That is to say the problem is caused by a bug in Interactive's 80387
  19. emulator that is used when no physical 80387 is present.  (Or is it
  20. ATT's emulator?   In other words will the problem affect non ISC
  21. system V.3.2's on 386's ?  How about System V.4 ?
  22.  
  23. The program:
  24.  
  25. ------------------------------------------------
  26.  
  27. #include <stdio.h>
  28.  
  29.  
  30. void Store (float a, float *b) { *b=a; }
  31. float Sum (float a, float b) {float r; Store(a+b, &r); return (r); }
  32. float Diff (float a, float b){float r; Store(a-b, &r); return (r); }
  33. float Mul (float a, float b) {float r; Store(a*b, &r); return (r); }
  34.  
  35.  
  36. int main () {
  37.     volatile int digits = 0;
  38.     volatile float b = 1.0;
  39.     volatile float base = 2;
  40.  
  41.     do {
  42.         digits++;
  43.         b = Mul (b, base);
  44.     }
  45.     while (Diff (Diff (Sum (b, 1.0), b), 1.0) == 0.0);
  46.  
  47.     printf ("Digits = %d\n", digits);
  48.  
  49.     return 0;
  50. }
  51.  
  52. --
  53. John Hughes, RCI CalvaCom, Paris, France
  54.  
  55.