6
I have this program:
int main(){
double x=2;
cout << sqrt(x);
}
I would like to show the result as accurately as possible. Thank you!
6
I have this program:
int main(){
double x=2;
cout << sqrt(x);
}
I would like to show the result as accurately as possible. Thank you!
7
Utilizes setprecision
in this way:
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits> // Para ter a máxima precisão
using namespace std;
int main(){
double x=2;
cout << setprecision(numeric_limits<double>::max_digits10) << sqrt(x);
}
6
You can do it like this:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double num = sqrt(2);
cout << fixed;
cout.precision(52);
cout << num << endl;
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
One question, whether the 2008 IEEE 754 standard, which defines the representation of double-precision floating-point numbers (64 bits), provides a relative accuracy of about 16 decimal digits and a magnitude range of 10 -308 to 10 +308, where does this number come from? For greater precision it would not be necessary to use one of the libraries that implement arbitrary precision decimal number representations (e.g., GMP - The GNU Multiple Precision Arithmetic Library ) and not the double data type?
Browser other questions tagged c++ mathematics
You are not signed in. Login or sign up in order to post.
It works. But is there any way to get the maximum precision?
– Aleph Zero
@Alephzero Yes, there is. You have to use numeric_limits<double>. I’ve already edited.
– Alexandre Cartaxo