       .TITLE DSQRT  COMPUTE SQUARE ROOT FOR DOUBLE 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.
/FOR HARDWARE FLOATING POINT PROCESSOR (FPP), DEFINE 90 FPP,
/EDIT 7   5-6-71
	.GLOBL DSQRT,.DA,.ER
	.IFUND %FPP
	.GLOBL .AA,.AB,.AC,.AO,.AP
	.GLOBL .AV,.AQ
	.ENDC
	.IFUND %FPP
	.DEFIN DLD%,A
	JMS* A			/DOUBLE LOAD (.AO)
	.ENDM
	.ENDC
	.IFDEF %FPP
DLD=713150
	.DEFIN DLD%
	DLD
	.ENDM
	.ENDC
	.IFUND %FPP
	.DEFIN UNDST%,A		/UNNORMALIZED
	JMS* A			/DOUBLE STORE (.AP)
	.ENDM
	.ENDC
	.IFDEF %FPP
UNDST=713770
	.DEFIN UNDST%
	UNDST
	.ENDM
	.ENDC
	.IFUND %FPP
	.DEFIN DRD%,A		/DOUBLE REVERSE DIVIDE
	JMS* A			/(.AV)
	.ENDM
	.ENDC
	.IFDEF %FPP
DRD=712540
	.DEFIN DRD%
	DRD
	.ENDM
	.ENDC
	.IFUND %FPP
	.DEFIN DAD%,A		/DOUBLE ADD (.AQ)
	JMS* A
	.ENDM
	.ENDC
	.IFDEF %FPP
DAD=716140
	.DEFIN DAD%
	DAD
	.ENDM
	.ENDC
/             CALLING SEQUENCE
/      JMS*   (DSORT)         SUBR CALL
/      JMP    .+2             SUBR RETURN (ROOT IN FLOATING ACC)
/      CAL/XCT ADDR           ADDR OF ARGUMENT (XCT IF INDIRECT)
/FPP INST. ASS.
	.IFDEF %FPP
BMA=716602			/BR ON MINUS FPP AC
BZA=716601			/BR ON 0 FPP AC
FDV=712040			/FLT. DIV.
FZR=711200		/MAKE FPP AC 0
	.ENDC
/
DSQRT  CAL    0              /ENTRY-EXIT
       JMS*   .DA            /GET ARGUMENT
       JMP    DSQR02
DSQR01 CAL    0              /(ARG ADDR)
DSQR02 DLD%   .AO            /LOAD DOUBLE
	.DSA	DSQR01+400000	/ (ARG)
	.IFDEF %FPP
DSQR11	BMA			/BR ON NEG FPP AC
	DSQR10			/ERR IF < 0
	BZA			/BR IF 0 FPP AC
	DSQRT+400000
	UNDST
	DSQR14
	LAC DSQR14
	.ENDC
	.IFUND %FPP
DSQR11 LAC*   .AB            /GET SIGN WORD
	SPA
       JMP    DSQR10         /ERROR IF .LT. ZERO
	SNA
       JMP*   DSQRT          /ROOT = ZERO IF ARG = ZERO
       LAC*   .AA            /GET ARG EXP (X)
	.ENDC
	CLL!SPA
	CML
	RAR
	DAC DSQR05	/SET EXP OF CONSTANT (K) = X/2
       SNL                   /WAS (X) ODD
       TAD    DSQR06         / NO-SET A = X/2 -1
	.IFDEF %FPP
	DAC	DSQR14
	DLD
	DSQR14
	.ENDC
	.IFUND %FPP
       DAC*   .AA            /SET EXP OF ARG = X/2 OR X/2 -1 (FORCE SFT)
	.ENDC
       DAD%   .AQ            /ADD DOUBLE
       .DSA   DSQR05         / (ARG + K = P(O))
	LAW -5		/SET ITERATION COUNTER
       DAC    DSQR05
DSQR13 UNDST%   .AP            /STORE DOUBLE
       .DSA   DSQR09         / (P(N))
       DRD%   .AV            /REVERSE DIVIDE DOUBLE
       .DSA   DSQR01+400000  / (ARG/P(N))
       DAD%   .AQ            /ADD DOUBLE
       .DSA   DSQR09         / (P(N)+(ARG/P(N)))
	.IFDEF %FPP
	FDV
	DSQR15	/DIV BY 2
	.ENDC
	.IFUND %FPP
       LAW    -1             /SET EXP OF ABOVE
       TAD*   .AA            / TO EXP-1 (DIVIDE ARG BY 2)
       DAC*   .AA
	.ENDC
       ISZ    DSQR05         /BUMP ITERATION COUNTER
       JMP    DSQR13         /MORE TO GO-CYCLE
       JMP*   DSQRT          /DONE-EXIT
	.IFDEF	%FPP
DSQR10	FZR		/MAKE FPP AC ZERO
	0		/NOT USED
	.ENDC
	.IFUND	%FPP
DSQR10	DZM* .AA	/ZERO RESULT
	DZM* .AB
	DZM* .AC
	.ENDC
       JMS*   .ER            /ERROR ROUTINE
       .DSA   400006         /ERR 6
       JMP*    DSQRT
DSQR05 CAL    0              /EXP OF K (= EXP/2 OF ARG) ALSO ITER CNTR
              200000
              0
DSQR06        777777         /CONSTANT OF -1
DSQR09 CAL    0              /STORAGE FOR P(N)
       CAL    0              /  (2)
       CAL    0              /  (3)
	.IFDEF %FPP
DSQR14	0		/TEMP FOR FPP AC
	0
	0
DSQR15	000002		/FLT 2
	200000
	.ENDC
	.END
