      SKP 
**                          **
***  COMPUTE CHEBYSHEV(X)  ***
**                          **
#CHEB JSB .FMP
      DEF K2
      DST X2TMP     X2TMP = X*2 
      LDB .CHEB,I 
      STB CTMP      POINTER TO COEFFICIENT TABLE
      DLD 1,I 
      DST DTMP      DTMP = COEFF(N) 
      CLA 
      STA BTMP
      STA BTMP+1    B = 0 
CHEB1 ISZ CTMPWW
      ISZ CTMP      N = N-1 
      LDA CTMP,I
      SZA,RSS       C(N) = 0? 
      JMP CHEB2     YES 
      DLD BTMP      NO
      DST ATMP      A = B 
      DLD DTMP
      DST BTMP      B = D 
      JSB .FMP--
      DEF X2TMP 
      JSB .FSB
      DEF ATMP
      JSB .FAD
      DEF CTMP,I
      DST DTMP      D = COEFF(N)-A+B*X2 
      JMP CHEB1 
CHEB2 DLD DTMP
      JSB .FSB
      DEF ATMP
      JSB .FMP
      DEF HALF
      ISZ .CHEB     ANS = (D-A)/2 
      JMP .CHEB,I 
      SPC 1 
* *                *
**  EXECUTE TAB(X)  * 
* *                *
ETAB  JSB .IENT     INTEGERIZE ARGUMENT 
      LDA .72       ARG > 32767 
      CLB           SET FLAG TO 
      STB EOL         'TAB OCCURRED'
      ADA M72       IS ARGUMENT 
      SSA,RSS         > 71 ?
      JMP ETAB2 
      ADA .72       NO
      CMA,INA       ANY 
      ADA CHRCT       BLANKS
      SSA,RSS           REQUIRED? 
      JMP ETAB2+1   NO
      STA LBTMP     YES 
ETAB1 LDA .+40B     OUTPUT
      JSB OUTCR       A BLANK 
      ISZ LBTMP     DONE? 
      JMP ETAB1     NO
      RSS           YES SY
ETAB2 JSB OUTLN     MOVE TO NEXT LINE 
      LDA BIT15     INSURE THAT OPCHK DOESN'T BARF
      JMP FRET,I
* *                *
**  COMPUTE ABS(X)  * 
* *                *
EABS  SSA           ARGUMENT NEGATIVE?
      JSB ARINV     YES, NEGATE IT
      JMP FRET,I    NO
      SPC 1 
**                    **
***  LIBRARY ENTIER  ***
**                    **
* 
*  ENTER WITH NUMBER IN (A) AND (B).  IF EXPONENT > 14
*  THEN EXIT TO (P+1), ELSE EXIT TO (P+2) WITH THE
*  ENTIER OF THE ARGUMENT IN (A). 
* 
#IENT STA LBTMP     SAVE (A)
      LDA 1         EXTRACT 
      AND B377        EXPONENT
      SLA,RAR       NEGATIVE? 
      JMP IENT1     YES 
      ADA .-15      NO, LESS THAN 
      SSA,RSS         OR EQUAL TO 14? 
      JMP .IENT,I   NO
IENT1 ISZ .IENT     YES 
      LDA LBTMP     RESTORE (A) 
      JSB IFIX      TAKE ENTIER 
      NOP 
      LDA 1         LOAD INTEGER
      JMP .IENT,I     INTO (A)
      SPC 2 
**                              **
***  MULTIPLY BY A POWER OF 2  ***
**                              **
* qq
*  ENTER WITH NUMBER IN (A) AND (B).  AUGMENT EXPONENT
*  BY THE VALUE POINTED TO BY (P+1) AND EXIT TO (P+2).
*  NO CHECK ON EXPONENT UNDERFLOW OR OVERFLOW.
* 
#PWR2 SZA,RSS       ARGUMENT ZERO?
      JMP PWR2A     YES, RETURN 0 
      STA X2TMP     NO, SAVE HIGH PART OF MANTISSA
      JSB .FLUN     UNPACK LOW PART OF NUMBER 
      STB X2TMP+1   SAVE LOW MANTISSA 
      LDB .PWR2,I   COMPUTE NEW 
      ADA 1,I         EXPONENT
      RAL           POSITION
      AND B377        AND MASK IT 
      STA 1         COMPUTE NEW LOW 
      ADB X2TMP+1     PART OF NUMBER
      LDA X2TMP     RETRIEVE HIGH MANTISSA
PWR2A ISZ .PWR2 
      JMP .PWR2,I 
* *                *
**  COMPUTE COS(X)  * 
* *                *
ECOS  JSB .FAD      COMPUTE 
      DEF PIBY2       SIN(X+PI/2) 
* *                *
**  COMPUTE SIN(X)  * 
* *                *
ESIN  JSB .FMP
      DEF TOPI
      DST XTEMP     X = 2*X/PI
      JSB .FAD
      DEF K1
      JSB .PWR2 
      DEF .-2 
      JSB .IENT 
      JSB RERRS+31,I  EXPONENT EXCEEDS 14 
      OCT 105120   FLT
      JSB .FMP
      DEF MM4 
      JSB .FAD
      DEF XTEMP 
      DST XTEMP     X = X-4*ENTIER((X+1)/4) 
      JSB .FSB
      DEF K1
      SSA           X<1?
      JMP ESIN1     YES 
      DLD K2        NO
      JSB .FSBS
      DEF XTEMP 
      DST XTEMP     X = 2-X 
ESIN1 DLD XTEMP 
      JSB .FMP
      DEF XTEMP 
      JSB .PWR2 
      DEF .+1 
      JSB .FSB
      DEF K1
      JSB .CHEB 
      DEF COEF2 		
      JSB .FMP
      DEF XTEMP 
      JMP FRET,I    ANS = X*CHEBY(2*X^2 -1) 
* 
TOPI  DEC .636619772     2/PI 
MM4   DEC -4. 
COEF2 DEC 1.18496E-6
      DEC -1.365875E-4
      DEC 9.118016E-3 
      DEC -.2852615692
      DEC 2.5525579248
      OCT 0 0Q
* *                *
**  COMPUTE TAN(X)  * 
* *                *
ETAN  JSB .FMPMy
      DEF FOPI      4/PI
      DST XTEMP 
      JSB .FAD
      DEF K1K]
      JSB .PWR2 
      DEF .-2 25
      JSB .IENT 
      JSB RERRS+31,I
      OCT 105120    FLT 
      JSB ARINV 
      JSB .PWR2 
      DEF .+2 
      JSB .FAD
      DEF XTEMP 
      DST XTEMP     X = X-4*ENTIER((X+1)/4) 
      JSB .FSB
      DEF K1
      STA LBTMP 
      SSA           X<1?
      JMP ETAN2     YES 
      DLD K2        NO
      JSB .FSB
      DEF XTEMP 
ETAN1 DST YTEMP     Y = 2-X 
      JSB .FMP
      DEF YTEMP 
      JSB .FMP
      DEF K2
      JSB .FSB
      DEF K1K]
      JSB .CHEB 
      DEF COEF0 
      JSB .FMP
      DEF YTEMP 
      DST YTEMP     Y = Y*CHEBY(2*Y^2 -1) 
      LDA LBTMP 
      SSA           X<1?
      JMP ETAN3     YES 
      DLD K1        NO
      JSB .FDV
      DEF YTEMP 
      JMP FRET,I    ANS = 1/Y 
ETAN2 DLD XTEMP 
      JMP ETAN1     Y = X 
ETAN3 DLD YTEMP 
      JMP FRET,I    ANS = Y 
* 
FOPI  DEC 1.273239545 
K1    DEC 1.
K2    DEC 2.
COEF0 DEC 1.4458E-8 
      DEC 2.013766E-7 
      DEC 2.804816E-6 
      DEC 3.906637E-5 
      DEC 5.4417038E-4
      DEC 7.586101578E-3
      DEC .10675392857
      DEC 1.7701474227
      OCT 0 
* *                *
**  COMPUTE ATN(X)  * 
* *                *
EATN  DST XTEMP 
      LDA 1 
      AND B377??
      STA LBTMP 
      SZA 
      SLA           ABS(X) > 1? 
      JMP EATN2     NO
      DLD K1        YES 
      JSB .FDV
      DEF XTEMP     U = 1/X 
EATN1 DST UTEMP 
      JSB .FMP
      DEF UTEMP 
      JSB .FMP
      DEF K2
      JSB .FSB
      DEF K1
      JSB .CHEB 
      DEF COEF1 
      JSB .FMP
      DEF UTEMP 
      DST YTEMP     Y = U*CHEBY(2*U^2 -1) 
      LDA LBTMP 
      SZA 
      SLA           ABS(X) > 1? 
      JMP EATN3     NO
      LDA XTEMP     YES 
      SSA           X<0?
      JMP EATN4     YES 
      DLD PIBY2     NON7
      JMP EATN4+2 
EATN2 DLD XTEMP 
      JMP EATN1     U = X 
EATN3 DLD YTEMP 
      JMP FRET,I    ANS = Y 
EATN4 DLD MP2 
      JSB .FSBS
      DEF YTEMP 
      JMP FRET,I    ANS = -PI/2-Y 
* 
PIBY2 DEC 1.5707963268   PI/2 
MP2   DEC -1.5707963268  -PI/2
COEF1 DEC -1.33034E-8 
      DEC 8.64888E-8
      DEC -56.99186E-8
      DEC 3.821037E-6 
      DEC -2.6215196E-5 
      DEC 1.8574297E-4
      DEC -1.381195004E-3 
      DEC .01113584206
      DEC -.1058929245
      DEC 1.762747174 
      OCT 0 
* *                *
**  COMPUTE EXP(X)  * 
* *                *
EEXP  JSB .EXP
      JMP FRET,I
#EXP  JSB .FMPMi
      DEF L2E 
      DST XTEMP     X = ARG*LOG2(E) 
      JSB .IENT 
      JMP .EXP2 
      STA LBTMP 
      OCT 105120   FLT
      DST YTEMP     Y = ENTIER(X) 
      LDA LBTMP 
      ADA M124
      SSA,RSS       X >= 124? 
      JMP .EXP2     YES 
      ADA .244      NO
      SSA           X < -120? 
      JMP .EXP1     YES 
      DLD XTEMP     NO
      JSB .FSB
      DEF YTEMP 
      DST XTEMP     X = X-ENTIER(X) 
      JSB .FMP
      DEF XTEMP 
      DST UTEMP     U = X^2 
      JSB .FADA$
      DEF AAAA
      DST YTEMP     Y = X^2+AAAA
      DLD BBBB
      JSB .FDV
      DEF YTEMP 
      DST YTEMP     Y = BBBB/Y
      DLD CCCC
      JSB .FMP
      DEF UTEMP 
      JSB .FAD
      DEF DDDD
      JSB .FSB
      DEF XTEMP 
      JSB .FSB
      DEF YTEMP 
      DST YTEMP     Y = -X+DDDD+CCCC*X^2-Y
      DLD XTEMP 
      JSB .FDV
      DEF YTEMP 
      JSB .FAD
      DEF HALF
      ISZ LBTMP 
      NOP 
      JSB .PWR2 2I
      DEF LBTMP 
      JMP .EXP,I    ANS = (0.5+X/Y)*2^ENTIER(ARG*LE)
.EXP1 CLA 
      CLB 
      JMP .EXP,I    ANS = 0 
.EXP2 LDA LBTMP     LARGE ARGUMENT
      SSA           NEGATIVE? 
      JMP .EXP1     YES 
      JSB WERRS+4,I NO
      LDA INF F#
      LDB .-2       ANS = POSITIVE INFINITY 
      JMP .EXP,I
* 
M124  DEC -124%%
.244  DEC 244 
AAAA  DEC 87.417497202
BBBB  DEC 617.9722695 
CCCC  DEC .03465735903
DDDD  DEC 9.9545957821
L2E   DEC 1.4426950409
      SKP 
* *                *
**  COMPUTE LOG(X)  * 
* *                *
ELOG  JSB .LOGOO
      JMP FRET,I
#LOG  SZA,RSS       NON-ZERO ARGUMENT?
      JMP .LOG1     NO
      SSA           YES, POSITIVE ARGUMENT? 
      JSB RERRS+27,I  NO
      STA XTEMP     YES,
      JSB .FLUN       SAVE MANTISSA 
      STB XTEMP+1       AND FLOATED 
      OCT 105120           EXPONENT 
      DST YTEMP             SEPARATELY
      DLD XTEMP P
      JSB .FAD
      DEF R22 2N
      DST UTEMP     U = X+SQR(0.5)
      DLD XTEMP 
      JSB .FSB
      DEF R22 
      JSB .FDV
      DEF UTEMP 
      DST UTEMP     U = (X-SQR(0.5))/U
      JSB .FMP
      DEF UTEMP 
      JSB .FSB
      DEF CCC 
      DST XTEMP 
      DLD MB
      JSB .FDV
      DEF XTEMP 
      JSB .FAD
      DEF AAA 
      JSB .FMP
      DEF UTEMP 
      JSB .FSB
      DEF HALF
      JSB .FAD
      DEF YTEMP 
      JSB .FMP
      DEF LE2       ANS = LOG(2)* 
      JMP .LOG,I      (MANTISSA-0.5+U*(AAA+MB/X)) 
.LOG1 JSB WERRS+1,I 
      LDA MNEG
      LDB B776      ANS = NEGATIVE INFINITY 
      JMP .LOG,I
* 
R22   DEC .707106781     SQR(0.5) 
LE2   DEC .6931471806    LOG BASE E (2) 
AAA   DEC 1.2920070987
MB    DEC -2.6398577035 
CCC   DEC 1.6567626301
      SKP 
* *                *
**  COMPUTE SQR(X)  * 
* *                *
ESQR  SZA,RSS       X= 0? 
      JMP FRET,I    YES, ANS = 0
      SSA           NO, X < 0?
      JSB RERRS+28,I  YES 
      STA XTEMP     NO
      JSB .FLUN 
      SLA,ARS       EXPONENT ODD? 
      JMP ESQR2     YES 
      ADA .-1       NO
      STA LBTMP     EXPONENT/2 -1 
      STB XTEMP+1   MANTISSA SAVED
      LDA XTEMP P/
      JSB .FMP
      DEF SA2 
      JSB .FAD
      DEF SB2       Y = SB2+SA2*X 
ESQR1 DST YTEMP Pi
      DLD XTEMP 
      JSB .FDV
      DEF YTEMP 
      JSB .FAD
      DEF YTEMP 
      JSB .PWR2 
      DEF .-1 
      DST YTEMP     Y = (Y+X/Y)/2 
      DLD XTEMP 
      JSB .FDV
      DEF YTEMP 
      JSB .FAD
      DEF YTEMP 
      JSB .PWR2 2I
      DEF LBTMP 
      JMP FRET,I    ANS = (P+F/P)*2^ESQ0
ESQR2 STA LBTMP     EXPONENT/2
      ADB B377
      STB XTEMP+1   MANTISSA/2 SAVED
      LDA XTEMP 
      JSB .FMP
      DEF SA1 
      JSB .FAD
      DEF SB1 
      JMP ESQR1     Y = SB1+SA1*X 
* 
SA1   DEC .875
SA2   DEC .578125 
SB1   DEC .27863
SB2   DEC .421875 
      HED ASCII TO BINARY NUMBER CONVERSION 
**                     ** 
***  HANDLE OVERFLOW  *** 
**                     ** 
* 
*  (A) CONTAINS THE HIGH MANTISSA UPON ENTRY.  (A) AND
*  (B) CONTAIN THE LARGEST REPRESENTABLE NUMBER OF
*  APPROPRIATE SIGN, PACKED, UPON EXIT. 
* 
#OVFL LDB .-2 
      SSA 
      LDB B776
      IOR INF F~
      SSA 
      LDA MNEG
      JMP OVFLW,I 
**                       ** 
***  LOOK FOR A NUMBER  *** 
**                       ** 
* *q
*  NUMCK LOOKS FOR AN UNSIGNED NUMBER, SIGN MUST BE SET 
*  BY THE CALLER (SIGN = -1 FOR NEGATIVE, ELSE POSITIVE). 
*  (A) CONTAINS A CHARACTER UPON ENTRY; IF IT IS NEITHER
*  A DIGIT NOR A DECIMAL POINT, EXIT IS TO (P+1) WITH 
*  (A) UNCHANGED AND (B) = 0.  EXIT IS TO ERROR ON FINDING
*  AN EXPONENT PART OF INCORRECT FORMAT.  ZERO REPLACES AN
*  UNDERFLOW; THE LARGEST REPRESENTABLE NUMBER OF THE 
*  APPROPRIATE SIGN REPLACES AN OVERFLOW.  AFTER STORING A
*  FLOATING POINT NUMBER IN M AND M+1 (WHERE SBPTR,I = M) 
*  EXIT IS TO (P+2) WITH THE NEXT INPUT STRING CHARACTER
*  IN (A) AND TEMP+1. 
* 
#NMCK CLB           ZERO
      STB EXP         ALL 
      STB MANT1         COMPONENTS
      STB MANT2           OF THE
      STB EXPON             NUMBER
      STB TEMP+1    SET 'NUMBER FLAG' FALSE 
      CCB           SET 'DECIMAL POINT' 
      STB DPFLG            FLAG FALSE 
NUMC1 CPA .+56B     DECIMAL POINT?
      ISZ DPFLG     YES 
      JMP NUMC2     NO
      CLA           ZERO POST-DECIMAL 
      STA EXPON       DIGIT 
      JMP NUMC4+1       COUNTER 
NUMC2 JSB DIGCK     DIGIT?
      JMP NUMC7     NO
      ISZ EXPON     YES, COUNT DIGIT
      ASL 11        LEFT-JUSTIFY DIGIT
      STA TEMP+2      AND SAVE IT 
      JSB MBY10     MULTIPLY PREVIOUS NUMBER BY 10
      LDB EXP       ZERO
      SZB,RSS         EXPONENT? 
      JMP NUMC6     YES 
      ADB .-4       NO, 
      CMB             SAVE
      LDA TEMP+2        SHIFT 
      STB TEMP+2          COUNT 
      CLB           CLEAR LOWER MANTISSA
