	.TITLE	ATAN2 ARCTANGENT FOR REAL ARGUMENTS (ATAN(A1/A2))
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/COPYRIGHT 1973 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/EDIT #8  25 MAY 73   T.A. MURRAY
/
/FOR HARDWARE FPP VERSION, DEFINE  %FPP=0
/
	.GLOBL	ATAN2,.DA,.ED,.ER
/
	.IFUND	%FPP
/
	.GLOBL	.AB,.AG,.AL,.AI,.AJ
/
	.DEFIN	FLD%	/FLOATING LOAD (.AG)
	JMS*	.AG
	.ENDM
	.DEFIN	FDV%	/FLOATING DIVIDE (.AL)
	JMS*	.AL
	.ENDM
	.DEFIN	FAD%	/FLOATING ADD (.AI)
	JMS*	.AI
	.ENDM
	.DEFIN	FSB%	/FLOATING SUBTRACT (.AJ)
	JMS*	.AJ
	.ENDM
/
	.ENDC
/
/
	.IFDEF	%FPP
/
BPA=716604
BMA=716602
BZA=716601
BNA=716610
/
FLD=713050
	.DEFIN	FLD%	/FPP FLOATING LOAD
	FLD
	.ENDM
FDV=712040
	.DEFIN	FDV%	/FPP FLOATING DIVIDE
	FDV
	.ENDM
FAD=716040
	.DEFIN	FAD%	/FPP FLOATING ADD
	FAD
	.ENDM
FSB=710440
	.DEFIN	FSB%	/FPP FLOATING SUBTRACT
	FSB
	.ENDM
/
	.ENDC
/CALLING SEQUENCE
/	JMS*	ATAN2
/	JMP	.+3	RETURN POINT
/	.DSA	ARG1[+400000]  ADDR OR ARG 1
/	.DSA	ARG2[+400000]  ADDR OF ARG 2
/
/
ATAN2	0		/ENTRY POINT
	JMS*	.DA	/SET UP ARGUMENT ADDRESSES
	JMP	ATN203	/JUMP AROUND ARGUMENT LIST
ATN201	0		/ARG 1
ATN202	0		/ARG 2
/
ATN203	FLD%		/LOAD ARGUMENT 1
	.DSA	ATN201+400000
	LAC	ATN202	/BEFORE PROCEEDING, CHECK IF THE DENOMINATOR OF 
	DAC	ATN205	/RATIO ARG1/ARG2 IS ZERO.  CHECK THE MOST SIG-
	ISZ	ATN205	/NIFICANT BITS OF ARG2
	LAC*	ATN205
	SZA
	JMP	ATN206	/(ARG2 NOT ZERO)
	.IFUND	%FPP	/WHEN ARG2 IS ZERO, THE VALUE PI/2 IS RETURNED
	LAC*	.AB	/IF ARG1 IS POSITIVE, AND -PI/2 IS RETURNED IF
	SMA		/ARG1 IS NEGATIVE
	JMP	ATN209
	.ENDC
	.IFDEF	%FPP
	BPA!BZA
	ATN209
	.ENDC
	FLD%		/LOAD -PI/2
	.DSA	ATN208
	JMP*	ATAN2	/..AND EXIT
/
ATN209=.
	.IFUND	%FPP	/CHECK FOR SPECIAL CONDITION OF ATAN 0/0
	SZA		/WHICH IS UNDEFINED.  SIGNAL OTS 16, AND RETURN 
	JMP	.+3	/WITH ARBITRARY VALUE OF +PI/2
	.ENDC
	.IFDEF	%FPP
	BNA
	.+3
	.ENDC
	JMS*	.ER
	.DSA	400016	/ERROR IS RECOVERABLE
	FLD%		/LOAD +PI/2
	.DSA	ATN207	/...AND EXIT.
	JMP*	ATAN2
ATN206	FDV%		/IN NON-EXCEPTIONAL CASES, DIVIDE ARG1 BY ARG2,
	.DSA	ATN202+400000	/AND USE .ED TO COMPUTE ARCTANGENT
	JMS*	.ED	/THE VALUE RETURNED IS IN THE INTERVAL
	LAC*	ATN205	/  -PI/2 TO PI/2.  IF THE SIGN OF ARG2 IS POSITIVE
	SMA		/THEN THE ANGLE IS CORRECTLY IN THE FIRST OR
	JMP*	ATAN2	/FOURTH QUADRANT, AND THE ANSWER IS OK AS IS.
	.IFUND	%FPP	/OTHERWISE WHEN ARG2 IA NEGATIVE AND THE ANSWER 
	LAC*	.AB	/POSITIVE, THEN THE CORRECTED ANSWER IS IN THE 3RD 
	SPA		/QUADRANT.  ELSE WHEN ARG2 IS NEGATIVE
	JMP	.+4	/AND THE PRINCIPLE INTERVAL IS NEGATIVE,
	.ENDC		/THE ADJUSTED ANGLE IS IN THE SECOND QUADRANT.
	.IFDEF	%FPP
	BMA
	.+4
	.ENDC
	FSB%		/SUBTRACT PI TO ADJUST TO 3RD QUADRANT
	.DSA	ATN204
	JMP*	ATAN2
	FAD%		/ADD PI TO ADJUST TO 2ND QUADRANT
	.DSA	ATN204
	JMP*	ATAN2
/
ATN204	553002		/PI
	311037
ATN205	0		/ADDRESS OF MSB OF ARG 2
ATN207	553001		/PI/2
	311037
ATN208	553001		/ -PI/2
	711037
	.END
