delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/04/03:29:59

Date: Wed, 4 Mar 1998 10:29:55 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Lawrence Kirby <fred AT genesis DOT demon DOT co DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: trigonometry problem (math.h)
In-Reply-To: <888961507snz@genesis.demon.co.uk>
Message-ID: <Pine.SUN.3.91.980304102936.6541C-100000@is>
MIME-Version: 1.0

On Tue, 3 Mar 1998, Lawrence Kirby wrote:

> >#include <math.h>     /* define M_PI and sin()       */
> 
> Note however that the C language does not permit a C compiler to define
> M_PI in <math.h>.

ANSI C doesn't define M_PI, but Posix does.  It certainly doesn't make
sense to roll your own value for PI if one is already available, since
defining accurate float constants can be tricky. 

All modern Unix compilers have this constant, and at least some DOS
ones (e.g., Borland C) do as well.  So I think it is safe to use,
perhaps with the following safeguard:

    #include <math.h>
    #ifndef M_PI
    #define M_PI 3.14159  /* use as many digits as you need */
    #endif

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019