home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bcdclass.zip / README.BCD < prev   
Text File  |  1995-10-05  |  7KB  |  142 lines

  1.  
  2. Announcing a Binary Coded Decimal Class for C++ applications requiring arithmetic
  3. operations on large integers.
  4.  
  5. Features:
  6. o  32 decimal digits
  7. o  Object construtors from string, double and long types
  8. o  Object contains sign and condition code in addition to 32 digit integer
  9. o  Overloaded cout << operator prints object contents with sign and condition code
  10. o  Add, Subtract, Multiply, Modulus and Divide supported via overloaded operators
  11. o  Overloaded Logical operators <, >, ==, != are supported
  12. o  Assignment operator, =, is supported.
  13. o  bcdToString function suppresses leading zeros and inserts decimal point
  14. o  Shift Left, Shift Right, Shift Right Rounded and Shift Right Coupled
  15.    are supported.
  16. o  sigD() function returns number of significant digits - quick bcd zero test
  17. o  Package now includes a simple PM calculator to demonstrate and test the 
  18.    arithmetic and shift functions of the bcd class.
  19.  
  20. BCD Arithmetic is not for everyone, primarily because it is serial and therefore
  21. slower than the fixed and floating point instructions embodied on the hardware
  22. chip.  In addition, the current version of the BCD class is implemented as a big
  23. integer so fractional data will be lost unless the operands are scaled
  24. appropriately.
  25.  
  26. The BCD register size can be set to any arbitrary length, within practical
  27. limits of course.  I chose 32 digits for the bcd class because it is about
  28. twice the capacity of a double floating point number and can be expected to
  29. operate at a reasonable performance.  
  30.  
  31. I am including my regression test bucket, bcdrun.cpp, in the package as a
  32. demonstration run and to give you some usage examples.  These tests produce
  33. the bcdrun.log which you should take time to review before embarking on your
  34. own experiments. Feel free to contribute to the test cases and I will include
  35. them in the next update.
  36.  
  37. The BCD Class is provided without warrantee for your personal use and is not
  38. licensed for inclusion in any commercial application or for subsequent resale.
  39. Fully licensed copies of the BCD Class, including source, users guide, and 
  40. technical support are available from JBC Enterprises, Inc.  
  41.  
  42. I am in the process of building floating point support which will be released
  43. later as a separate class object.
  44.  
  45.  
  46. Condition Codes:
  47.  
  48.  16 Non-zero condition code on resubtract.  When the significant digits are the
  49.     same, I make a guess about which operand is the larger so I can subtract
  50.     the smaller from the larger.  If I am wrong, I have to swap the operands
  51.     and repeat the subtraction.  If the cc is still non-zero on the resubtract
  52.     something is wrong.
  53.  
  54.  16 Shift out of range - On Shift Left, if significant digits plus shift amount
  55.     are greater than 32.  On all Shift Right operations, if shift amount is
  56.     greater than 32.
  57.  
  58.  16 Divide by zero.
  59.  
  60.  16 Add overflow detected by significant digits test.  This is a quick check
  61.     that is done early in the operation.  There is an ambiguity on the 33rd
  62.     digit which is covered later during the add.
  63.  
  64.  15 Add overflow detected by the adder.  If the destination digits have been
  65.     exhausted but there are still unprocessed source digits.  This picks up
  66.     the ambiguity that is missed by the significant digits test.
  67.  
  68.  14 Adder error: swap/digofs are something other than 0 or 1.  This is an 
  69.     internal issue and is probably overkill in the checking. (:}
  70.  
  71.  12 Multiply error:  Non-decimal digit encountered during multiply operation.
  72.  
  73.   1 Carry out of the high order digit of the adder returned on an addition.  This
  74.     is not quite the same as cond code 15 since all of the source and destination
  75.     digits are accommodated but there is still a carry left in the adder.
  76.  
  77. Bill Connors
  78. JBC Enterprises, Inc.
  79. 17820 Stoneridge Drive
  80. Gaithersburg, MD  20878
  81. 1(800)249-8223 voice/fax
  82.  
  83. Beta.1   8/26/95
  84. ==================================================================================
  85. 1. Original distribution to 2 persons on Compuserve who expressed interest in
  86.    having a bcd class.
  87.  
  88. Files:
  89.  8-26-95   1:26p      1989           0  BCD.H
  90.  8-26-95   5:51p     37812           0  bcd.obj
  91.  8-26-95   5:37p     15141           0  bcdrun.cpp
  92.  8-26-95   5:52p    153496          49  BCDRUN.EXE
  93.  8-26-95   5:52p     10953           0  bcdrun.log
  94.  8-26-95   5:29p      1934           0  readme.bcd
  95.  
  96.  
  97. Beta.2   9/12/95, 9/13/95, 9/14/95, 9/24/95
  98. =================================================================================
  99. 1. Changed multiply so that overflow returns the original multiplicand and sign
  100.    on multiply overflow.  Overflow is determined by adding the number of signi-
  101.    ficant digits in the multiplicand and multiplier, or as a result of a high
  102.    order carry out during the multiply-add operations.  In the case of cascaded
  103.    multiply ops, A * B * C ... etc., the returned value is the product of the
  104.    last successful multiply.
  105.  
  106. 2. Changed divide so that the original dividend and sign are returned on a
  107.    divide by zero error.  Since modulus is a divide in disguise it is affected
  108.    also.
  109.  
  110. 3. Created a simple BCD Calculator as a test and demonstration tool.  It is not
  111.    intended for everyday use mainly because it is an integer calculator and has
  112.    some suprising attributes.  For example, you might expect 1/3 to be .333333
  113.    or something.  Instead the answer is 0 because fractions are truncated.  On
  114.    the other hand, if you divide 1000 by 3 the result is 333.  Personally, I
  115.    prefer my pocket calculator to manage the decimal points for me.
  116.  
  117. 4. Fixed a divide "incorrect output" error revealed by the BCD Calculator.
  118.    (I knew the calculator would turn out to be useful). ;^)
  119.  
  120. 5. Changed multiply to detect overflow errors at the end of each multiplier
  121.    digit case.
  122.  
  123. 6. Changed the adder to detect overflows when the result digits are exhausted
  124.    but there are still unprocessed source digits.
  125.  
  126. 7. Added Shift Right Coupled.
  127.  
  128. 8. Deleted bcdrun.exe from distribution zip file - saves about 50% of the space.
  129.  
  130.  
  131. Beta.2 Files:
  132.  
  133.  9-24-95  12:50p      2338           0  BCD.H
  134.  9-24-95  12:51p     42342           0  bcd.obj      precompiled bcd class
  135.  9-24-95   1:38p     61984           0  BCDCALC.EXE  PM applette demo/test
  136.  9-12-95  11:38a       874          22  BCDCalc.ICO
  137.  9-25-95  10:13a      5106           0  BCDCalc.INF
  138.  9-24-95  10:23a     17833           0  bcdrun.cpp          | to recreate bcdrun.exe
  139.  9-24-95  12:52p    149977          49  BCDRUN.EXE  deleted:| compile bcdrun.cpp and
  140.  9-24-95  12:52p     13205           0  bcdrun.log          | link with bcd.obj
  141.  9-25-95  11:01a      6499           0  readme.bcd
  142.