Re: float decimal



Mike Cowlishaw wrote:
"Terje Mathisen" <terje.mathisen@xxxxxxxxxxxxx> wrote in message
That isn't really true: The algorithm I invented to convert unsigned binary numbers to decimal can do 32-bit to 10 decimal digits in ~40 cycles, which is quite competitive even with a base-1000 (or 754r declet) encoding and table lookup.

I did oversimplify ... but at small bases (10, 100, 1000) table look-up is hard to beat. For converting the decimal64 DPD format to string, my worst-case time in ANSI C code is 84 cycles (on a Pentium M laptop), which includes decoding the 'combination field', signs layout, 16 digits of coefficient, inserting '.', and a three-digit exponent. I'm not at all familiar with x86 so I am sure that could be bettered.

Sure, but you confirmed my estimate that two sets of my conversion code would be close to table lookup for 16 digits.

Working in base 1e9 or (better) 2^32 keeps the number of carry operations well down, which more than compensates for the small increase in conversion cost.

There's definitely a cross-over point depending on the length of the operands. The conversion cost is quite significant for somall operands/results. I'll send you my decNumber microbenchmark timings, if you would like, for chunk size 1-9

At some later time, I'm all out of "round'tuit's" this year, due to some very interesting extra-curricular programming. :-)

With a 128-bit BCD FP type with 34 digits, I could store those digits internally as a 113 bit (14 bytes + 1 spare bit) value, leaving 1 bit for the sign and 14 bits for the exponent. With a base 10 exponent that would cover 10^-8191 to 10^8191. :-)

Indeed, but if all one's data are in BCD or character form, it gets tedious converting to and from binary. Even BCD assists in hardware seem a better

Tedious is what we have computers for, right? :-)

In my own arbitrary precision code I tend to work in either 2^32 or 1e9, the latter if exact decimal is needed.

Terje

--
- <Terje.Mathisen@xxxxxxxxxxxxx>
"almost all programming can be viewed as an exercise in caching"
.