www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/06/18/13:30:09

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: M_PI and -ansi
Date: 18 Jun 2001 17:21:09 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 22
Message-ID: <9glda5$e5s$1@nets3.rz.RWTH-Aachen.DE>
References: <TMoX6.1671$Ug2 DOT 550858 AT carnaval DOT risq DOT qc DOT ca>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 992884869 14524 137.226.32.75 (18 Jun 2001 17:21:09 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 18 Jun 2001 17:21:09 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Patrick Mitran <pmitran AT tsp DOT ece DOT mcgill DOT ca> wrote:
> Hi,

> when I compile with the -ansi switch, it seems that I don't have a
> predefined constant for PI in math.h.

As the old saying goes: "Well, don't do that, then!". In this case:
don't use -ansi unless you positively have to.

> What would be a good way of getting a numerically accurate value of
> PI that is ANSI compliant?

#include <math.h>

const double pi = 4*atan(1.0);

That's about as portable as it gets, and as numerically accurate as
anything else you'll be doing in the same instance of the program,
using the same C math library implementation.
-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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