home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!uwm.edu!ogicse!news.u.washington.edu!stein.u.washington.edu!golbone
- From: golbone@stein.u.washington.edu (Sima Hashemifar)
- Newsgroups: comp.lang.c
- Subject: Re: Rounding floating point numbers in C
- Message-ID: <1992Nov22.040145.6371@u.washington.edu>
- Date: 22 Nov 92 04:01:45 GMT
- Article-I.D.: u.1992Nov22.040145.6371
- References: <1992Nov20.215133.3271@enterprise.rdd.lmsc.lockheed.com> <7959@charon.cwi.nl>
- Sender: news@u.washington.edu (USENET News System)
- Organization: University of Washington, Seattle
- Lines: 41
-
- In article <7959@charon.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
- >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
-
- No! No! No! You can not in any way deduce the properties of the floating
- point system based on the rounding behavior. For one, most modern fp
- units may be convinced to act in many way, affine ...
- More impotantly, there are elementary rules for rounding in scientific
- world. Any odd number followed by 5 is rounded down while even numbers
- are rounded up. Based on this simple rule, the results printed above
- are not valid in your laboratory notebook.
- Thanks.
- BTW, I ran the numbers through my fortran compiler on DEC/Ultrix, I got
- the scientifically correct results, BUT the C compiler generated the
- results above. I can only say that "C" has a different floating point
- model than Fortran.
-