From 4599762451426027659
X-Google-Thread: f78e5,4ba9dcb1ae436e16
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: pfefferd@hotmail.co.il.nospam ("Daniel Pfeffer")
Newsgroups: comp.std.c++
Subject: Re: Pi, Euler Number, and perhaps other 'natural' constants?
Date: Tue, 27 Jul 2004 16:01:12 GMT
Organization: INTERNET-ZAHAV
Lines: 53
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <ce5ais$f50$1@news.inter.net.il>
References: <5cydnSisJNo4yJncRVn-sQ@speakeasy.net>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1090944077 10671 158.152.254.254 (27 Jul 2004 16:01:17 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Tue, 27 Jul 2004 16:01:17 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
X-Priority: 3
X-Spam-Checker-Version: SpamAssassin 2.60-mulga_r1 (1.212-2003-09-23-exp) on 
	mulga.cs.mu.OZ.AU
X-Spam-Status: No, hits=-3.0 required=5.2 tests=AWL,BAYES_00,PRIORITY_NO_NAME 
	autolearn=no version=2.60-mulga_r1
X-MSMail-Priority: Normal
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i6RG1CWZ005184;
	Wed, 28 Jul 2004 02:01:12 +1000 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-NNTP-Posting-Date: Tue, 27 Jul 2004 10:25:32 +0000 (UTC)
X-Spam-Level: 
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:1465

"Steven T. Hatton" <hattons@globalsymmetry.com> wrote in message
news:5cydnSisJNo4yJncRVn-sQ@speakeasy.net...
> I was a bit surprised that the Standard does not specify that the constant
> Pi be part of an implementation. It seems like an obvious feature to want
> in a programming language. The Euler Number would also be nice, but not
> nearly as desirable as Pi.  Sure there are questions of how to handle the
> difference between a float and a double Pi, but I'm (almost) sure that
> isn't a big obstacle.
>
> I've found ways to jump though hoops to get Pi defined by using
> transcendental functions provided in the Standard Library, but that seems
a
> bit convoluted to me.  Is there a reason Pi is missing from C++?

While I cannot speak for the Standards committee, a few reasons occur to me:

Given
    pi - the mathematical infinitely precise value
    PI - the limited machine representation
    ulp - unit in last position - the smallest difference between adjacent
floating point numbers

1. Should PI be provided for every supported floating-point format?
2. To what precision should PI be provided?
3. How should PI be rounded? note that std::atan(pi-ulp) is a large positive
number, while std::atan(pi+ulp) would be a (different) large negative
number. The second choice may cause problems if atan(pi) is assumed to be
positive.

All in all, I believe that it is better to let each application determine
the answers to these questions. For serious numerical work, the required
machine representation of PI must be determined for each floating-point
implementation. For most engineering and many scientific uses, calculation
of PI to 12 digits (or less, in many cases) would be more than sufficient.
For the rest of us, 355/113 or even 22/7 are probably accurate enough. :-)

As you have discovered, a good way to calculate PI at close to machine
precision is to define functions as follows:

inline float PI_f() { return 4.0f*std::atan(1.0f); }
inline float PI() { return 4.0*std::atan(1.0); }
inline float PI_l() { return 4.0l*std::atan(1.0l); }


Daniel Pfeffer


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



