C++ Variable Types
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
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement