perm filename SAITG2.FAI[S,AIL]1 blob sn#102558 filedate 1974-05-22 generic text, type T, neo UTF8
COMPIL(TG2,<ATAN$,ASIN$,ACOS$,ATAN2$>,<OVPCWD,TRIGINI,X33,SQRT$,X22,X11>
	,<ARC-TRIG ROUTINES>)
BEGIN ATAN$
	AA←1
	BB←13
	CC←14
	DD←15
HERE(ATAN$) 			;ENTRY TO ARCTANGENT ROUTINE
	MOVE	AA,-1(P)	;PICK UP THE ARGUMENT IN AA
ATAN1:	MOVM	BB, AA		;GET ABSF OF ARGUMENT
	CAMG	BB, A1		;IF X LESS THAN 2↑-33, THEN RETURN WITH...
	JRST	EXIT		;ATAN(X) = X
	HLLO	DD, AA		;SAVE SIGN, SET RH(DD) = -1
	CAML	BB, A2		;IF AA GREATER THAN 2↑33, THEN RETURN WITH
	JRST	AT4		;ATAN(X) = PI/2
	MOVSI	CC, (1.0)	;FORM 1.0 IN CC
	CAMG	BB, CC		;IS ABSF(X) GREATER THAN 1.0?
	TRZA	DD, -1		;IF BB .LE. 1.0, THEN RH(DD) = 0
	FDVM	CC, BB		;BB IS REPLACED BY 1.0/BB
	TLC	DD, (DD)	;XOR SIGN WITH .G. 1.0 INDICATOR
	PUSH	P,BB		;SAVE THE ARGUMENT
	FMP	BB, BB		;GET BB↑2
	MOVE	CC, KB3		;PICK UP A CONSTANT
	FAD	CC, BB		;ADD BB↑2
	MOVE	AA, KA3		;ADD IN NEXT CONSTANT
	FDVM	AA, CC		;FORM -A3/(B↑2 + B3)
	FAD	CC, BB		;ADD BB↑2 TO PARTIAL SUM
	FAD	CC, KB2		;ADD B2 TO PARTIAL SUM
	MOVE	AA, KA2		;PICK UP -A2
	FDVM	AA, CC		;DIVIDE PARTIAL SUM BY -A2
	FAD	CC, BB		;ADD BB↑2 TO PARTIAL SUM
	FAD	CC, KB1		;ADD  B1 TO PARTIAL SUM
	MOVE	AA, KA1		;PICK UP A1
	FDV	AA, CC		;DIVIDE PARTIAL SUM BY A1
	FAD	AA, KB0		;ADD B0
	FMP	AA,(P)		;MULTIPLY BY ORIGINAL ARGUMENT
	TRNE	DD, -1		;CHECK .G. 1.0 INDICATOR
	FSB	AA, PIOT	;ATAN(AA) = -(ATAN(1/AA)-PI/2)
	SUB	P,X11
	SKIPA	0,0		;SKIP
AT4:	MOVE	AA, PIOT	;GET PI/2 AS ANSWER
	SKIPGE	DD		;LH(DD) = -SGN(BB) IF BB GREATER THAN 1.0
	MOVNS	AA		;NEGATE ANSWER
EXIT:	SUB	P,X22
	JRST	@2(P)
A1:	145000000000		;2**-33
A2:	233000000000		;2**33
KB0:	176545543401		;0.1746554388
KB1:	203660615617		;6.762139240
KB2:	202650373270		;3.316335425
KB3:	201562663021		;1.448631538
KA1:	202732621643		;3.709256262
KA2:	574071125540		;-7.106760045
KA3:	600360700773		;-0.2647686202
PIOT:	201622077325		;PI/2
BEND ATAN$
BEGIN ASIN$
	AA←13
	BB←1
HERE(ASIN$) 			;ENTRY TO ASIN ROUTINE
	MOVM	BB,-1(P)	;GET MAGNITUDE OF ARG. IN BB
	CAMLE	BB,ONE		;IS THE MAGNITUDE OF THE ARG. LE 1.0?
	JRST	TOOLRG		;NO, GO TO ERROR RETURN.
	MOVN	AA,-1(P)	;GET THE NEGATIVE OF ARG
	FMP	AA,-1(P)	;CALCULATE -(X↑2)
	JFOV	.+1		;SUPPRESS ERROR MESSAGE FROM OVTRAP
	FAD	AA, ONE		;CALCULATE 1-(X↑2)
	JUMPE	AA, ASIN1	;WAS X EITHER -1.0 OR 1.0?
	PUSH	P,AA		;NO,
	PUSHJ	P,SQRT$		;CALCULATE SQRT(1-X↑2)
	MOVE	AA,-1(P)	;GET THE ARGUMENT BACK AGAIN
	FDV	AA,BB		;CALCULATE X/SQRT(1-X↑2)
	PUSH	P,AA		;THEN
	PUSHJ	P,ATAN$		;CALCULATE ATAN(X/SQRT(1-X↑2)),.
