Jump to content
  • Advertisement

Archived

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

JYoung

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!