Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2005-04-02 11:24:08


As part of the project to produce a Boost TR1 implementation I've
implemented the additional algorithms in <complex> that are part of the TR:

fabs
asin asinh
acos acosh
atan atanh

It occurs to me that maybe these should really be spun out as a separate
library rather than "slipped in" as part of another submission (comments
welcome on that).

In the mean time these algorithms can be downloaded as part of the TR1
library here:
http://boost-sandbox.sourceforge.net/vault/index.php?&direction=0&order=&directory=tr1

All the inverse trig functions are defined for the full complex plain, and
do the right thing even for exceptional input (no overflow or underflow
during the computation if the result is actually representable). They also
do the right thing for infinities and nan's, as specified by C99.

The asin/asinh/acos/acosh algorithms have a theoretical max error bound of
9.5e (experimental bounds are much lower, about 4e), there is no theoretical
work on atan/atanh that I know of, but experimentally the error bound seems
lower than for asin/acos. This is some of the most heavily commented code
I've written, so refer to the header for more information on the literature
sources used etc.

During the implementation I found that I needed a few other things that
might make useful Boost components (part implemented, part wish list as
noted below):

log1p:
~~~~

This algorithm is part of C99, but by no means all compilers support it yet,
I used a Taylor series expansion for small x: I'm aware that there are much
more efficient methods, but optimizing compilers completely trash the logic
of these (Intel C++ proved to be particularly bad).

Series Summation (Kahan Method):
~~~~~~~~~~~~~~~~~~~~~~~~

I wrote a small routine to apply the Kahan summation method to a
nullary-functor that generates successive terms in a series. Summation
stops when the next term is below a particular threshold. I've found the
Kahan method to be significantly more accurate for certain series, but again
some highly optimizing compilers can cause small errors to creep in (I
believe that the issue is double-rounding of intermediate terms on machines
with extended-double registers). Probably my current interface to this one
needs some more thought before it could be anything other than a detail, and
if we're talking about wish lists, infinite product, and continued fraction
evaluation would be useful additions too....

Floating point testing:
~~~~~~~~~~~~~~

Currently just a version of C99's isnan, and only works for quiet nan's with
IEEE-conforming compilers. More of a wish list really, I could really use
all the C99 fp-testing macros (as C++ functions obviously).

Numeric constants:
~~~~~~~~~~~~~

Currently I've embedded the numeric constants used inside the
implementation, a numeric constants library really would have simplified
things... just a pity we could never agree on an interface last time this
came up.

Whew, I think that's all, thanks for reading this far!

Regards,

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk