
	.TITLE STRIGS
/COPYRIGHT 1969, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/SINGLE PRECEISION TRIG FUNCTIONS
/
/	SQRT		SQUARE ROOT
/	ATAN		ARCTANGENT
/	EXP		NATURAL EXPONENTIAL
/	ALOG		NATURAL LOGARITHM
/	ALOG10		COMMON LOGARITHM
/	SIN		SINE
/	COS		COSINE
/	TANH		HYPERBOLIC TANGENT
/
/--------------------
/
	.IFUND	%NCOS
/SIN-COS
/COMPUTE THE SINE OR COSINE OF A S.P.
/FLOATONG POINT ARGUMENT.
/THE RESULT WILL APPEAR IN THE
/FLOATING POINT ACCUMULATOR.
/
/METHOD:	COS X = SIN (PI/2 +X)
/
COS	0
	JMS	%FG.
	0
	JMS	FLAC
	XCT	.-2
	JMS	FAD		/ADD PI/2 TO ARG
	.DSA	%SC1		/ADDRESS OF PI/2
	JMS	%SIN		/COMPUTE COSINE USING SIN FUNCTION
	JMP*	COS		/ERROR RETURN
	ISZ	COS		/POINT TO NORMAL
	JMP*	COS		/RETURN
%SC1		553001		/PI/2 (1) 1.570796327
		311037		/     (2)
	.ENDC
/
/--------------------
/
/SINE
	.IFUND	%NSIN
SIN	0
	JMS	%FG.
	0
	JMS	FLAC
	XCT	.-2
	JMS	%SIN
	JMP*	SIN		/ERROR RETURN
	ISZ	SIN		/POINT TO
	JMP*	SIN		/NORMAL RETURN
	.ENDC
/
/--------------------
/
/COMPUTE THE SINE
/OF THE S.P. ARG IN THE FLTING ACC.
/
	.IFUND	%NCOS
	.IFUND	%NSIN
%SIN	0
	LAC	%FAC2		/BIT 0=SIGN
	AND	(400000		/KEEP ONLY THE SIGN BIT
	DAC	%SCA		/SAVE IT FOR LATER.
	LAC	%FAC2		/GET HIGH ORDER WORD AGAIN
	AND	(377777		/KEEP THE ABSOLUTE VALUE.
	DAC	%FAC2
	JMS	FMPY		/MULTIPLY (2/PI*ARG)
	.DSA	%SC2		/ADDRESS OF (2/PI)
	JMS	FDAC		/STORE PRODUCT AT
	.DSA	%SCB		/ %SCB.
/
/UNFLT TO GET INT. LO ORDER 2 BITS
/DETERMINE QUAD OF ARG. QUAD IS
/NECESSARY FOR MODFCTN OF ARG TO
/COMPLETE APPROX.
/
	JMS	%FUNF.		/UNFLOAT AND SAVE INTEGER
	JMP*	%SIN		/ERROR RETURN
	DAC	%SCC		/FOR QUADRANT DETERMINATION.
/
/FLOAT THE INTEGER AND SUBTRACT IT FROM THE ORIGINAL FLOATING
/POINT QUANTITY. THE RESULT WILL BE ONLY THE FRACTIONAL PORTION (F)
/OF THE ORIGINAL QUANTITY.
/
	JMS	%FLOT.		/FLOAT INTEGER ONLY
	JMS	FSBR		/REVERSE SUB US TO GET A
	.DSA	%SCB		/POS DIFF WHEN SUBTRAHEND
/				/IS LARGER THAN MINUEND.
	LAC	%SCC		/GET INT TO DETERMINE QUADRANT.
	RCR			/BIT 17 TO LINK. IF BIT 17 IS
	SNL			/ON THE QUADRANT IS 2 OR 4.
	JMP	%SINA		/IF THE QUAD IS 2 OR 4 SUBTRACT
	JMS	FSBR		/F FROM 1. (1-F).F IS ALREADY
	.DSA	%SC3		/IN THE FLTING ACC.
/
/IF BIT 16 IS ON, THE QUANTITY IN THE FLOATING AC MUST BE
/NEGATED.
/
%SINA	LAC	%SCC		/GET INT AGAIN FOR QUAD 1 OR 3.
	RTR			/BIT 16 TO LINK
	SNL			/IF SET NEGATE ANSWER 
	JMP	%SINB		/SIGN(QUAD 3 OR 4)
	LAC	(400000		/0 BIT ON
	XOR	%SCA		/EXCLUSIVE OR SIGN BIT
	DAC	%SCA		/SAVE ANSWER SIGN BIT
/
/CALL POLYNOMIAL EVALUATOR.  THE TABLE IS AT %SIN4
/
%SINB	JMS	POLY
	.DSA	%SC4	/SC4 REPRESENTS NO. OF ARGS.
	LAC	%FAC2	/GET SIGN WORD OF ANSWER.
	AND	(377777	/STRIP SIGN BIT
	XOR	%SCA	/INSERT SIGN OF ANSWER AND
	DAC	%FAC2	/RESTORE IN FLOATING AC.
	ISZ	%SIN	/POINT TO NORMAL RET.
	JMS	%FNOR.
	JMP*	%SIN	/RETURN
%SCA	0		/TEMP STORAGE
%SCB	0		/TEMP STORAGE
	0		/TEMP STORAGE
%SC2	016000		/2/PI (1)  0.63661977236
	242763		/	(2)
%SCC	0
%SC3	000001		/1.0
	200000
%SC4	777774		/NUMBER OF COEFFICIENTS(4)
	351764		/C(4) (1) +0.00015148419
	236657		/C(3) (1) -0.00467376557
	615771		/	(2)
	631114		/	(2)
	537775		/C(2) (1) +0.07968967928
	243150		/	(2)
	603000		/C(1) (1) -0.6459637111
	645273		/	(2)
	552001		/C(0) (1) 1.570796327
	311037		/	(2)
	.ENDC
	.ENDC
/
/--------------------
/
/EXP	/COMPUTE THE NATURAL EXPONENTIAL
/OF A S.P. FLTING POINT ARGUMENT.
/
	.IFUND	%NEXP
	.IFUND	%NTANH
EXP	0
	JMS	%FG.
	0
	JMS	FLAC
	XCT	.-2
	LAC	%FAC2	/GET SIGN-WORD
	DAC	%EXP1	/SAVE SIGN IN WORK WORD5
	AND	(377777	/GET ABSOLUTE VALUE
	DAC	%FAC2	/OF ARGUMENT
	JMS	FMPY
	.DSA	%EXPC1	/SINGLE PRECISION CONSTANT (LOG2(E)).
	JMS	FDAC	/FLOATING STORE S.P. ARG
	.DSA	%EXP2
	JMS	%FUNF.	/UNFLOAT TO GET THE INTERGER
	JMP*	EXP	/ERROR RETURN
	DAC	%EXPC2	/SAVE INTEGER AS ANSWER EXP
	ISZ	%EXPC2	/BUMP EXPONENT FOR .5 SCALING
	JMS	%FLOT.	/FLOAT INTERGER
	JMS	FSBR	/REVERSE SUBTRACT
	.DSA	%EXP2	/(TEMP-ACC) FRACTION ONLY (E)
	JMS	FDAC	/STORE PRODUCT (F)
	.DSA	%EXP2
	LAW	-6	/SET INTERATION COUNTER
	DAC	%EXP4	/SAVE IT AT WORK WORD 4
/INITIALIZE TABLE POINTER.
	LAC	%EXPB	/ADDRESS OF TABLE %EXPC
	DAC	%EXP5	/USE WORK WORD5 TO STEP DOWN TABLE
	JMS	FLAC	/LOAD THE TOP ELEMENT
	.DSA	%EXPC	/OF THE TABLE
%EXPA	JMS	FMPY	/FLOATING POINT S.P. MULTIPLY
	.DSA	%EXP2	/((F)*TERM)
	ISZ	%EXP5	/POINT TO NEXT (C)
	ISZ	%EXP5
	JMS	FAD	/FLOATING ADD
	XCT	%EXP5	/(C+(F*TEMM))
	ISZ	%EXP4	/COUNTER=COUNTER+1
	JMP	%EXPA	/CYCLE BACK
/
	JMS	FDAC	/DONE
	.DSA	%EXP2
	JMS	FMPY	/RESULT*RESULT=RESULT**2
	.DSA	%EXP2
	JMS	FMPY	/EXPONENT *FINAL RESULT
	.DSA	%EXPC2
/
	ISZ	EXP
	LAC	%EXP1	/IF INPUT ARGUMENT WAS NEGATIVE
	SMA		/NEGATE THE RESULT BEFORE
	JMP*	EXP	/ARG .GT.0
	JMS	FDVR	/ARG.LT.0  GET RECIPROCAL
	.DSA	%EXPC3
	JMP*	EXP
%EXP1	0
%EXP2	0
	0
%EXP4	0
%EXP5	0
%EXPC1	355001		/LOG2(E)
	270524
%EXPC2	0		/0.5
	200000
/THE VALUES OF C ARE:
/
%EXPB	.DSA	%EXPC	/USE TO INITIALIZE POINTER
%EXPC	760756		/C(7) (1) (0.241E-5)
	241556		/	(2)
	512762		/C(6) (1) (0.4167E-4)
	256615		/	(2)
	233766		/C(5) (1) (0.60113E-3)
	235452		/	(2)
	374771		/C(4) (1) (0.693801E-2)
	343260		/	(2)
	703774		/C(3) (1) (0.06005663)
	365773		/	(2)
	140777		/C(12) (1) (0.34657359)
	261344		/	(2)
%EXPC3	     1		/C(1) (1) (1.0)
	200000		/	(2)
	.ENDC
	.ENDC
/
/--------------------
/
/SQRRT	/COMPUTE THE SQUARE ROOT
/OF A S.P. FLTING POINT ARGUMENT.
/
	.IFUND	%NSQRT
SQRT	0
	JMS	%FG.
%SQRT1	0
	JMS	FLAC
	XCT	%SQRT1
	LAC	%FAC2	/GET SIGN WORD
	SPA!CLL		/CONTINUE IF NOT NEGATIVE
	JMP	%SQRTB
	ISZ	SQRT	/POINT TO NORMAL EXIT
	SNA		/IF ARGUMENT IS ZERO
	JMP*	SQRT	/EXIT IMMEDIATELY
	LAC	%FAC1	/DIVIDE THE EXPONENT
	SPA
	STL
	RAR
	DAC	%FAC1
	AND	(777	/LOW 9-BITS AS EXP OF K
	DAC	%SQRC1	/(K=.5*2**EXP/2)
	LAC	%FAC1
	SNL		/WAS EXP OD
	TAD	(-1	//NO..SET TO SHIFT ARG TO
	DAC	%FAC1	/ARG 12 BEFORE ADD.
	JMS	FAD	/FLOATING ADD
	.DSA	%SQRC1	/(K+ARG) OR (K+ARG12)=P(0)
	LAW	-3	/SET ITERATION COUNTER
	DAC	%SQRC1	/USE EXP PART OF PROGRAM CONSTANT.
%SQRTA	JMS	FDAC	/FLOATING STORE
	.DSA	%SQRT2	/P(N)
	JMS	FDVR	/REVERSE DIVIDE
	XCT	%SQRT1	/(ARG/P(N)
	JMS	FAD	/FLOATING ADD
	.DSA	%SQRT2	/(P(N)+ARG/P(N))
	LAW	-1	/EXP=EXP-1
	TAD	%FAC1	/(DIVIDE BY 2)
	DAC	%FAC1
	ISZ	%SQRC1	/BUMP COUNTER
	JMP	%SQRTA	/LOOP BACK AGAIN
	JMP*	SQRT	/FINISHED-EXIT
%SQRTB	STL!GLK		/ERROR # 1
	JMP*	SQRT	/ERROR EXIT
%SQRC1	0
	200000
%SQRT2	0
	0
	.ENDC
/
/--------------------
/
/ALOG	/COMPUTE THE NATURAL LOGARITHM
/OF A S.P. FLTING POINT NUMBER IN
/THE FLTING ACC.
/
	.IFUND	%NALOG
ALOG	0
	JMS	%FG.
	0
	JMS	FLAC
	XCT	.-2
	JMS	%LOGS		/COMPUTE LOG 2(ARG)
	JMP*	ALOG		/ERROR EXIT
	JMS	FMPY		/FLOATING MULTIPLY
	.DSA	%ALOG1		/RESULT=RESULT*LOGE(2)
	ISZ	ALOG		/POINT TO NORMAL EXIT
	JMP*	ALOG		/EXIT
%ALOG1	140000			/LOGE(2) (1) 0.6931471806
	261344			/        (2)
	.ENDC
/
/--------------------
/
/ALOG10	/COMPUTE THE COMMON LOGARITHM
/OF A S.P. FLTING POINT NUMBER IN
/THE FLTING ACC.
/
	.IFUND	%NLG10
ALOG10	0
	JMS	%FG.
	0
	JMS	FLAC
	XCT	.-2
	JMS	%LOGS		/COMPUTE LOG 2(ARG)
	JMP*	ALOG10		/ERROR EXIT
	JMS	FMPY		/FLOATING MULTIPLY
	.DSA	%ALG1		/RESULT=LOG 2(ARG)*LOG 10(2)
	ISZ	ALOG10		/POINT TO NORMAL EXIT
	JMP*	ALOG10		/EXIT
%ALG1	152777		/LOG10(2) (1) 0.301029 957
	232101		/	(2)
	.ENDC
/COMPUTE LOG BASE 2 OF ARGUMENT
/IN THE FLOATING ACCUMULATOR.
/
	.IFUND	%NALOG
	.IFUND	%NLG10
/
/--------------------
/
%LOGS	0
/
/LOG BASE (X) 1=0
/CHECK FOR 1.0 IN FAC
	LAC	%FAC1		/OK IF EXP.GT. 1
	SNA
	JMP	%LOG1
	AND	(777776
	SZA
	JMP	%LOG1
	LAC	%FAC3		/OK IF NOT 0
	SZA
	JMP	%LOG1
	LAC	%FAC2
	SAD	(200000		/OK IF NOT 200000
	JMP	%LOGSZ		/SET TO ZERO
%LOG1	LAC	%FAC2		/GET SIGN-WORD
	SNA!SPA			/IF .LE.0
	JMP	%LOGSA		/ERROR 2
	ISZ	%LOGS		/POINT TO NORMAL EXIT
	LAW	-1		/SUBTRACT 1 FROM
	TAD	%FAC1		/EXPONENT AND SAVE IT
	DAC	%LOGS1		/FOR INTEGER DETERMINATION
	LAC	(1		/SET ARGUMENT EXPONENT=1
	DAC	%FAC1		/ (1.LE.ARG.LT.2)=F
	JMS	FAD		/FLOATING ADD
	.DSA	%LOGC1		/(F+SQRT(2))
	JMS	FDAC		/STORE SUM TEMPORARILY
	.DSA	%LOGS2		/AT WORK WORDS 2 & 3
	JMS	FSUB		/FLOATING SUBTRACT
	.DSA	%LOGC2		/(F+SQRT(2)-(2*SQRT(2)=F-SQRT(2))
	JMS	FDVD		/FLOATING DIVIDE
	.DSA	%LOGS2		/(F-SQRT(2)/F+SQRT(2)
	JMS	POLY		/POLYNOMIAL EVALUATE ABOVE
	.DSA	%LOGSB		/ADDR OF CALLING SEQUENCE
	JMS	FDAC		/FLOATING STORE
	.DSA	%LOGS2		/(PARTIAL RESULT TO TEMP)
	LAC	%LOGS1		/GET INTEGER (EXP-1)
	STL			/INTEGER=INTEGER/0,4(2*INTEGER+1)
	RAL			/(INTEGER*2)
	JMS	%FLOT.		/FLOAT THE INTEGER
	LAW	-1		/SET EXPONENT=EXP-1(2
	TAD	%FAC1		/	/*INTEGER+0.5)
	DAC	%FAC1
	JMS	FAD		/FLOATING ADD
	.DSA	%LOGS2		/(PARTIAL RESULT+INTEGER+0.5)
	JMP*	%LOGS		/EXIT
/
/AT %LOGSZ CLEAN THE FAC
%LOGSZ	DZM	%FAC1
	DZM	%FAC2
	ISZ	%LOGS
	JMP*	%LOGS
/
%LOGSA	LAC	(2		/ERROR 2
	JMP*	%LOGS		/ERROR EXIT
%LOGS1	0
%LOGS2	0
	0
%LOGC1	715001		/SQRT(2)	(1) 1.41421356
	265011		/
%LOGC2	715002		/2*SQRT(2)(1) 2.82843712
	265011	/	(2)
/THE VALUES OF C ARE:
%LOGSB	777776		/NUMBER OF COEFFICIENTS (3)
	251000		/C(2)	(1) 0.59897865
	231255		/	(2)
	702000		/C(1)	(1) 0.96147063
	366105		/	(2)
	401002		/C(0)	(1) 2.8853913
	270524		/	(2)
	.ENDC
	.ENDC
/
/--------------------
/
/ATAN	/COMPUTE THE ARCTANGENT
/FOR A S.P. FLTING POINT VALUE
/
	.IFUND	%NATAN
ATAN	0
	JMS	%FG.
	0
	JMS	FLAC
	XCT	.-2
	LAC	%FAC2	/GET SIGN-WORD
	DAC	%ATAN1	/SAVE TEMPORARILY
	AND	(377777	/STRIP SIGN
	DAC	%FAC2	/RESTORE ABSOLUTE VALUE
	LAC	%FAC1	/GET EXPONENT
	DAC	%ATAN2	/SAVE FOR LATER TEST
	SNA!SPA		/IF EXP.GT.0 (ARG.GT.1) TAKE 1/ARG
	JMP	%ATANA	/OR SKIP
	JMS	FDVR	/REVERSE DIVIDE
	.DSA	%ATAC1	/(1/ARG)
%ATANA	JMS	POLY	/POLYNOMIAL EVALUATE
	.DSA	%ATANC
	LAC	%ATAN2	/GET ORIGINAL EXPONENT
	SNA!SPA		/TEST AGAIN FOR ARG.GT.1 (EXP.GT.0)
	JMP	%ATANB	/NOT.GT.1, SKIP
	JMS	FSBR
	.DSA	%ATAC2	/(PI/2-ANS)
%ATANB	LAC	%ATAN1	/GET ORIGINAL SIGN WORD
	AND	(400000	/KEEP SIGN ONLY
	XOR	%FAC2	/INSERT ANSWER SIGN
	DAC	%FAC2
	JMS	%FNOR.
	JMP*	ATAN	/EXIT
%ATAN1	0
%ATAN2	0
%ATAC1	1		/1.0
	200000
/THE VALUES FOR C ARE:
/
%ATANC	777771		/NO OF COEFF.
	635771		/C(7)	(1) -0.0040540580
	604657		/	(2)
	507773		/C(6)	(1) 0.0218612288
	263054		/	(2)
	417774		/C(5)	(1) -0.0559098861
	745003		/	(2)
	575775		/C(4)	(1) 0.0964200441
	305357		/	(2)
	613776		/C(3)	(1) -0.1390853351
	616330		/	(2)
	227776		/C(2)	(1) 0.1994653599
	314201		/	(2)
	160777		/C(1)	(1) -0.3332985605
	652514		/	(2)
	723000		/C(0)	(1) +0.9999993329
	377777		/	(2)
%ATAC2	553001
	311037
	.ENDC
/
/--------------------
/
/TANH	/COMPUTE THE HYPERBOLIC TANGENT
/OF A S. P. FLTING POINT VALUE IN THE
/FLTING ACC.
/
	.IFUND	%NTANH
TANH	0
	JMS	%FG.
	0
	JMS	FLAC
	XCT	.-2
	LAC	%FAC2		/GET SIGN WORD
	DAC	%TANH3		/STORE FOR FINAL SIGN
	AND	(377777
	DAC	%FAC2		/ABSOLUTIZE
	ISZ	%FAC1		/EXP-EXP+1 (ARG = 2*ARG)
	NOP
	JMS	FDAC
	.DSA	%TANH1
	JMS	EXP
	.DSA	%TANH1
	JMP*	TANH		/ERROR EXIT
				/REAL EXPONENTIAL EXP(2X)
	JMS	FAD		/ADD REAL
	.DSA	%TANH5		/ (1)
	JMS	FDVR		/REVERSE DIVIDE REAL
	.DSA	%TANH6		/ (2/(1+E**2 )
	JMS	FSBR		/REVERSE SUBTRACT REAL
	.DSA	%TANH5		/ (1(21(1+E *2X)))
	LAC	%TANH3		/SIGN WITH ORIGINAL SIGN
	AND	(400000
	XOR	%FAC2
	DAC	%FAC2
	ISZ	TANH		/NORMAL EXIT
	JMS	%FNOR.
	JMP*	TANH		/EXIT
%TANH3		0		/ANS SIGN
%TANH5		1		/FLOATING 1
		200000
%TANH6		2		/FLOATING 2
		200000
%TANH1	0
	0
	.ENDC
/
/--------------------
/
/POLY
/
/DESCRIPTION:	COMPUTE THE RESULTS OF THE GENERAL POLYNOMIAL
/	EXPRESSION:
/
/		X=(C(2I+1)*Z**(2I+1)) I=0,N
/
/CALLING SEQUENCE:	JMS	POLY
/		.DSA	PLIST	/ADDRESS OF PARAM LIST
/		.	(RETURN HERE)
/		.
/	PLIST	-N		/-NO OF TERMS +1
/		C(N)		/LAST COEFFICIENT
/		C(N-1)
/		.
/		C(0)		/1ST TERM
/
/
/METHOD:	THE POLYNOMIAL IS EVALUATED AS FOLLOWS:
/
/	X=((((C(N)*Z**2+C(N-1))Z**2+....C(1))Z**2+C(0))Z
/
/	DURING THE COMPUTATIONS THE LAST COEFFICIENT IS TAKEN FIRST, ETC.
/
/THE VALUE (Z) IS CARRIED IN THE FLOATING ACCUMULATOR
/UPON ENTERING SUBROUTINE POLY. RETURN IS MADE WITH
/THE RESULT (X) IN THE FLOATING AC.
/
/
	.IFUND	%NPOLY
POLY	0
	LAC*	POLY		/ADDRESS OF PARAMETER
	DAC	%POLA		/SAVE AS POINTER
	LAC*	%POLA		/GET 1ST PARAMETER -(N)
	DAC	%POLB	/SAVE IT AS COUNTER
	ISZ	%POLA		/BUMP POINTER TO 1ST COEFFICIENT
	ISZ	POLY		/PREPARE RETURN ADDRESS.
/
/SQUARE THE FLOATING ACCUMULATOR.
/
	JMS	FDAC		/SAVE FLOATING ACCUMULATOR
	.DSA	%POLD		/AND MULTIPLY IT ITSELF
	JMS	FMPY
	.DSA	%POLD
	JMS	FDAC		/SAVE SQUARED VERSION
	.DSA	%POLC		/OF Z.
/
/LOAD COEFFIECIENT FROM CALLING PROGRAM PROGRAM INTO FLOATING AC.
/
	JMS	FLAC
	.DSA	%POLA+400000	/INDIERECTLY BECAUSE %POLA IS A OINTER
/
/START THE POLY NOMIAL EVALUATION
/
  
%POL1	JMS	FMPY		/C(N)*Z2
	.DSA	%POLC
	ISZ	%POLA		/POINT TO COEFF.
	ISZ	%POLA		/TWICE BECAUSE EACH COEFF=
	JMS	FAD		/2 WORDS.
	.DSA	%POLA+400000	/ADD NEXT COEFFICIENT.
	ISZ	%POLB		/FINISHED?
	JMP	%POL1		/NO MPY NEW TERM BY Z2
	JMS	FMPY		/YES..MPY RESULT BY ORGINAL Z.
	.DSA	%POLD
	JMP*	POLY		/RETURN
/
/
%POLA	0			/POINTER
%POLB	0			/COUNTER
%POLC	0			/(1) SQUARE VERSION OF ARGUMENT (Z)
	0			/(2) COMING INTO PROGRAM
%POLD	0			/(1) SAVE ARGUMENT (Z) COMING INTO
	0			/(2) THE PROGRAM (FROM FLOATING AC)
	.ENDC
	.EOT
