Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: •Re: Re: Deriving pi and e

by tilly (Archbishop)
on Oct 25, 2003 at 13:52 UTC ( [id://302061] : note . print w/replies, xml ) Need Help??

in reply to •Re: Re: Deriving pi and e
in thread Deriving pi and e

Personally I do it for the reason that theorbtwo stated. I know how to do it with atan (and make the well-known power series converge), and the easiest way is to do 45 degrees and multiply by 4. Then I try to convert it to Perl, notice that there is no atan function, and use atan2.

That said, noting that I can do it directly with atan2 won't convince me not to reach for 4*atan2(1,1) for several reasons:

  1. I don't have this memorized, just the derivation of how it should work. I have more years of math than Perl, and so the derivation I know is the one that comes up immediately.
  2. Perl's documentation doesn't indicate whether atan(0,-1) will give you PI or -PI (or blow up because someone decided that "in the range of -PI to PI" means an open interval, not a half-closed one). I therefore don't know whether to trust it in future implementations of Perl.
  3. Even though I have had it pointed out to me that Perl's implementation gives you PI, I don't know whether I can trust that trivia in future implementations of atan2 that I may encounter in other languages. This goes doubly because I know enough about how one might try to implement atan2 to come up with plausible implementations which break at (0,-1).

Replies are listed 'Best First'.
Re: Re: o Re: Re: Deriving pi and e
by ambrus (Abbot) on Nov 02, 2003 at 17:36 UTC

    I agree. Actually, it's imo better to define atan2(0,-1)=-Pi, so that atan2's range would be [-Pi,Pi), not (-Pi,Pi] (not that this would matter at all). Actually, even my prof at complex functions course defined it this way: log(-1)=-i*Pi.

    I use 4*atan2(1,1) instead of atan2(0,-1) or 2*atan2(1,0), because I got used to bc and basic, where you have to write 4*a(1), and 4*atn(1) resp., because there is no atan2 function.