home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16981 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  2.6 KB

  1. Path: sparky!uunet!spool.mu.edu!uwm.edu!ogicse!news.u.washington.edu!stein.u.washington.edu!golbone
  2. From: golbone@stein.u.washington.edu (Sima Hashemifar)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Rounding floating point numbers in C
  5. Message-ID: <1992Nov22.040145.6371@u.washington.edu>
  6. Date: 22 Nov 92 04:01:45 GMT
  7. Article-I.D.: u.1992Nov22.040145.6371
  8. References: <1992Nov20.215133.3271@enterprise.rdd.lmsc.lockheed.com> <7959@charon.cwi.nl>
  9. Sender: news@u.washington.edu (USENET News System)
  10. Organization: University of Washington, Seattle
  11. Lines: 41
  12.  
  13. In article <7959@charon.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
  14. >This is not in the FAQ, but perhaps something should go there about the
  15. >inexactitude of FP arithmetic and FP constants.
  16. >
  17. >In article <1992Nov20.215133.3271@enterprise.rdd.lmsc.lockheed.com> gumerman@aspen.ops.lmsc.lockheed.com () writes:
  18. > > The way numbers are rouned is totally inconsistent.  Sometimes numbers are 
  19. > > rounded up sometimes they are rounded down.  What is going on here?
  20. >It is, in a way.  Note that not all numbers are exactly representable on
  21. >the machine.
  22. > > 
  23. > > 1.15      1.1   /* round down */
  24. > > 1.25      1.3   /* round up  */
  25. > > 1.35      1.4   /* round up  */
  26. > > 1.45      1.5   /* round up  */
  27. > > 1.55      1.5   /* round down */
  28. > > 1.65      1.6   /* round down */
  29. > > 1.75      1.8   /* round up  */
  30. > > 1.85      1.9   /* round up  */
  31. > > 1.95      2.0   /* round up  */
  32. >Of these only 1.25 and 1.75 are exactly represented on your machine, so the
  33. >others have representations that are slightly larger or slightly smaller
  34. >than the presented value.  This influences the rounding.  (Looking at the
  35. >numbers, 1.15, 1.55 and 1.65 are represented slightly smaller; taking a
  36. >lot of time it is even possible to deduce a lot of the properties of the
  37. >fp system and fp conversion of your machine.)
  38. >-- 
  39. >dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland
  40. >home: bovenover 215, 1025 jn  amsterdam, nederland; e-mail: dik@cwi.nl
  41.  
  42. No! No! No! You can not in any way deduce the properties of the floating
  43. point system based on the rounding behavior. For one, most modern fp
  44. units may be convinced to act in many way, affine ...
  45. More impotantly, there are elementary rules for rounding in scientific
  46. world. Any odd number followed by 5 is rounded down while even numbers
  47. are rounded up. Based on this simple rule, the results printed above
  48. are not valid in your laboratory notebook.
  49. Thanks.
  50. BTW, I ran the numbers through my fortran compiler on DEC/Ultrix, I got 
  51. the scientifically correct results, BUT the C compiler generated the
  52. results above. I can only say that "C" has a different floating point
  53. model than Fortran.
  54.