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.
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