[Developers] Re: [Aeidevelopment] CVS: "AEIDevelopment/ADMMass/src volume_integral.c"

Jonathan Thornburg jthorn at aei.mpg.de
Thu Oct 6 04:51:28 CDT 2005


[[how to get $\pi$ as a compile-time constant in C code]]

I suggested
| Why not just use M_PI (defined by <math.h>, which you've already 
| included)?
| Are there systems whose <math.h> doesn't define M_PI?

On Thu, 6 Oct 2005, Frank Loeffler wrote:
> Concerning this, and probably an error of mine: Lately I tries to compile 
> Cactus with gcc4.0.1, and the option std=c99. This resulted in an undefined 
> M_PI, even if math.h was included. Do you know why?

I should have checked the FAQ.  Quoting from
   http://www.eskimo.com/~scs/C-faq/q14.8.html
: Question 14.8
: 
: The pre-#defined constant M_PI seems to be missing from my machine's copy
: of <math.h>.
: 
: That constant (which is apparently supposed to be the value of pi, accurate
: to the machine's precision), is not standard. If you need pi, you'll have
: to #define it yourself.
: 
: References: PCS Sec. 13 p. 237

The reference points to
   Mark R. Horton, Portable C Software, Prentice Hall, 1990, ISBN 0-13-868050-7.

So apparently M_PI is just a "common extension", not part of the C
standard.  So... gcc 4.* tries to be more standard-conforming, and
evidently in C99 mode it's trying to avoid tromping on the user namespace
with macros like M_PI.

There's always 4.0*atan(1.0).

ciao,

-- 
-- Jonathan Thornburg <jthorn at aei.mpg.de>
    Max-Planck-Institut fuer Gravitationsphysik (Albert-Einstein-Institut),
    Golm, Germany, "Old Europe"     http://www.aei.mpg.de/~jthorn/home.html
    "Washing one's hands of the conflict between the powerful and the
     powerless means to side with the powerful, not to be neutral."
                                       -- quote by Freire / poster by Oxfam




More information about the Developers mailing list