S
sergio
hi, i've been proggraming for years, and have no ideia what the bug is
in this simple code, does someone has a clue? I'm including all the
code (20 lines).
the output is:
2
2
3
3
instead of the expected:
3
3
3
3
#include <iostream.h>
#include <math.h>
template <class T>
T f(T index,T N)
{
double t=(log(8)/log(2));
//at this point of the code t=3, but after the cast it turns to
2!
return (T)t;
}
int main()
{
cout<<f<int>(8,2)<<endl;
cout<<f<short>(8,2)<<endl;
cout<<f<float>(8,2)<<endl;
cout<<f<double>(8,2)<<endl;
return 0;
}
thanks for any help
in this simple code, does someone has a clue? I'm including all the
code (20 lines).
the output is:
2
2
3
3
instead of the expected:
3
3
3
3
#include <iostream.h>
#include <math.h>
template <class T>
T f(T index,T N)
{
double t=(log(8)/log(2));
//at this point of the code t=3, but after the cast it turns to
2!
return (T)t;
}
int main()
{
cout<<f<int>(8,2)<<endl;
cout<<f<short>(8,2)<<endl;
cout<<f<float>(8,2)<<endl;
cout<<f<double>(8,2)<<endl;
return 0;
}
thanks for any help