473,396 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Does C++ have a standard symbol representing the value Pi?

I can get the accurate value of Pi to an arbitrary precision, but it would
be nice to have it directly and readily available as a standard feature of
the language. Have I overlooked something, or is it not there?

ISO/IEC14882:2003(E) offers me this:

template<class T> complex<T> log(const complex<T>& x);

"4 Notes: the branch cuts are along the negative real axis.
5 Returns: the complex natural (base e) logarithm of x, in the range of a
strip mathematically unbounded along the real axis and in the interval [-i
times pi, i times pi ] along the imaginary axis. When x is a negative real
number, imag(log(x)) is pi."

3.141592653589793238462643383279502884197169399375 1058209749445923078164062862\
08998628034825342117067982148086513282306647093844 6095505822317253594081284811\
17450284102701938521105559644622948954930381964428 8109756659334461284756482337\
86783165271201909145648566923460348610454326648213 39360726024914127
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #1
9 83591
* "Steven T. Hatton" <su******@setidava.kushan.aa> schriebt:

I can get the accurate value of Pi to an arbitrary precision, but it would
be nice to have it directly and readily available as a standard feature of
the language. Have I overlooked something, or is it not there?
It's not there in C (at least pre 1999), so it's not there in C++.

As a non-standard extension you might find M_PI in your <cmath>.

See <url: http://www.eskimo.com/~scs/C-faq/q14.8.html>.
ISO/IEC14882:2003(E) offers me this:

template<class T> complex<T> log(const complex<T>& x);

"4 Notes: the branch cuts are along the negative real axis.
5 Returns: the complex natural (base e) logarithm of x, in the range of a
strip mathematically unbounded along the real axis and in the interval [-i
times pi, i times pi ] along the imaginary axis. When x is a negative real
number, imag(log(x)) is pi."

3.141592653589793238462643383279502884197169399375 1058209749445923078164062862\
08998628034825342117067982148086513282306647093844 6095505822317253594081284811\
17450284102701938521105559644622948954930381964428 8109756659334461284756482337\
86783165271201909145648566923460348610454326648213 39360726024914127


Only a mathematician could have thunk of that! ;-)

Why not acos?

And btw., have you checked the digits after the twentieth? (I haven't,
but suspect garbage there.)

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
Hi,

pi is an "invinite" number. If you want do use pi within your program,
you have to define the precision yourself (depending on your
requirements). Have a look at analysis 1.

regards marbac
Jul 22 '05 #3
"Alf P. Steinbach" <al***@start.no> wrote
* "Steven T. Hatton" <su******@setidava.kushan.aa> schriebt:

I can get the accurate value of Pi to an arbitrary precision, but it would
be nice to have it directly and readily available as a standard feature of
the language. Have I overlooked something, or is it not there?


It's not there in C (at least pre 1999), so it's not there in C++.

As a non-standard extension you might find M_PI in your <cmath>.

See <url: http://www.eskimo.com/~scs/C-faq/q14.8.html>.
ISO/IEC14882:2003(E) offers me this:

template<class T> complex<T> log(const complex<T>& x);

"4 Notes: the branch cuts are along the negative real axis.
5 Returns: the complex natural (base e) logarithm of x, in the range of a
strip mathematically unbounded along the real axis and in the interval [-i
times pi, i times pi ] along the imaginary axis. When x is a negative real
number, imag(log(x)) is pi."

3.141592653589793238462643383279502884197169399375 1058209749445923078164062862\ 08998628034825342117067982148086513282306647093844 6095505822317253594081284811\ 17450284102701938521105559644622948954930381964428 8109756659334461284756482337\ 86783165271201909145648566923460348610454326648213 39360726024914127


Only a mathematician could have thunk of that! ;-)

Why not acos?

And btw., have you checked the digits after the twentieth? (I haven't,
but suspect garbage there.)


The digits are good, including proper rounding of the last 7. What good this
would do in the real world is certainly debatable.

Claudio Puviani
Jul 22 '05 #4
marbac wrote:
Hi,

pi is an "invinite" number.
Did you mean /infinite/? "Invinite" is not in any of the dictionaries I
queried, and it doesn't show on a google, except as a misspelling.
If you want do use pi within your program,
you have to define the precision yourself (depending on your
requirements).
There could almost certainly be a way to provide a standard representation
of Pi. There may be a need for a PI_d, and a PI_f, but I don't see why
there is a fundamental reason it could not be part of the standard.
Perhaps I should take this over to comp.std.c++.
Have a look at analysis 1.


I don't follow? Are you talking about "analysis" as in /real analysis/?
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #5
Claudio Puviani wrote:
The digits are good, including proper rounding of the last 7. What good this
would do in the real world is certainly debatable.


Haven't you seen the movie "Pi"? :))

- J.
Jul 22 '05 #6
"Jacek Dziedzic" <ja*************@janowo.net> wrote
Claudio Puviani wrote:
The digits are good, including proper rounding of the last 7.
What good this would do in the real world is certainly debatable.


Haven't you seen the movie "Pi"? :))


I haven't, but I intend to rent it some time. I wonder if it's a sequel to the
movie 'e': http://www.imdb.com/title/tt0132667/

;-)

Claudio Puviani
Jul 22 '05 #7
Claudio Puviani wrote:
"Jacek Dziedzic" <ja*************@janowo.net> wrote
Claudio Puviani wrote:
> The digits are good, including proper rounding of the last 7.
> What good this would do in the real world is certainly debatable.
Haven't you seen the movie "Pi"? :))


I haven't, but I intend to rent it some time. I wonder if it's a sequel to
the movie 'e': http://www.imdb.com/title/tt0132667/

;-)

Claudio Puviani


Then there's the sequel to Pi:

hattons@ljosalfr:~/code/c++/scratch/forward/
Wed Apr 28 17:58:06:> echo "N[Pi,600]" | math
Mathematica 5.0 for Linux
Copyright 1988-2003 Wolfram Research, Inc.
-- Motif graphics initialized --

In[1]:=
Out[1]=
3.141592653589793238462643383279502884197169399375 1058209749445923078\
16406286208998628034825342117067982148086513282306 6470938446095505822317\
25359408128481117450284102701938521105559644622948 9549303819644288109756\
65933446128475648233786783165271201909145648566923 4603486104543266482133\
93607260249141273724587006606315588174881520920962 8292540917153643678925\
90360011330530548820466521384146951941511609433057 2703657595919530921861\
17381932611793105118548074462379962749567351885752 7248912279381830119491\
29833673362440656643086021394946395224737190702179 8609437027705392171762\
9317675238467481846766940513


--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #8
On Wed, 28 Apr 2004 21:36:25 GMT, "Claudio Puviani" <pu*****@hotmail.com>
wrote:
"Jacek Dziedzic" <ja*************@janowo.net> wrote
Claudio Puviani wrote:
> The digits are good, including proper rounding of the last 7.
> What good this would do in the real world is certainly debatable.


Haven't you seen the movie "Pi"? :))


I haven't, but I intend to rent it some time. I wonder if it's a sequel to the
movie 'e': http://www.imdb.com/title/tt0132667/


Looks like the title of that movie is E, not e, so it probably isn't
related ;-)

As for Pi (the title is actually the Greek letter, but I can't figure out
how to insert it at all with Agent, let alone in a way that would allow
anyone else to read it...), if you suffer from migraines, like I do, you'll
/really/ relate to this movie... I'd put it up there somewhere with Repo
Man and Brazil (but not quite as good as either).
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #9

Did you mean /infinite/? "Invinite" is not in any of the dictionaries I
queried, and it doesn't show on a google, except as a misspelling.

Yes, i meant "infinite" (sorry, was a typing error)
There could almost certainly be a way to provide a standard representation
of Pi. There may be a need for a PI_d, and a PI_f, but I don't see why
there is a fundamental reason it could not be part of the standard.
Perhaps I should take this over to comp.std.c++.

Someone wrote it before, some constants are defined in math.h (cmath).
/* Some useful constants. */
#if defined __USE_BSD || defined __USE_XOPEN
# define M_E 2.7182818284590452354 /* e */
# define M_LOG2E 1.4426950408889634074 /* log_2 e */
# define M_LOG10E 0.43429448190325182765 /* log_10 e */
# define M_LN2 0.69314718055994530942 /* log_e 2 */
# define M_LN10 2.30258509299404568402 /* log_e 10 */
# define M_PI 3.14159265358979323846 /* pi */
# define M_PI_2 1.57079632679489661923 /* pi/2 */
# define M_PI_4 0.78539816339744830962 /* pi/4 */
# define M_1_PI 0.31830988618379067154 /* 1/pi */
# define M_2_PI 0.63661977236758134308 /* 2/pi */
# define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#endif

/* The above constants are not adequate for computation using `long
double's.
Therefore we provide as an extension constants with similar names as a
GNU extension. Provide enough digits for the 128-bit IEEE quad. */
#ifdef __USE_GNU
# define M_El 2.7182818284590452353602874713526625L /* e */
# define M_LOG2El 1.4426950408889634073599246810018921L /* log_2 e */
# define M_LOG10El 0.4342944819032518276511289189166051L /* log_10
e */
# define M_LN2l 0.6931471805599453094172321214581766L /* log_e 2 */
# define M_LN10l 2.3025850929940456840179914546843642L /* log_e
10 */
# define M_PIl 3.1415926535897932384626433832795029L /* pi */
# define M_PI_2l 1.5707963267948966192313216916397514L /* pi/2 */
# define M_PI_4l 0.7853981633974483096156608458198757L /* pi/4 */
# define M_1_PIl 0.3183098861837906715377675267450287L /* 1/pi */
# define M_2_PIl 0.6366197723675813430755350534900574L /* 2/pi */
# define M_2_SQRTPIl 1.1283791670955125738961589031215452L /*
2/sqrt(pi) */
# define M_SQRT2l 1.4142135623730950488016887242096981L /* sqrt(2) */
# define M_SQRT1_2l 0.7071067811865475244008443621048490L /*
1/sqrt(2) */
#endif


Have a look at analysis 1.

I don't follow? Are you talking about "analysis" as in /real analysis/?


whats an irrational number .. thats what i wanted to say.

It makes no sense if you define Pi with ..... lets say 50 digits (in
this case: base 10) if you not define a datatype in this range for all
your variables.

simple example: 2*pi*r ...... what is the accuracy of pi (example long
double) worth, if r (example float) is only of low accuracy?
regards marbac
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Timothy Madden | last post by:
Hello If I say #define MASK 0x00F0 #define BIT_SET MASK #define MASK 0x000F than what value will BIT_SET macro expand to ? I mean the preprocessor does lasy evaluation or immediate...
15
by: greenflame | last post by:
First of all I only have IE for testing. Ok. I have a script that is supposed to show, not evaluate, the indefinite integral of something. When I run the script it just craches IE. I have tried...
15
by: Claudio Grondi | last post by:
Let's consider a test source code given at the very end of this posting. The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in...
32
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
24
by: not_a_commie | last post by:
If you were going to hire a software architect / functional lead for your project (written exclusively in C# including WPF, WCF) would you require that they have UML skills? Is being able to...
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.