Mail Archives: djgpp/1998/12/18/10:41:08
It's almost always best to use a constant. If all else fails, cut and paste
the #define PI from math.h and put it into your program. There was a
discussion a few months ago on a NG about the value of PI. And I quote (It may
be somewhat paraphrased) "Leave PI a constant as God intended."
You _can't_ count on the accuracy or precision of trig functions.
And if you do want to get PI from an equation (which I don't suggest) it's
easier to take acos(-1.0), rather than 4 * atan(1.0).
dj-admin AT delorie DOT com wrote:
A better way would be to calculate pi once by eg
double pi = 4 * atan(1.0);
it should give you pi in a precision suitable for the
math library.
Just my two cents ..
Anton Helm wrote:
>
> At 18:27 17.12.98 +0000, Arthur wrote:
>
> >I think in math.h, there is a definition called PI. This is much more
> >accurate than what you've got here.
> >
> >So you can use sin(x*PI/180); instead (easier).
> >
>
> PI is not ANSI (checked) and as far as I know
> it isn't POSIX either (unchecked).
>
> So if you want a portable code you should
> have a
>
> #ifndef PI
> #define PI 3.1415.....
> #endif
>
> somewhere (well, preferably in a *.h file) in your program.
>
> Although PI and M_PI are #defined on lots of systems you
> can't rely on them.
>
> Tony
____________________________________________________________________
Get free e-mail and a permanent address at http://www.netaddress.com/?N=1
- Raw text -