       .TITLE SQRT	 COMPUTE SQUARE ROOT FOR REAL ARGUMENT		
/ 
/ 
/                   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 1970,1971, DIGITAL EQUIPMENT CORP., MAYNARD, MASS. 01754
/FOR HARDWARE FLOATING POINT PROCESSOR (FPP), DEFINE 90 FPP,
	/EDIT 8 5-6-71
       .GLOBL SQRT,.DA,.ER		
	.IFUND %FPP
	.GLOBL .AA,.AB,.AC,.AG,.AH,.AN,.AI
	.ENDC
	.IFUND %FPP
	.DEFIN FLD%,A		/FLOATING LOAD (.AG)
	JMS* A
	.ENDM
	.ENDC
	.IFDEF %FPP
FLD=713050
	.DEFIN FLD%
	FLD
	.ENDM
	.ENDC
	.IFUND %FPP
	.DEFIN FST%,A		/FLOATING STORE (.AH)
	JMS* A
	.ENDM
	.ENDC
	.IFDEF %FPP
FST=713640
	.DEFIN FST%
	FST
	.ENDM
	.ENDC
	.IFUND %FPP
	.DEFIN FRD%,A		/FLOATING REVERSE DIVIDE
	JMS* A			/(.AN)
	.ENDM
	.ENDC
	.IFDEF %FPP
FRD=712440
	.DEFIN FRD%
	FRD
	.ENDM
	.ENDC
	.IFUND %FPP
	.DEFIN FAD%,A		/FLOATING ADD (.AI)
	JMS* A
	.ENDM
	.ENDC
	.IFDEF %FPP
FAD=716040
	.DEFIN FAD%
	FAD
	.ENDM
	.ENDC
/      JMS*   (SQRT)	SUBR CALL 			
/      JMP    .+2		SUBR RETURN (ROOT IN FLOATING ACC)	
/      CAL/XCT ADDR 	ADDR OF ARGUMENT (XCT IF INDIRECT)	
/FPP INSTR ASS.
	.IFDEF %FPP
BMA=716602		/BR ON MINUS FPP AC
BNA=716610		/BR ON NON-ZERO FPP AC
DLD=713150
UNDST=713770
FDV=712040
FZR=711200		/ZERO FPP AC.
	.ENDC
/
SQRT   CAL    0	         /ENTRY-EXIT			
       JMS*   .DA	         /GET ARGUMENT			
       JMP    SQRT02					
SQRT01 CAL    0	         /(ADDR OF ARG)			
SQRT02 FLD%   .AG	         /LOAD REAL 			
       .DSA   SQRT01+400000  / (ARG)				
	.IFDEF %FPP
SQRT11	BMA		/BR IF NEG
	SQRT10
	BNA		/BR IF NON-ZERO
	SQRT14
	.ENDC
	.IFUND %FPP
SQRT11 LAC*   .AB	         /GET SIGN WORD
	SPA
       JMP    SQRT10         /ERROR IF .LT.ZERO			
	SNA
	.ENDC
	JMP*   SQRT	         /SQRT IS ZERO IF ARG IS ZERO		
	.IFDEF %FPP
SQRT14	UNDST
	SQRT15
	LAC SQRT15
	SPA!CLL
	CML
	RAR
	DAC SQRT15
	AND SQRT04
	DAC SQRT05
	LAC SQRT15
	SNL
	TAD SQRT06
	DAC SQRT15
	DLD
	SQRT15
	.ENDC
	.IFUND %FPP
       LAC*   .AA	         /GET EXP				
	SPA!CLL
	CML
	RAR
	DAC* .AA
       AND    SQRT04         /KEEP LOWER 9 BITS			
       DAC    SQRT05         /STORE AS EXP OF K (K= .5 * 2**EXP/2)	
	LAC* .AA
       SNL	         /WAS EXP ODD			
       TAD    SQRT06         / NO-SET TO SHIFT ARG TO ARG12 BEFORE ADD
       DAC*   .AA						
	.ENDC
       FAD%   .AI	         /ADD REAL				
       .DSA   SQRT05         / (K + ARG)  OR (K + ARG12) = PO	
	LAW -4		/SET ITERATION COUNTER.
       DAC    SQRT05					
SQRT13 FST%   .AH	         /STORE REAL			
       .DSA   SQRT09         / (P(N))				
       FRD%   .AN	         /REVERSE DIVIDE REAL 		
       .DSA   SQRT01+400000  / (ARG/P(N))			
       FAD%   .AI	         /ADD REAL				
       .DSA   SQRT09         / (P(N) + ARG/P(N))			
	.IFDEF %FPP
	FDV		/DIV BY 2
	SQRT16
	.ENDC
	.IFUND %FPP
       LAW    -1	         /EXP = EXP -1 (DIVIDE BY 2)		
       TAD*   .AA						
       DAC*   .AA						
	.ENDC
       ISZ    SQRT05         /BUMP COUNTER			
       JMP    SQRT13         /MORE ITERATIONS			
       JMP*   SQRT	         /EXIT				
	.IFDEF %FPP
SQRT10	FZR	/MAKE RESULT 0
	0
	.ENDC
	.IFUND %FPP
SQRT10	DZM* .AA	/MAKE RESULT 0
	DZM* .AB
	DZM* .AC
	.ENDC
       JMS*   .ER	         /ERROR ROUTINE
       .DSA   400005         /ERR 5
       JMP*    SQRT	/EXIT WITH ZERO RESULT
SQRT06	    777777         /CONSTANT (-1)			
SQRT04	    777	         /EXP MASK FOR NEG EXP		
SQRT05 CAL    0	         /EXP OF K (SET TO ARG EXP/2) ALSO ITER CNTR
	    200000         /K = 0.5				
SQRT09 CAL    0	         /STORAGE FOR P(N) (1)		
       CAL    0	         /	       (2)		
	.IFDEF %FPP
SQRT15	0
	0
	0
SQRT16	000002
	200000
	.ENDC
	.END
