home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 17081 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  2.2 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: <7977@charon.cwi.nl>
  6. Date: 24 Nov 92 01:45:35 GMT
  7. References: <1992Nov20.215133.3271@enterprise.rdd.lmsc.lockheed.com> <7959@charon.cwi.nl> <1992Nov22.040145.6371@u.washington.edu>
  8. Sender: news@cwi.nl
  9. Organization: CWI, Amsterdam
  10. Lines: 32
  11.  
  12. In article <1992Nov22.040145.6371@u.washington.edu> golbone@stein.u.washington.edu (Sima Hashemifar) writes:
  13.  > No! No! No! You can not in any way deduce the properties of the floating
  14.  > point system based on the rounding behavior.
  15. You do not know how wrong you are.  At the very least rounding behaviour
  16. will give information about the number of bits to store the mantissa of
  17. the number (when given enough roundings).
  18.  >                                              For one, most modern fp
  19.  > units may be convinced to act in many way, affine ...
  20. But they generally do not change it on the fly, so you have to make some
  21. assumptions.
  22.  > More impotantly, there are elementary rules for rounding in scientific
  23.  > world. Any odd number followed by 5 is rounded down while even numbers
  24.  > are rounded up. Based on this simple rule, the results printed above
  25.  > are not valid in your laboratory notebook.
  26. Now I am not in physics but in mathematics, so if physics says the above
  27. it might very well be true (makes my card-play scoring scientific rather
  28. than ad-hoc, I like that).  But you still fail to see that on your system
  29. there is nothing like a trailing 5.  The only possibilities are a trailing
  30. 1 or a trailing 0, nothing else is available.
  31.  
  32.  > BTW, I ran the numbers through my fortran compiler on DEC/Ultrix, I got 
  33.  > the scientifically correct results, BUT the C compiler generated the
  34.  > results above. I can only say that "C" has a different floating point
  35.  > model than Fortran.
  36. I presume that C is pre-ANSI and so uses double precision in its calculations
  37. while Fortran uses single precision only, so actually the C results will
  38. be more precise ;-).  Learn something about the inexactitude of floating-
  39. point numbers.  It helps a lot.
  40.  
  41. -- 
  42. dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland
  43. home: bovenover 215, 1025 jn  amsterdam, nederland; e-mail: dik@cwi.nl
  44.