scientific computation

W

Wing

Hello eveyone,

I am programming some scientific computation based on C++. I would like
to set every output/input (e.g. cout, io file stream) to be a high
precision.

What C++ command should I use?

Thanks so much.
 
V

Victor Bazarov

Wing said:
I am programming some scientific computation based on C++. I would
like to set every output/input (e.g. cout, io file stream) to be a
high precision.

What C++ command should I use?

You need to read about 'setprecision', my guess would be.

V
 
J

Jacek Dziedzic

Wing said:
Hello eveyone,

I am programming some scientific computation based on C++. I would like
to set every output/input (e.g. cout, io file stream) to be a high
precision.

What C++ command should I use?

First, #include<iomanip>.

Then choose fixed-point output (cout << fixed;)
or scientific-notation output (cout << scientific;).

Finally tell the output stream how many digits of precision
you require, eg. for 12 try

cout << setprecision(12);

That's basically it. For more details read up on "manipulators".

HTH,
- J.
 
M

Marcus Kwok

Jacek Dziedzic said:
First, #include<iomanip>.

Then choose fixed-point output (cout << fixed;)
or scientific-notation output (cout << scientific;).

Finally tell the output stream how many digits of precision
you require, eg. for 12 try

cout << setprecision(12);

That's basically it. For more details read up on "manipulators".

Also, the OP may want to investigate the use of
std::numeric_limits<T>::digits10 (requires #include <limits>), which
will give "the number of decimal digits that the type can represent
without change" (quote from Dinkumware documentation:
http://www.dinkumware.com/manuals/?manual=compleat&page=limits2.html#numeric_limits::digits10).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top