home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / coherent / 6372 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.6 KB  |  74 lines

  1. Newsgroups: comp.os.coherent
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!mcshub!csx.cciw.ca!hcp
  3. From: hcp@csx.cciw.ca (H.C. Pulley)
  4. Subject: Re: Floating point: printf "%g" bug?
  5. Organization: Canada Centre for Inland Waters
  6. Date: Tue, 22 Dec 1992 13:00:28 GMT
  7. Message-ID: <1992Dec22.130028.27444@csx.cciw.ca>
  8. References: <1992Dec21.123913.2881@philips.oz.au>
  9. Lines: 63
  10.  
  11. In article <1992Dec21.123913.2881@philips.oz.au> brianw@philips.oz.au (Brian Wallis) writes:
  12. >I've come across a possible anomally in the floating point output from printf
  13. >in Coherent 4.0. The program to demonstrate this is appended at the end. It
  14. >looks to me like a rounding error.
  15. >
  16. >Here are the rusults of running the program on my system...
  17. >
  18. >
  19. >38 - (.13g)38 (.14g)38
  20. >39 - (.13g)39 (.14g)39
  21. >40 - (.13g)40 (.14g)40
  22. >41 - (.13g)41 (.14g)41.00000000000001
  23. >42 - (.13g)42 (.14g)42
  24. >43 - (.13g)43 (.14g)43
  25. >44 - (.13g)44 (.14g)44
  26. >45 - (.13g)45 (.14g)45
  27. >46 - (.13g)46 (.14g)46.00000000000001
  28. >47 - (.13g)47 (.14g)47
  29. >48 - (.13g)48 (.14g)48.00000000000001
  30. >49 - (.13g)49 (.14g)49
  31. >50 - (.13g)50 (.14g)50
  32. >51 - (.13g)51 (.14g)51.00000000000001
  33. >52 - (.13g)52 (.14g)52
  34. >53 - (.13g)53 (.14g)53.00000000000001
  35. >54 - (.13g)54 (.14g)54
  36. >55 - (.13g)55 (.14g)55
  37. >56 - (.13g)56 (.14g)56.00000000000001
  38. >57 - (.13g)57 (.14g)57
  39. >58 - (.13g)58 (.14g)58.00000000000001
  40. >59 - (.13g)59 (.14g)59
  41. >
  42. >The extra ...0001 is causing problems in my port of perl. I may have to replace
  43. >printf and friends, but then again perhaps the problem is in the floating point
  44. >itself?
  45. >
  46. >Any clues from anyone?
  47.  
  48. I think the problem is just that double precision floating point IEEE format 
  49. is not significant to the number of digits you are trying to display.  If you
  50. try this with float instead of double you should see the same thing or worse
  51. (this used to happen a lot in FORTRAN with different machines having very 
  52. different doubleprecision in the mainframe days - CDC Cybers have 128 bit 
  53. doubles, and you wonder why your answer is not the same as the guy using the 
  54. VAX).
  55.  
  56. I am sure you know, but just like there is 1/3 = .3333333..... in decimal, 
  57. there are non-repeating numbers in binary, octal and hex too.  Numbers which 
  58. repeat in one system, may not repeat in another.
  59.  
  60. The DECVAX format used in Coherent 286 has a few more fraction bits.
  61.  
  62. >thanks, brian...
  63.  
  64. I hope it helps!
  65.  
  66. [coding example deleted]
  67.  
  68. Harry
  69. -- 
  70.          hcp@csx.cciw.ca          |This message released|It takes all kinds,
  71.    hcpiv@grumpy.cis.uoguelph.ca   |to the PUBLIC DOMAIN.|and to each his own.
  72. ----------------------------------+---------------------|This thought in mind,
  73. Stay away from the DOS side, Luke!|Un*x don't play that.|I walk alone.
  74.