BCD Division



#2

One time 'quiche eater' seeks a (clear) description of the algorithm to perform the division of two (unpacked) BCD numbers (10 digit mantessa + 2 digit exponent - now where might you have seen that format before).

I know it is shift and subtract but I can't remember exactly how it was supposed to work - I do remember it wasn't obvious!

Mike T.

PS I don't want to use an existing library like BIGINT or similar.


#3

I'd start at http://www2.hursley.ibm.com/decimal. The web page's author is the expert on decimal arithmetic.


#4

Many thanks, I'd had found the site earlier but not that page - must have missed it.


I'll have to read it slowly to make sense of it properly (and I guess I'll have to create my own flowchart or structure diagram as there wasn't one) but I think that given a few days, and no too many late nights I should be able to cut some useful code...

Mike T.

#5

to perform U/V where these are bcd floats. first unpack the mantissas, exponents and signs so that you have two positive mantissas u/v. start by settings the exponent of the result, w, to be exp(U) - exp(V). now perform the u/v division as follows:

(1)	ensure that u >= v. if not, shift u left 1 packed bcd digit and decrement w, if quotient = 0, otherwise shift quotient left 1 digit.. goto (1)
(2) while u >= v, perform u = u - v. count the number of subtractions, q. this is the next digit of the answer. goto (1)

there’s a bit more to it than this but essentially you are shifting until you’ve got something to subtract then you subtract all you can at each digit and put the number of subtractions into the answer and continue until you’ve got a full house of quotient mantissa.

lastly fix up the signs and exponent of the quotient.

i wrote some `C’ code one for this here:
http://www.voidware.com/bcdfloats.htm


#6

Now I can make a connection - I did find your web site a while ago, and I should have guessed you would be reading these posts! Unfortunately I haven't yet got the hang of unravelling somebody else's code and have been having more than a little difficulty sorting out what was going on as your routines use packed BCD which makes life a little more interesting. Thank you for the precis.

Mike T.


#7

those routines are a bit old. i have a new 20 digit bcd library now. i keep meaning to put this up for download.


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP Prime polynomial long division bluesun08 13 873 10-30-2013, 03:29 AM
Last Post: parisse
  Why does PEMDAS do multiplication and division before addition and subtraction? Don Shepherd 12 855 07-31-2013, 10:59 AM
Last Post: robert rozee
  BCD, Binary, ...Binary Coded Duodecimal? mpi 7 494 02-20-2013, 04:28 PM
Last Post: Paul Dale
  Understanding HP-16C integer division Jimi 18 1,122 10-16-2012, 09:13 PM
Last Post: Eddie W. Shore
  HP-97S with a bad BCD interface: help me! Ignazio Cara (Italy) 3 290 03-22-2011, 03:54 AM
Last Post: Katie Wasserman
  Corvallis Division - DIV.39 Joerg Woerner 3 299 09-13-2010, 04:15 PM
Last Post: Martin Pinckney
  HP 48gII displays division as a fraction Peter Klein 5 392 04-10-2010, 05:32 PM
Last Post: Peter Klein
  Math Software that supports BCD? Tim Wessman 16 780 04-07-2010, 06:53 AM
Last Post: Bill (Smithville, NJ)
  Integer division on HP 33S Antonio Maschio (Italy) 22 1,005 08-22-2006, 11:47 AM
Last Post: e,young
  exponents in 14-nybble BCD floating-point representations Cameron Paine 3 277 04-12-2006, 09:53 PM
Last Post: Vieira, L. C. (Brazil)

Forum Jump: