store pi O.o;

This is a discussion on store pi O.o; within the C++ Programming forums, part of the General Programming Boards category; Hi. I am making a program to find a circle's circumference. I want to use the longer pi ... but ...

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?

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.

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..

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:

> 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.

There's your problem right there!
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?

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.

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.)

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.)

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.