	.TITLE	DATAN2 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	DATAN2,.DA,.DD,.ER
/
	.IFUND	%FPP
/
	.GLOBL	.AB,.AO,.AT,.AQ,.AR
/
	.DEFIN	DLD%	/FLOATING LOAD (.AO)
	JMS*	.AO
	.ENDM
	.DEFIN	DVD%	/FLOATING DIVIDE (.AT)
	JMS*	.AT
	.ENDM
	.DEFIN	DAD%	/FLOATING ADD (.AQ)
	JMS*	.AQ
	.ENDM
	.DEFIN	DSB%	/FLOATING SUBTRACT (.AR)
	JMS*	.AR
	.ENDM
/
	.ENDC
/
/
	.IFDEF	%FPP
/
BPA=716604
BMA=716602
BZA=716601
BNA=716610
/
DLD=713150
	.DEFIN	DLD%	/FPP FLOATING LOAD
	DLD
	.ENDM
DVD=712140
	.DEFIN	DVD%	/FPP FLOATING DIVIDE
	DVD
	.ENDM
DAD=716140
	.DEFIN	DAD%	/FPP FLOATING ADD
	DAD
	.ENDM
DSB=710540
	.DEFIN	DSB%	/FPP FLOATING SUBTRACT
	DSB
	.ENDM
/
	.ENDC
/CALLING SEQUENCE
/	JMS*	DATAN2
/	JMP	.+3	RETURN POINT
/	.DSA	ARG1[+400000]  ADDR OR ARG 1
/	.DSA	ARG2[+400000]  ADDR OF ARG 2
/
/
DATAN2	0		/ENTRY POINT
	JMS*	.DA	/SET UP ARGUMENT ADDRESSES
	JMP	DTN203	/JUMP AROUND ARGUMENT LIST
DTN201	0		/ARG 1
DTN202	0		/ARG 2
/
DTN203	DLD%		/LOAD ARGUMENT 1
	.DSA	DTN201+400000
	LAC	DTN202	/BEFORE PROCEEDING, CHECK IF THE DENOMINATOR OF 
	DAC	DTN205	/RATIO ARG1/ARG2 IS ZERO.  CHECK THE MOST SIG-
	ISZ	DTN205	/NIFICANT BITS OF ARG2
	LAC*	DTN205
	SZA
	JMP	DTN206	/(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	DTN209
	.ENDC
	.IFDEF	%FPP
	BPA!BZA
	DTN209
	.ENDC
	DLD%		/LOAD -PI/2
	.DSA	DTN208
	JMP*	DATAN2	/..AND EXIT
/
DTN209=.
	.IFUND	%FPP	/CHECK FOR SPECIAL CONDITION OF ATAN 0/0
	SZA		/WHICH IS UNDEFINED.  SIGNAL OTS 17, AND RETURN 
	JMP	.+3	/WITH ARBITRARY VALUE OF +PI/2
	.ENDC
	.IFDEF	%FPP
	BNA
	.+3
	.ENDC
	JMS*	.ER
	.DSA	400017	/ERROR IS RECOVERABLE
	DLD%		/LOAD +PI/2
	.DSA	DTN207	/...AND EXIT.
	JMP*	DATAN2
DTN206	DVD%		/IN NON-EXCEPTIONAL CASES, DIVIDE ARG1 BY ARG2,
	.DSA	DTN202+400000	/AND USE .DD TO COMPUTE ARCTANGENT
	JMS*	.DD	/THE VALUE RETURNED IS IN THE INTERVAL
	LAC*	DTN205	/  -PI/2 TO PI/2.  IF THE SIGN OF ARG2 IS POSITIVE
	SMA		/THEN THE ANGLE IS CORRECTLY IN THE FIRST OR
	JMP*	DATAN2	/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
	DSB%		/SUBTRACT PI TO ADJUST TO 3RD QUADRANT
	.DSA	DTN204
	JMP*	DATAN2
	DAD%		/ADD PI TO ADJUST TO 2ND QUADRANT
	.DSA	DTN204
	JMP*	DATAN2
/
DTN204	000002		/PI
	311037
	552421
DTN205	0		/ADDRESS OF MSB OF ARG 2
DTN207	000001		/PI/2
	311037
	552421
DTN208	000001		/ -PI/2
	711037
	552421
	.END
