home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / bsd / 4986 < prev    next >
Encoding:
Text File  |  1992-09-01  |  1.7 KB  |  64 lines

  1. Newsgroups: comp.unix.bsd
  2. Path: sparky!uunet!mcsun!Germany.EU.net!rrz.uni-koeln.de!aix370!a0045
  3. From: a0045@rrz.uni-koeln.de (Jochen Roderburg)
  4. Subject: 386BSD FP problems, or: why is 0.0 == -1.0 ??
  5. Message-ID: <A0045.92Sep2120530@berry.rrz.uni-koeln.de>
  6. Sender: news@rrz.uni-koeln.de (Usenet News System)
  7. Organization: Regional Computing Center, University of Cologne, F. R. Germany
  8. Distribution: comp
  9. Date: 2 Sep 92 12:05:30
  10. Lines: 52
  11.  
  12. The C system on 386BSD seems to have some strange problems with
  13. floating-point constants. 
  14.  
  15. The following test program justs prints out a few constants:
  16.  
  17. main () { 
  18. printf ("0.  %+f\n", 0. ); 
  19. printf ("0.0 %+f\n", 0.0); 
  20. printf ("0.1 %+f\n", 0.1); 
  21. printf ("0.5 %+f\n", 0.5); 
  22. printf ("0.6 %+f\n", 0.6); 
  23. printf ("1.0 %+f\n", 1.0); 
  24. printf ("1.1 %+f\n", 1.1); 
  25. printf ("1.5 %+f\n", 1.5); 
  26. printf ("1.6 %+f\n", 1.6); 
  27. }
  28.  
  29. And these are the suprising results:
  30.  
  31. 0.  +0.000000
  32. 0.0 -1.000000
  33. 0.1 +0.000000
  34. 0.5 +0.000000
  35. 0.6 +1.000000
  36. 1.0 +1.000000
  37. 1.1 +1.000000
  38. 1.5 +2.000000
  39. 1.6 +2.000000
  40.  
  41. Especially entertaining is the wonderful transformation from 0.0 to -1.0.
  42. You may understand that a small utility which uses a few of these constants 
  43. brought not very useful results. 
  44.  
  45. The errors seem to happen already in the compiler, not during the printout.
  46. When you use the constants in expressions you get results that fit to the
  47. printout, for example  2+0.0 -> 1.0.
  48.  
  49. I have observed this on PCs without mathematical coprocessor, if this is of
  50. any importance.
  51.  
  52. Has anybody a clue what is going on here ?
  53.  
  54. Jochen Roderburg
  55. Regional Computing Center
  56. University of Cologne
  57. Robert-Koch-Str. 10                    Tel.:   +49-221/470-4564
  58. D-5000 Koeln 41                        E-Mail: Ro @ RRZ.Uni-Koeln.DE
  59. Germany
  60.  
  61.  
  62.  
  63.  
  64.