The Museum of HP Calculators

HP Forum Archive 15

[ Return to Index | Top of Index ]

Decimal floating point
Message #1 Posted by Thomas Okken on 14 Feb 2006, 5:52 p.m.

I just started work on adding support for decimal floating point to Free42. I'm getting close to the point where I can hook an actual decimal library into the code, and I'm now on the lookout for the best code to use.

Hugh Steers kindly gave me a copy of the decimal code he wrote for OpenRPN, and I may decide to use that code eventually - it has an unrestrictive license and it's fast, but because of its encoding scheme it is not very memory-efficient, and at present it still lacks a few functions I need (hyperbolics, gamma, ln(1+x), exp(x)-1).

So, does anyone know of any other options? The IBM decNumber code has licensing restrictions I'm not sure I'm prepared to live with... Something that implements IEEE-754R (including "extended", preferably) and comes under a nice BSD-ish license would be perfect, but I guess that may be a bit much to hope for...

(One cute benefit of the Free42 code restructuring is that I'm going to support the use of extra-wide numbers internally (for complex and matrix computations), so on platforms where "long double" really is longer than plain "double", you'll get some pretty decent accuracy when stress testing INVRT with Hilbert matrices and such... Something to keep fans of binary happy. If they're using Linux, anyway -- VC++ 6.0 does not support "long double" so unless I switch to different development software, the 80-bit capability of your PC's FPU will continue to sit idle. And PalmOS (or rather, MathLib) won't do long double, period. Oh, well, enough rambling.)

- Thomas

Edited: 14 Feb 2006, 6:26 p.m.

      
re: Decimal floating point
Message #2 Posted by hugh steers on 16 Feb 2006, 9:06 a.m.,
in response to message #1 by Thomas Okken

hi thomas,

for your long doubles, take a look at this: http://www.voidware.com/index.php?option=com_wrapper&page=http://www.voidware.com/dp.htm

its a handy template i wrote that turns your doubles into double-doubles. and you can re-apply it, to turn your double-doubles into double-double-doubles and so on!

you can recompile my BCD library with any N precision. i think, originally i set N to use 24 decimal digits. this was to be pretty confident of 20 digit accurate results. it should be good for sqrt too, but all the trigs are designed to be 20 digit accurate, although in most you could simply increase the number of terms used in the calculations.

a while back i looked at the IBM library, however the license isnt very clear. the thing i did acertain is that it isnt BCD in the usual sense. it works with large binary integers which it converts to decimal on IO. this has the advantage of a smaller representation, but you do need a double sized accumulator eg. for multiply.

incidently, i'm working on a new BCD float library for my "exact" calculator which is variable precision. the fun part is writing the arbrary precision implementations of functions. eg here's the gamma function i've only recently coded:

exact -acc 50
Exact! engine (experimental) V1.03
Usage: exact [-max <max-digits>] [-acc <accurate-digits>]
enter expression to evaluate. variables, x=<expr>
`ans' is last result. `clear' erases all variables
`i' is sqrt(-1). blank line to quit. (min accuracy 50, working accuracy 60)
> gamma(20+17i)
= -1.4506843033047183744112948625133950394899762252240E14-4.9626218780536756371909659359160242411188406767529E13i_

best regards,

Edited: 17 Feb 2006, 9:09 a.m.

            
Re: re: Decimal floating point
Message #3 Posted by Thomas Okken on 17 Feb 2006, 11:31 a.m.,
in response to message #2 by hugh steers

Hi Hugh,

I've more or less decided to use your code -- nice license, and if I use 12 bytes, I'll get an effective 17 digits, which is good enough for a 42S simulator (and in binary mode, I can use "long double" without changing the memory footprint, and that ought to make fans of ill-conditioned linear systems happy).
I'm still going to need hyperbolics, gamma, log1p, and expm1, but that, at least, is not a show-stopper as these are not too hard to fake.
BTW, do you know of any nice binary<->string routines? The code I wrote for Free42 works fine with "double", but it uses a look-up table that becomes a bit large when using "long double". For the Unix and Windows versions, I'll get around that by using sprintf and sscanf instead, but on PalmOS, that is not an option...

Thanks,

- Thomas

            
Re: re: Decimal floating point
Message #4 Posted by Rodger Rosenbaum on 17 Feb 2006, 4:10 p.m.,
in response to message #2 by hugh steers

Hugh says:

> gamma(20+17i) = -1.4506843033047183744112948625133950394899762252240E14-4.9626218780536756371909659359160242411188406767529E13i_

Both Mathematica and Maple say that gamma(20+17i) is about:

-6.65309788E13 + 1.381348614E14 i

You've got a lot of digits, but they all seem to be wrong. Any idea why?


[ Return to Index | Top of Index ]

Go back to the main exhibit hall