Class Templates + Me = Frustration

I've written a class template for complex numbers, which has two private data members (real and imaginary parts) - in this program they are either ints or doubles. I have a piece of code which works fine for doubles:

template <class T>
double complex<T>::arg() const{
T i(im), j(re);
double x = i/j;
return std::atan(x);

}

, but for integers it keeps returning the inverse tangent of the nearest integer, instead of the actual ratio between the two. Help me Obi-Wan Kenobis, you're my only hopes.

Cheers
1
2
T i(im), j(re);
double x = i/j;  


You are doing integer arithmetic when T is type int - that is truncation of im and re in T i(im), j(re); if im and re are always doubles (i.e not dependent on T), and loss of precision in i/j
Ah, ok, I've declared i and j as doubles and that's worked. Thanks a lot
Topic archived. No new replies allowed.