home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12580 < prev    next >
Encoding:
Text File  |  1992-08-20  |  1.3 KB  |  60 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cs.utexas.edu!natinst.com!banshee
  3. From: banshee@natinst.com (Jeff Kellam)
  4. Subject: Possible Borland 3.1 bug
  5. Message-ID: <1992Aug20.165327.18694@natinst.com>
  6. Sender: news@natinst.com
  7. Nntp-Posting-Host: eagle.natinst.com
  8. Organization: National Instruments, Austin, TX
  9. Date: Thu, 20 Aug 1992 16:53:27 GMT
  10. Lines: 48
  11.  
  12. There appears to be a bug in the optimization routines of
  13. the Borland 3.1 compiler.
  14.  
  15.  
  16. If the code below is compiled with optimization set to fastest code
  17. a floating point error occurs.
  18.  
  19. Using the debugger, I was able to determine that the source of the
  20. problem is related to the optimization of -divisor, which is calculated
  21. outside of the loop.  It seems in calculating the value of -divisor,
  22. the compiler doesn't clean up the floating point stack, so after eight
  23. iteration of Function, the FP stack overflows.
  24.  
  25. If anyone sees a flaw in this reasoning, or has had similiar experiences,
  26. please post or email me at banshee@natinst.com
  27.  
  28.  
  29. Thanks,
  30.  
  31. Jeff Kellam
  32. banshee@natinst.com
  33.  
  34.  
  35. /*   PROGRAM STARTS  */
  36.  
  37. double array[5] = {1.0,2.0,3.0,4.0,5.0};
  38.  
  39. void Function(double);
  40.  
  41. main() {
  42.     int i;
  43.  
  44.     for (i=10; i<20; i++)
  45.         Function(i);
  46.     return 0;
  47. }
  48.  
  49. void Function(double divisor) {
  50.  
  51.     int i;
  52.  
  53.     for (i=0;i<5;i++) {
  54.         array[i] *= divisor;
  55.         array[i] *= -divisor;
  56.     }
  57. }
  58.  
  59. /*  PROGRAM ENDS  */
  60.