1. ## store pi O.o;

Hi. I am making a program to find a circle's circumference. I want to use the longer pi ... but I dont know how to store all the digits in it. I can get some of them using float, but I like to have more ... like over 32m of em XD.I kinda knew that float wouldnt work fully, seeing as the money size would be way to larg to store it all at once. Anyone have a idea to maybe store all these digists?

Code:
```#include "c:\tt.h"

using namespace std;
int main(void)
{
float pi = 3.14159265358979323846264338327950288419716939937510;
cout<<"pi is "<<pi<<endl;
system("pause");
}```

2. The number of digits displayed is different than the number stored. You need to use io manipulators like setprecision to display more digits.

You should use a long double to store your pi value, since it has a greater precision and will hold the value more accurately than a float. I'm not sure even long double can store all of those digits. If you really need them all, you might need a separate number library.

3. im sure this has come up before, search either here or another search engine. i quickly seen a neat way of doing it, store it as a char array. since it would be a pain to type somethign like: char pi[] = {'3','.',etc',, id imagine it would be feasible with file i/o..

ie, save a file with the value of pi in it. write a seperate program to read in that file, char by char, and create an output file that would create the code for you.

example input file:
3.14etc

example output file:
char pi[] = {'3','.',... etc

you can then use this second file and paste it to your code... however the line would be incredibly long if you were to actually do it to 32m..

4. If you need to do calculations with it there are some arbitrary precision libraries floating around on the internet, Google for them if that's the case.

If you don't need to do any calculations with it, just use a character as someone said before, but you can just use a string:
Code:
`string pi="3.14159265358979323846264338327950288419716939937510";`

5. oh whoops thought this was C, good thinking.

im sure this has come up before, search either here or another search engine. i quickly seen a neat way of doing it, store it as a char array. since it would be a pain to type somethign like: char pi[] = {'3','.',etc',, id imagine it would be feasible with file i/o..

ie, save a file with the value of pi in it. write a seperate program to read in that file, char by char, and create an output file that would create the code for you.

example input file:
3.14etc

example output file:
char pi[] = {'3','.',... etc

you can then use this second file and paste it to your code... however the line would be incredibly long if you were to actually do it to 32m..

Neat idea ^.^ yea its all ready in a text file I made... XD Sorry, I didnt know what to totaly search for really so when I was looking for.

The number of digits displayed is different than the number stored. You need to use io manipulators like setprecision to display more digits.

You should use a long double to store your pi value, since it has a greater precision and will hold the value more accurately than a float. I'm not sure even long double can store all of those digits. If you really need them all, you might need a separate number library.
I think so too. I know the long double cant deal with them all either.

If you need to do calculations with it there are some arbitrary precision libraries floating around on the internet, Google for them if that's the case.

If you don't need to do any calculations with it, just use a character as someone said before, but you can just use a string:

Code:
string pi="3.14159265358979323846264338327950288419716939 937510";
Hmmm, I didnt think that O.o; but I thought string cant add like it would a int or something that deal with numbers.

7. >> but I thought string cant add like it would a int or something that deal with numbers.
Right, that's why a string or char array are not options if you need to do any calculations with it.

8. Yeah, I don't think he's looking just for the number pi, he wants to work with it.

As already mentioned, you're better off with an arbitrary precision library. There are many free ones.

9. Yea... I want to work with the numbersXD Sorry I missed read the string thing there, thought he was telling me that, that would work too. Yea I am looking up the precision library stuff.

10. > I think so too. I know the long double cant deal with them all either.
float.h defines constants like
FLT_DIG
DBL_DIG
LDBL_DIG
Which represent the number of decimal digits a float can store with any degree of accuracy.

For many implementations, FLT_DIG is 6 and DBL_DIG is 15.
Code:
```float pi = 3.14159265358979323846264338327950288419716939937510;
double pi = 3.14159265358979323846264338327950288419716939937510;```

I want to use the longer pi ...
You don't need more precision than that, you just want it, and for no good reason.

doubles are more than accurate enough for your every need, and anything more is just pointless until you can prove that doubles are insufficient, and I don't think you can. What could you possibly be doing with this circumference result that wouldn't work with doubles?
What are you REALLY trying to achieve here?

12. doubles are more than accurate enough for your every need, and anything more is just pointless until you can prove that doubles are insufficient, and I don't think you can. What could you possibly be doing with this circumference result that wouldn't work with doubles?
What are you REALLY trying to achieve here?
I am just running a test was all. Is that so wrong? Its no differnt then people making another C++ program that someone els has done befor; so what I am really trying to achieve is what I want to achieve. Lol, Yea ^^; I just want to see how much differnt would it be with more digits from pi then the stander 3.14.

Anyways, i've been looking on the net for a bit here and found many arbitrary precision library. Which one do you think is perty good; befor I start downloading them and find out they may not work for what I am trying to do or maybe not run for my compiler? I am using Dev-C++ ver. 4.9.9.2.

13. I just want to see how much differnt would it be with more digits from pi then the stander 3.14.
Not much. In real life the accuracy of measurement will be limited anyway. If you are able to measure the diameter with the accuracy of a millimeter, you can't expect to calculate the circumference to more decimal places. You'll just have to round off any places after millimeters.

So, if your base unit is metres 3.1416 would be all you need to find the circumference in mm. (If you have a circle with diameter 1 m exactly, the circumference rounded to millimeters will be 3.142. You need pi up to the 4th decimal place, so you can round the value properly to the 3rd decimal place. If you use a more accurate pi, the result after rounding will still be the same.)

14. Originally Posted by anon
Not much. In real life the accuracy of measurement will be limited anyway. If you are able to measure the diameter with the accuracy of a millimeter, you can't expect to calculate the circumference to more decimal places. You'll just have to round off any places after millimeters.

So, if your base unit is metres 3.1416 would be all you need to find the circumference in mm. (If you have a circle with diameter 1 m exactly, the circumference rounded to millimeters will be 3.142. You need pi up to the 4th decimal place, so you can round the value properly to the 3rd decimal place. If you use a more accurate pi, the result after rounding will still be the same.)
Hmm ^.^ ok, thanks for clearning that up.

15. Well, actually my explanation may be a little faulty. But still, using a more precise pi doesn't change the orders of magnitude, and for most purposes double would be enough. If you measure in kilometers, there's no point in calculating the circumference in centimeters etc.