By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

scientific computation

P: n/a
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.

Sep 25 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Wing wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 25 '06 #2

P: n/a
Wing wrote:
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.
Sep 25 '06 #3

P: n/a
Jacek Dziedzic <jacek@no_spam.tygrys.no_spam.netwrote:
Wing wrote:
>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".
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/?m...its::digits10).

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Sep 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.