problem with complex functions

View: New views
2 Messages — Rating Filter:   Alert me  

problem with complex functions

by Bugzilla from daniel.barna@cern.ch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Running the attached simple program results in the output
(11616.5,0)
which is obviously wrong. If I uncomment the function declarations,
everything is fine: (0.707107,0.707107)
This means there is something wrong with the sqrt(complex<double>)
function in cint.
My version is: 5.16.29
Thanks
Daniel

#include <complex>
#include <cmath>


/*
template <class T>
T abs(const complex<T> &a)
{
    return sqrt(a.real()*a.real() + a.imag()*a.imag());
}

template <class T>
T phase(const complex<T> &a)
{
    return atan2(a.imag(), a.real());
}

template <class T>
complex<T> sqrt(const complex<T> &a)
{
    const T amp = abs(a);
    const T pha = phase(a);
    complex<T> result(sqrt(amp)*cos(pha/2),sqrt(amp)*sin(pha/2));
    return result;
}
*/

int main()
{
    complex<double> a(0,1);
    complex<double> b = sqrt(a);
    cerr<<b<<endl;
    return 0;
}

Re: problem with complex functions

by Axel Naumann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Daniel,

Thanks for letting us know! It's simply not implemented (and due to a
bug in CINT wrt conversions it somehow succeeds in calling a wrong
overload). I'll implement it next week and let you know.

Cheers, Axel.

On 2009-03-05 11:08, daniel.barna@... wrote:

> Hi,
> Running the attached simple program results in the output
> (11616.5,0)
> which is obviously wrong. If I uncomment the function declarations,
> everything is fine: (0.707107,0.707107)
> This means there is something wrong with the sqrt(complex<double>)
> function in cint.
> My version is: 5.16.29
> Thanks
> Daniel