Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!oberon!sm.unisys.com!csun!solaria!ecphssrw@afws.csun.edu From: ecphssrw@afws.csun.edu (Stephen Walton) Newsgroups: comp.sys.amiga Subject: Re: atan2 sources (clarification) Summary: Here's one, and it wasn't hard to write. Message-ID: <495@solaria.csun.edu> Date: 23 Feb 89 21:44:08 GMT References: <1991@pur-phy> Sender: ecphssrw@solaria.csun.edu Reply-To: ecphssrw@afws.csun.edu (Stephen Walton) Organization: California State Univ., Northridge Lines: 34 In-reply-to: murphy@pur-phy (William J. Murphy) This took about ten minutes, counting testing. Based on the manual entry for Microsoft C's atan2 (which is all I had around), but the code itself is entirely PD (in fact, I just wrote and tested it against the system atan2()). /* myatan2 */ #include #include #include #define PI 3.14159265359 extern int errno; double myatan2(y, x) double y, x; { double atan(); if (x == 0.0) { if (y == 0.0) { errno = EDOM; fputs("atan2: DOMAIN error\n", stderr); return(0.0); } else if (y > 0.0) return(PI/2.0); else return(-PI/2.0); } else if (x > 0) return(atan(y/x)); else if (y >= 0.0) return(atan(y/x) + PI); else return(atan(y/x) - PI); }