home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / arch / 10503 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  3.0 KB

  1. Path: sparky!uunet!decwrl!waikato.ac.nz!comp.vuw.ac.nz!zl2tnm!toyunix!don
  2. Newsgroups: comp.arch
  3. Subject: Re: IEEE used for Dollars and Cents
  4. Message-ID: <628311@zl2tnm.gen.nz>
  5. From: don@zl2tnm.gen.nz (Don Stokes)
  6. Date: 7 Nov 92 11:00:54 GMT
  7. Sender: news@zl2tnm.gen.nz (GNEWS Version 2.0 news poster.)
  8. Distribution: world
  9. Organization: The Wolery
  10. Lines: 55
  11.  
  12. keith@ksmith.uucp (Keith Smith) writes:
  13. > In article <1917307@zl2tnm.gen.nz> don@zl2tnm.gen.nz (Don Stokes) writes:
  14. > >Machines that can handle 64 bit integers cleanly will make this problem
  15. > >largely go away.  8-)
  16. > A pretty darn big assumption that you only need 2 or 3 decimal places of
  17. > precision in a financial calculation.  We have some 4 decimal place
  18. > multiplication here.
  19.  
  20. I did say "largely".  You can get yourself screwed up with BCD or decimal
  21. character datatypes too -- I have fond memories of the fun and games when
  22. a customer of a bureau I was working for started putting through >$10M 
  23. transactions, and the system dropped the 10th digit (dollar amounts were
  24. represented by ascii representations of an integer number of cents).  But
  25. I digress.
  26.  
  27. A signed 64 bit integer gives nearly 19 digits of precision.  A four decimal
  28. place multiplication of a dollar amount (thinking of them as integral
  29. numbers of cents makes this easier) will only lose four of those digits 
  30. before you divide the result by 10,000 to bring it back to a cent value 
  31. again.  That still leaves you with dollar values of up to
  32. $9,223,372,036,854.77.  
  33.  
  34. The "other" approach to the problem of datatypes that are too small is to
  35. use floating point but keep to integer values.  The peril there of course
  36. is that you silently lose digits if the value exceeds the precision of the
  37. mantissa.
  38.  
  39. 128 bit integers, anyone?
  40.  
  41. > Why doesen't someone build a bcd or bcddouble type INTO the 'C' compiler
  42. > with a higher order than float.  Numbers could be 8 or 16 bytes, 2 bytes
  43. > of sign/exponent, and eith 7 or 15 bytes of mantissa, (14 or 30
  44. > *DECIMAL* as in BASE 10 places of precision).
  45.  
  46. Possibly because they feel, as I do, that C isn't the language to write
  47. "business" applications in.  But a bit of extended precision support in the
  48. language wouldn't go amis.  (He says having just written code _full_ of 64 
  49. bit arithmetic on a 32 bit machine to cope with monthly network traffic
  50. values in bytes....) 
  51.  
  52. Extended precision fixed point would be a reasonable compromise, and could
  53. be made to run quite a bit faster than decimal on current hardware.
  54.  
  55. While I'm ranting:  Bricks to DEC for putting 64 bit integer support in the
  56. Alpha C compiler only, and making the "same" datatype 32 bits on "compatible"
  57. MIPS platforms.  Jeez!  Extended precision isn't _that_ hard.  Sure, it'll
  58. run a little slower than a native datatype and operations won't be atomic,
  59. but surely documenting this fact (or not treating programmers as idiots) is
  60. a better way?
  61.  
  62. --
  63. Don Stokes, ZL2TNM (DS555)                        don@zl2tnm.gen.nz (home)
  64. Network Manager, Computing Services Centre            don@vuw.ac.nz (work)
  65. Victoria University of Wellington, New Zealand              +64-4-495-5052
  66.