06/16/2008 11:09 AM
post9192
|
Hi,
I believe there might be a bug in libm. "pow(x,2.0)" gives incorrect results for very small x.
The following program gives incorrect results for double pow(double,double), but correct
results for pow(double,int).
#include <cmath>
#include <iostream>
using namespace std;
int main(int argc,char**argv)
{
double dz=+1e-170;
cout<<"dz= "<<dz<<endl;
cout<<"pow(dz,2.0)= "<<pow(dz,2.0)<<endl;
cout<<"pow(dz,2)= "<<pow(dz,2)<<endl;
return EXIT_SUCCESS;
}
If compiled with " QCC -o foo foo.cpp -lm" the output is:
dz= 1e-170
pow(dz,2.0)= inf
pow(dz,2)= 0
Am I doing something wrong and if not, is there a known workaround?
Thanks,
Thomas Buschmann
|
|
|