/
/
/
/	A  T  A  N  2
/	-  -  -  -  -
/
/SUBROUTINE	ATAN2(Y,X)
/
/ VERSION 5A 4-27-77  PT
/
	SECT	ATAN2
	JA	#ATAN2
	TEXT	+ATAN2 +
ATN2XR,	SETX	XRATN2
	SETB	BPATN2
BPATN2,	FNOP
	0
	0
XRATN2,	F 0.0
YCOR,	F 0.0
XCOR,	F 0.0
FPIAT2,	2		/PI
	3110
	3755
ATPI,	F 1.570796		/PI/2
	ORG	10*3+BPATN2
	FNOP
	JA	ATN2XR
	0
AT2RTN,	JA	.
	BASE	0
#ATAN2,	STARTD
	FLDA	10*3
	FSTA	AT2RTN
	FLDA	0
	SETX	XRATN2
	SETB	BPATN2
	BASE	BPATN2
	LDX	1,1
	FSTA	BPATN2
	FLDA%	BPATN2,1	/ADDR OF Y
	FSTA	YCOR
	FLDA%	BPATN2,1+	/ADDR OF X
	FSTA	XCOR
	STARTF
	FLDA%	YCOR		/GET Y - THE TAN
	FSTA	YCOR		/SAV FOR A SECOND
	LDX	1,2		/POSITIVE X
	JEQ	ATN0
	JGT	ATN1
	LDX	0,2
ATN1,	FLDA%	XCOR		/GET X - THE QUADRAND
	FSTA	XCOR		/+MOVE IT TO A SAFE PLACE
	JEQ	ATASP
	FLDA	YCOR		/Y/X
	FDIV	XCOR
	FSTA	YCOR
	EXTERN	ATAN
	JSR	ATAN		/CALL ATAN
	JA	.+4		/TAKE ARCTAN OF Y/X
	JA	YCOR
	FSTA	YCOR		/SAVE IT AWAY
	JGE	A2		/SKIP IF 1 OR 3 Q
	FADD	FPIAT2		/ADD PI FOR 4TH Q
	FSTA	YCOR
A2,	JXN	AT2RTN,2
	FLDA	YCOR
	FSUB	FPIAT2		/SUB PI FOR 2ND+3RD QUADS
	JA	AT2RTN
ATASP,	FLDA	ATPI		/X=0 MEANS +-PI/2
	JXN	ATNG,2
	FNEG
ATNG,	JA	AT2RTN
ATN0,	FLDA%	XCOR
	JLT	POSX		/IF X POS,ANS IS 0
	FCLA
	JA	AT2RTN
POSX,	FLDA	FPIAT2		/OTHERWISE,ANS IS PI
	JA	AT2RTN
