dimanche 5 avril 2015

Can't make C++ program use high enough precision


...
cout << setprecision(100) << pow((3+sqrt(5.0)),28) << endl;
...


outputs



135565048129406451712


which isn't precise enough but.



$ bc <<< "scale = 100; (3+sqrt(5.0))^28"


outputs



135565048129406369791.9994684648068789538123313610677119237534230237579838585720347675878761558402979025019238688523799354


which is what I want. I'm setting the cout precision so it must be the sqrt, pow or + are losing the precision?


Aucun commentaire:

Enregistrer un commentaire