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