C++ Variable Types

Started by
3 comments, last by PulsarSL 18 years, 8 months ago
Hey, I wrote this program to compute pi, but it's not of much value unless I can get more than 5 decimal places (all my result turns out to be 5, even though I used long doubles [supposed to have 19 decimal places??]). Am I doing something wrong with my source? If you run it, use at least 100,000 cycles, without screen drawing. Thanks, PulsarSL source + binary: http://rapidshare.de/files/4481396/main.zip.html
Advertisement
All you need to do is insert the line "cout.precision(19);" before you print the result. Cout by default truncates floats to whatever number of decimal places it defaults to.
Quote:Original post by stro
All you need to do is insert the line "cout.precision(19);" before you print the result. Cout by default truncates floats to whatever number of decimal places it defaults to.


Thanks, works perfectly!

Let me ask one more question, though. Is there any way I can either a)increase the number of decimal digits, or b) define some sort of custom variable type that allows more decimial digits than 19?

PulsarSL
Download a multiprecision library. A quick web search should provide you with several options.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Fruny
Download a multiprecision library. A quick web search should provide you with several options.


Thanks

This topic is closed to new replies.

Advertisement