in reply to Lissajous curves

I always chuckle at:
sub pie() { 2 * atan2(1, 0); }
as in "compute pi/2, then double it", instead of just computing pi directly:
sub pi () { atan2(0, -1); }

Replies are listed 'Best First'.
Re^2: Lissajous curves
by ambrus (Abbot) on Jun 14, 2007 at 15:58 UTC

    Sure you can, but atan2 has a branch cut there so you have to know that it returns pi, not minus pi which would also make sense to me (though the IEEE 754 committee might have had a reason).

    Update 2011-04-18: in fact, appendix F of the C99 standard states that atan2 with zero first argument and negative second argument gives pi with the sign copied from the zero. This guarantees that atan2(-1,0) must return positive pi. You can see that indeed perl will give negative pi for a negative zero first argument:

    $ perl -wE '$x = -1; $x/=2 for 1..9999; $,=" "; say $x, atan2($x,-1), +atan2(0,-1);' -0 -3.14159265358979 3.14159265358979