dan i have have been talking about the decimal math package for bigint/bigfloat. i have some ideas and am looking for some of you to work with me on this.
my idea is to use an old hardware trick called excess-3 to efficiently do decimal adds/subtracts in word sized chunks. this is much faster than nibble or byte at a time algorithms. the principal is fairly simple. a given BCD number is modified by adding 3's to each nibble (hence the name excess-3). when two excess-3 words are added in binary, any nibble which would have carried as a decimal will now carry in binary as the nibble sum is now excess-6. you can detect nibble overflows by looking at the low order bit of the next higher order nibble. just xor the original operands and the result and make a low nibble bit mask which will mark which nibbles overflowed. result nibbles that didn't overflow get 3 subtracted from them which brings them back to excess-3 (from the excess 6 they were). result nibbles that did overflow get 3 added to them which brings them back to excess-3 (since they were excess 0). so all the add/subtract math can be done in word sized chunks with adds, masks, shifts and xors. supporting multiple decimal words is not too much harder. you just have to handle carry/borrow between words. memory management of these decimal buffers will be a small issue too. there are many little areas that have to be worked on including multiply/divide and signed number handling. i implemented this package for a PL/I compiler runtime many years ago and i just got off the phone with the guy who taught it to me back then. i can't find any useful web links on it other than hardware related ones and such. none seem to have the software algorithms and i can't get a hold of my old code for this (which would need a total rewrite anyhow). so do any of you want to work on this with me? i may not do the primary coding but work with the algorithms, design, data structures, etc. if this gets busy (there is a fair amount of design and coding involved) we can spin off a perl6-internals-decimal list for it. one intersting idea is a design which supports bigint/bigfloat as one unified data type. the only difference is where the decimal point is and how many fractional digits you have. i have many more design ideas for this that i want to put into this first post (including mutiplication speedups, decimal alignment stuff, etc.). we will also want to research how other langs do their big num stuff as well. thanx, uri -- Uri Guttman --------- [EMAIL PROTECTED] ---------- http://www.sysarch.com SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com Search or Offer Perl Jobs -------------------------- http://jobs.perl.org