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

  1. Path: sparky!uunet!mcsun!sun4nl!cwi.nl!dik
  2. From: dik@cwi.nl (Dik T. Winter)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Rounding floating point numbers in C
  5. Message-ID: <7959@charon.cwi.nl>
  6. Date: 22 Nov 92 02:00:23 GMT
  7. References: <1992Nov20.215133.3271@enterprise.rdd.lmsc.lockheed.com>
  8. Sender: news@cwi.nl
  9. Organization: CWI, Amsterdam
  10. Lines: 27
  11.  
  12. This is not in the FAQ, but perhaps something should go there about the
  13. inexactitude of FP arithmetic and FP constants.
  14.  
  15. In article <1992Nov20.215133.3271@enterprise.rdd.lmsc.lockheed.com> gumerman@aspen.ops.lmsc.lockheed.com () writes:
  16.  > The way numbers are rouned is totally inconsistent.  Sometimes numbers are 
  17.  > rounded up sometimes they are rounded down.  What is going on here?
  18. It is, in a way.  Note that not all numbers are exactly representable on
  19. the machine.
  20.  > 
  21.  > 1.15      1.1   /* round down */
  22.  > 1.25      1.3   /* round up  */
  23.  > 1.35      1.4   /* round up  */
  24.  > 1.45      1.5   /* round up  */
  25.  > 1.55      1.5   /* round down */
  26.  > 1.65      1.6   /* round down */
  27.  > 1.75      1.8   /* round up  */
  28.  > 1.85      1.9   /* round up  */
  29.  > 1.95      2.0   /* round up  */
  30. Of these only 1.25 and 1.75 are exactly represented on your machine, so the
  31. others have representations that are slightly larger or slightly smaller
  32. than the presented value.  This influences the rounding.  (Looking at the
  33. numbers, 1.15, 1.55 and 1.65 are represented slightly smaller; taking a
  34. lot of time it is even possible to deduce a lot of the properties of the
  35. fp system and fp conversion of your machine.)
  36. -- 
  37. dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland
  38. home: bovenover 215, 1025 jn  amsterdam, nederland; e-mail: dik@cwi.nl
  39.