Boost logo

Boost :

Subject: [boost] Review request: extended complex number library
From: Matthieu Schaller (matthieu.schaller_at_[hidden])
Date: 2012-03-05 16:41:16


Dear all,

Following the comments from V. Escriba, I formally propose my complex
number library for review.
The library is an extension of the std::complex class addressing two issues:
- The standard does not guaranty the behaviour of the complex class if
instantiated with types other than float/double/long double.
- Some calculation where pure imaginary numbers (i.e. multiples of
sqrt(-1)) appear are unnecessarily slowed down due to the lack of
support for these numbers.
The code I submit contains two interleaved classes boost::complex and
boost::imaginary which can be instantiated with any type T provided T
overloads the usual arithmetic operators and some basic (real)
mathematical functions depending on which complex function will be
used. It is thus an extended version of Thorsten Ottosen's n1869
proposal
(http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1869.html)

Performance tests show some non-negligible speed-ups compared to
std::complex for calculations where pure imaginary numbers are involved.
A speed-up of 25% has been observed when solving the Schroedinger
equation explicitly on a regular mesh and some comparable figures can be
observed when computing the Mandelbrot set (the two examples snippets
provided in the archive).
Furthermore, the functions (sin(), exp(), log(),...) involving
boost::imaginary numbers are more precise than their equivalent using a
std::complex with the real part set to 0.

The code and (doxygen) documentation is available in the repository
http://code.google.com/p/cpp-imaginary-numbers/
A comprehensive zip archive can be found in the "download" and the code
can also be checked-out via the SVN repository.
The archive contains the class header, two examples, a comprehensive
precision test, a brute-force performance test and the documentation.

I'd be happy to answer any question from your side and to provide more
detailed information if required.

Regards,

Matthieu

-- 
Matthieu Schaller
PhD student - Durham University

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