#### Archived

This topic is now archived and is closed to further replies.

# a number for pi

This topic is 5741 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hey, i have a program where i have to convert radians to degrees. In order to do that i have to divide by pi. Instead of using the inaccurate 3.14 is there a known function or variable for pi? thanks, JYoung

##### Share on other sites
There are a number of ways of calculating PI at runtime, such as 4*atan(1). The thing is floating point numbers don''t have a huge accuracy (around 7 digits for single precision and 15 digits for double precision), so 3.14159 or something similar is usually accurate enough for typical use.

##### Share on other sites
Assuming you're using C/C++, it is pretty standard for all C/C++ compilers to have a define for pi, called M_PI, defined in math.h, so:

#include <math.h>

And then just use M_PI

eg:

double pi = M_PI;

Unless you need pi to a ridiculous number of decimal points (more than a double can hold), this works fine and is easily understood.

[edited by - gmcbay on February 7, 2003 1:32:51 PM]

##### Share on other sites
I tend to grab it & #define it from windows calculator...or any calculator I can get my hands on!

##### Share on other sites
double Pi = M_PI;

C:\Program Files\Microsoft Visual Studio\VC98\OpenGL\TheGrapher\main.cpp(81) : error C2065: 'M_PI' : undeclared identifier

[edited by - JYoung on February 7, 2003 3:47:49 PM]

##### Share on other sites
Check math.h, you have to #define some macro in MSVC to make M_PI and various other constants available.

##### Share on other sites
#define my_PI 3.1415926535897932384626433832795

and you are good to go.

____________________________________________________________
Try RealityRift at www.planetrift.com
Feel free to comment, object, laugh at or agree to this. I won''t engage in flaming because of what I have said.
I could be wrong or right but the ideas are mine.

##### Share on other sites
Here is some more digits if you care. Of course, it all depends on the resolution on your platform.

const long double gPI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647094;

##### Share on other sites
Sooooooo.....

if you are not satisfied with one million digits...
And you laugh at 2 million digits..
and 3 million make you yawn..
and you think 4 million digits are for girls...
..and so on...

http://www.hepl.phys.nagoya-u.ac.jp/%7Emitsuru/pi-e.html

that should satisfy even the toughest...

Wow!

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633388
• Total Posts
3011617
• ### Who's Online (See full list)

There are no registered users currently online

×