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: <7977@charon.cwi.nl>
- Date: 24 Nov 92 01:45:35 GMT
- References: <1992Nov20.215133.3271@enterprise.rdd.lmsc.lockheed.com> <7959@charon.cwi.nl> <1992Nov22.040145.6371@u.washington.edu>
- Sender: news@cwi.nl
- Organization: CWI, Amsterdam
- Lines: 32
-
- In article <1992Nov22.040145.6371@u.washington.edu> golbone@stein.u.washington.edu (Sima Hashemifar) writes:
- > No! No! No! You can not in any way deduce the properties of the floating
- > point system based on the rounding behavior.
- You do not know how wrong you are. At the very least rounding behaviour
- will give information about the number of bits to store the mantissa of
- the number (when given enough roundings).
- > For one, most modern fp
- > units may be convinced to act in many way, affine ...
- But they generally do not change it on the fly, so you have to make some
- assumptions.
- > 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.
- Now I am not in physics but in mathematics, so if physics says the above
- it might very well be true (makes my card-play scoring scientific rather
- than ad-hoc, I like that). But you still fail to see that on your system
- there is nothing like a trailing 5. The only possibilities are a trailing
- 1 or a trailing 0, nothing else is available.
-
- > 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.
- I presume that C is pre-ANSI and so uses double precision in its calculations
- while Fortran uses single precision only, so actually the C results will
- be more precise ;-). Learn something about the inexactitude of floating-
- point numbers. It helps a lot.
-
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland
- home: bovenover 215, 1025 jn amsterdam, nederland; e-mail: dik@cwi.nl
-