I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

Help on c++ (how to round correctly the pi value)

will\′s Photo
10 May 09, 2:30PM
Help on c++ (how to round correctly the pi value)
Hi, I've a couple of comments:
  • digits variable isn't used by the series approximation. You get exactly the same value regardless of digits.
  • In you final code you've used series 1; where as in the example usage you enter series 2.
  • Pasting in your previous code for series 2, I get: 3.141592644041437 this is accurate to 7 significant digits.
  • What is a 'long float', isn't that a 'double'. Either way gcc doesn't like it so I would avoid using them.

On a more general point. Why do I keep finding people trying to calculate PI ! There are a number of good algorithms out there that evaluate it to thousands of digits. In deed there are whole books writing out PI. I suggest a quick read of Numerical Recipes

One further comment
cout << PI
Will only output to 5 significant digits, you therefore need something like
cout << setprecision(16);
cout << PI
Currently you need to be logged in to leave a message.