XBCD_Math is a high performance floating point math package which supports extended precision operations optimized for calculator type applications. The choice of BCD (Binary Coded Decimal) representation as the intrinsic data type is a compromise which is tilted toward I/O intensive environments, such as calculators, where much of the calculation overhead is due to conversion from user input to internal format and back. BCD minimizes the conversion overhead and, as a convenient side effect, provides a number format which is easy to edit.
The package is written entirely in Intel x86 assembler language, except for the conversion routines between character string representation and internal BCD format. The supported functions include ordinary math operations, square root, all trig and inverse trig functions, logs and exponentials, all hyperbolic and inverse hyperbolic functions, and a full range gamma function. Miscellaneous utility routines for truncation, rounding, floor and ceiling are also supported, as are conversions from integers, floats, doubles, and back.
Internally, numbers are stored in 32-byte blocks consisting of 58 BCD digits of mantissa, 4 BCD digits of exponent, and 1 byte which contains the mantissa and exponent signs plus status bits. They dynamic range, excluding transient underflow conditions, is from 1.0000...E-9999 to 9.9999...E+9999 for positive numbers. Except in pathological computations involving catastrophic loss of precision, extended computations will return about 56 correct digits, considerably beyond the capabilities of quad-precision packages.
A number of advanced algorithms are employed. These include CORDIC, pseudo-multiplication and pseudo-division, non-restoring pseudo-division, etc. Special methods are used for ordinary multi-digit multiplication and division to reduce the number of repeated additions and subtractions normally associated with non-binary formats.
At other pages on this web site, you will find application packages written for or ported to XBCD_Math. These include linear algebra functions, eigensystem solvers, non-linear solvers, integrators, root-finders, C++ classes, etc. A scientific calculator demonstrating the capabilities of the package can be found here.
I have ported the C version of MINPACK available elsewhere on this web site to work with XBCD_Math. Although most applications for nonlinear solvers do not require extended precision, there are occasions when it is helpful. The extended precision port is available here. A sample program which fits a set of measured points to a Lorentzian pulse model is also included.
The complete XBCD Math library is now available as a DLL. This archive includes the DLL, a Borland compatible import library, a complete set of format conversion routines and the XFLOAT class. Although the XFLOAT class is not required, it supports operator overloading of the C++ math and stream operators so new applications can be easily created.
If you wish to use the DLL with a different compiler (different from Borland C++) you will want to create an import library from the DLL which is compatible with your compiler.
The code below is a simple example of the ease with which the XBCD library can be incorporated into a C++ program. It is included in the archive. Many existing C++ math codes can be converted to extended precision by simply replacing all doubles with xfloats and including the library and support files.
// XBCD test program: bcdtst1.cpp
// This file requires an import library created from 'fltpt8d.dll'.
// Compile and link with: fpconv.cpp, xfloat.cpp, fltpt8d.lib
cout << sqrt(a) << endl;
cout << gamma(b) << endl;
cout << factorial((xfloat)48) << endl;
The output from this program is shown below.