EXIT:	SUB	P,X22
	JRST	@2(P)
TOOLRG:	ERR <ASIN: Argument mangitude greater than 1.0; 0 returned>,1
	TDZA	BB,BB
ASIN1:	MOVE	BB, PIOT	;ANSWER IS EITHER PI/2 OR-PI/2
	SKIPG	-1(P)		;WAS ORIGINAL ARGUMENT POSITIVE?
	MOVNS	BB		;NO, GET -PI/2
	JRST	EXIT
PIOT:	201622077325		;PI/2
ONE:	1.0
BEND ASIN$
BEGIN ACOS$
HERE(ACOS$)			;ENTRY TO ACOS ROUTINE.
	MOVM	1,-1(P)		;GET /ARG./ IN AC 1.
	CAMLE	1,ONE		;IS MAGNITUDE OF ARG. GT 1.0?
	JRST	TOOLRG		;YES, GO TO ERROR RETURN.
	JUMPE	1,ZERARG	;IF ARG=0, GO TO ZERARG.
	FMPR	1,1		;X↑2 IN AC 1.
	JFOV	.+1		;SUPPRESS ERROR MESSAGE FROM OVTRAP
	MOVNS	1		;-X↑2 IN AC 1.
	FAD	1,ONE		;1.0-X↑2 IN AC 1.
	PUSH	P,1
	PUSHJ	P,SQRT$		;CALC. $SQRT(1.0-X↑2).
	FDVR	1,-1(P)		;($SQRT(1.0-X↑2))/X IS IN AC 1.
	JFOV	.+1		;SUPPRESS ERROR MESSAGE FROM OVTRAP
	PUSH	P,1
	PUSHJ	P,ATAN$		;FIND $ATAN($SQRT(1.0-X↑2)/X).
	SKIPL	-1(P)		;SKIP IF ORIGINAL ARG LESS THAN 0.
	JRST	EXIT		;RETURN.
	FAD	1,PII		;ANSWER IS PI + ANSWER IN AC 1.
EXIT:	SUB	P,X22
	JRST	@2(P)
TOOLRG:	ERR <ACOS: Argument magnitude greater than 1.0;  0 returned>,1
	TDZA	1,1		;RETURN ZERO.
ZERARG:	MOVE	1,PI2		;ANSWER IS PI/2
	JRST	EXIT
ONE:	1.0
PI2:	201622077325
PII:	202622077325
BEND ACOS$
BEGIN ATAN2$
	AA←13
	BB←1
HERE(ATAN2$) 			;ENTRY POINT TO ATAN2 ROUTINE
	JFOV	.+1		;CLEAR FLAGS FOR GOOD MEASURE (JAM)
	MOVE	AA,-2(P)	;PICK UP FIRST ARGUMENT
	MOVE	BB,-1(P)	;PICK UP SECOND ARGUMENT
	FDVR	AA, BB		;FORM AA/BB
	JFOV	OVUNFO		;EXTRA JFCL BECAUSE OF FDV HARDWARE BUG
	JFOV	OVUNFO		;SUPPRESS ERROR MESSAGE FROM
	PUSH	P,AA		;CALCULATE ATAN(AA/BB)
	PUSHJ	P,ATAN$
	SKIPL	-1(P)		;IF BB GREATER THAN 0, SGN(ATAN2)=SGN(A)
	JRST	EXIT		;EXIT
	JUMPGE	BB, ATAN2A	;IS BB POSITIVE?
	FADR	BB, PII		;NO, SECOND QUADRANT, ADD PI
EXIT:	SUB	P,X33
	JRST	@3(P)
ATAN2A:	FSBR	BB, PII		;YES,3RD QUADRANT, SUBTRACT PI
	JRST	EXIT		;EXIT
OVUNFO:	SKIPN	AA,OVPCWD	;PICK UP FLAGS.
	JSP	AA,.+1
	TLNE	AA,100		;SKIP IF OVERFLOW
	 JRST	 UNDER
	MOVE	BB,HALFPI	;ANSWER TO PI OVER 2
	SKIPGE	-2(P)		;SKIP IF ANS IS TO BE +
	 MOVNS	 BB
	JRST	EXIT
UNDER:	JUMPL	BB,BNEG
	MOVEI	BB,0
	JRST	EXIT		;RETURN 0
BNEG:	MOVE	BB,PII
	SKIPGE	-2(P)
	 MOVNS	 BB
	JRST	EXIT
PII:	202622077325		;PII
HALFPI:	201622077325		;PII/2
BEND ATAN2$
ENDCOM(TG2)