NUMC3 ISZ TEMP+2    ALL SHIFTS DONE?
      JMP NUMC5     NO
      CLE           YES, ADD IN 
      ADB MANT2       LOW PART
      CLO               OF NUMBER 
      SEZ           OVERFLOW FROM (B)?
      INA           YES 
      ADA MANT1     ADD IN HIGH PART OF MANTISSA
      SOS           OVERFLOW? 
      JMP NUMC4     NO
      CLE,ERA       YES, CORRECT
      ERB             MANTISSA
      ISZ EXP           AND BUMP
      NOP                 EXPONENT
NUMC4 JSB NORML     NORMALIZE THE NUMBER
      ISZ TEMP+1    SET 'NUMBER FLAG' TRUE
      JSB GETCR     FETCH CHARACTER 
      JMP NUM12-1   NONE FOUND
      JMP NUMC1 
NUMC5 CLE,ERA       SHIFT 
      ERB             DIGIT 
      JMP NUMC3         RIGHT 
NUMC6 LDA .+4       SET 
      STA EXP         EXPONENT
      LDA TEMP+2    LOAD
      CLB             NUMBER
      JMP NUMC4 //
NUMC7 CLB           SET EXPONENT
      STB TEMP+2      SIGN TO '+' 
      CPB TEMP+1    DIGIT OR DECIMAL POINT FOUND? 
      JMP NUMCK,I   NO
      CPA E         'E' ? 
      RSS           YES 
      JMP NUM12     NO
      JSB GETCR     FETCH CHARACTER 
      JMP NUM16     NONE FOUND
      CPA .+53B     '+' ? 
      JMP NUMC8     YES 
      CPA .+55B     NO, '-' ? 
      CCA,RSS       YES 
      JMP NUMC9     NO
      STA TEMP+2    SET EXPONENT SIGN TO '-'
NUMC8 JSB GETCR     FETCH CHARACTER 
      JMP NUM16     NONE FOUND
NUMC9 JSB DIGCK     DIGIT?
      JMP NUM16     NO
      STA TEMP+1    YES, SAVE IT
      JSB GETCR 
      JMP NUM11 
      JSB DIGCK     DIGIT?
      JMP NUM11     NO
      LDA TEMP+1    YES, MULTIPLY 
      STB TEMP+1      PREVIOUS DIGIT
      MPY .+10          BY 10 
      ADA TEMP+1    ADD IN NEW DIGIT
      STA TEMP+1    SAVE EXPONENT 
      JSB GETCR 
      JMP NUM11 
      JSB DIGCK     THIRD DIGIT?
      RSS           NO
      JMP NUM16     YES 
NUM11 LDB TEMP+1    LOAD EXPONENT 
      ISZ TEMP+2    POSITIVE? 
      CMB,INB       YES, COMPLEMENT IT
      RSS           NO
      CLB 
NUM12 STA TEMP+1    SAVE CHARACTER
      ISZ DPFLG     DECIMAL POINT FOUND?
      ADB EXPON     YES, CORRECT EXPONENT 
      SZB,RSS       NO, ZERO EXPONENT?
      JMP NUM14     YES 
      SSB           NO, POSITIVE EXPONENT?
      JMP NUM13     YES 
      CMB,INB       NO, SET 
      STB EXPON       COUNTER 
      JSB DBY10     DIVIDE NUMBER BY 10 
      ISZ EXPON     DONE? 
      JMP *-2       NO
      JMP NUM14     YES 
NUM13 STB EXPON     SET COUNTER 
      JSB MBY10     MULTIPLY NUMBER BY 10 
      ISZ EXPON     DONE? 
      JMP *-2       NO
NUM14 LDA MANT1     LOAD
      LDB MANT2       MANTISSA
      ISZ SIGN      POSITIVE? 
      JMP NUM15     YES 
      CMA           NO, COMPLEMENT
      CMB,INB,SZB,RSS  THE
      INA                NUMBER 
NUM15 JSB .PACK     NORMALIZE AND PACK
      STA SBPTR,I   STORE 
      JSB SBPUD       NUMBER IN 
      STB SBPTR,I       DESTINATION 
      JSB SBPUD           ADDRESS 
      LDA TEMP+1    RETRIEVE CHARACTER
      ISZ NUMCK 
NUM16 ISZ NUMCK 
      JMP NUMCK,I 
