Boost logo

Boost :

Subject: Re: [boost] Determining interest: Pure imaginary number library
From: Grizzly(Francis Smit) (grizzly_at_[hidden])
Date: 2011-11-17 00:41:49


Interesting stuff but I found some minor problems with the code
1). in Imaginary.hpp on lines 293,300
*
/// Returns the value of x divided by y
template<typename T>
inline Imaginary<T> operator/(const T& x, const Imaginary<T>& y)
{
     Imaginary<T> r = y;
     r /= x;
     return r;
}

*as you can see there is an error in this we should be calculating x/y
but instead y/x is calculated it should be
Imaginary<T>(-x/y.imag()) i.e. x/(0 + y.imag()**/I/*) ==
x*(-*/i/*)/y.imag()

2). some of the comments are wrong in the cases of operator!=() on lines
383 & 390 & 397 & 404 & 411 it says

///Returns true if x equals y

of course it should say true if x does not equal y no doubt you forgot
to change them after cut/copy & paste thats how I make those sort of errors

those are the only errors I found, simply beautiful code and very handy
they should add it to the STL love your work

Francis Grizzly Smit

On 16/11/11 10:40, Matthieu Schaller wrote:
> Dear all,
>
> I have recently been playing a lot on numerical analysis problems
> containing complex numbers and functions. I have been using the SL
> std::complex<> library and could observe that some of the algorithms
> weren't optimized in cases where complex numbers have to be multiplied by
> pure imaginary numbers (i.e. x*sqrt(-1)). I have implemented a class to
> represent these numbers and overloaded all relevant operators in a more
> optimized fashion thanks to the knowledge that the real part of these
> complex numbers is 0. I could observe an important speed-up in some
> calculations. As an example, this piece of code (1D Schroedinger equation
> using finite differences):
>
> for(size_t i(0); i<nbPoints; ++i)
> {
> Psi_new[i] = Psi_old[i]
> + ii * hbar * deltaT / (12.*m*deltaX*deltaX) *
> (-Psi_cur[i-2] + 16.*Psi_cur[i-1] - 30.*Psi_cur[i] + 16.*Psi_cur[i+1] -
> Psi_cur[i+2])
> - 2. * ii * V(x[i]) / hbar * deltaT * Psi_cur[i];
>
> }
>
> is more than 2 times faster (g++ 4.6.1 core i7 2820QM) when the imaginary
> unit (constant) variable ii is defined to be
>
> Imaginary<double> ii(1.);
>
> than when it is defined as
>
> std::complex<double> ii(0.,1.);
>
> Some other expressions also benefit from this improvement and can run
> faster. Expressions including square roots or exponentials of pure
> imaginary numbers are improved a lot.
>
> The range of application of such a class is quite narrow but it may be
> helpful to speed-up some simple numerical problems. The source code as well
> as a working example is available here:
> http://code.google.com/p/cpp-imaginary-numbers/
>
> Thanks,
>
> Matthieu
>
> _______________________________________________
> Unsubscribe& other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


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