/***** FLOAT -- FOR FOCAL 5/69 *****
/E.A.TAFT  25-JUL-72
*5600
/DECIMAL TO BINARY CONVERSION 2/10/69
DBCONV,	0
	FLOAT		/FLOAT A ZERO
	DCA DECEXP	/INITIALIZE
	CMA
	DCA PSWIT
	TAD C43	/35(10)
	DCA FLAC0
	JMS I SGNTST	/SIGN OF MANTISSA
	DCA INSIGN
	JMP NEWDIG+1
PERIOD,	ISZ PSWIT	/. FOUND, SEE IF FIRST
	ERROR		/DOUBLE PERIODS
NEWDIG,	GETC		/LOOK FOR A DIGIT
	TESTN
	JMP PERIOD	/. FOUND
	JMP NOTDIG	/NOT FOUND
	TAD PSWIT	/DECREMENT DECIMAL EXPONENT
	SMA CLA		/IF AFTER .
	CMA
	TAD DECEXP
	DCA DECEXP
	JMS MULT10	/MULTIPLY FLAC BY 10
	TAD SORTCN	/ADD NEW DIGIT
	DCA FLOP3
	DCA FLOP2
	DCA FLOP1
	JMS TRPLAD
OVCHEK,	TAD REMAIN	/CHECK FOR OVERFLOW
	SZA CLA
	JMP .+4
	TAD FLAC1
	SMA CLA
	JMP NEWDIG	/NO OVERFLOW
	TAD IOVRL	/OVERFLOW, ROTATE RIGHT
	DCA I IRARAC	/SET UP RETURN TO OVCHEK
	TAD REMAIN	/ROTATE REMAIN
	CLL RAR
	DCA REMAIN
	TAD FLAC1
	JMP I ROTRAC	/ROTATE REST OF FLAC

NOTDIG,	SORTC		/TEST FOR LETTER E
	 C305-1
	JMP EINPUT	/FOUND E
DBTERM,	ISZ INSIGN	/END OF INPUT, AFFIX SIGN
	NEGATE
	TAD CFNR	/SET UP TO NORMALIZE
DBLOOP,	DCA .+2
	FENT
PSWIT,	FNR		/OR FMY BY 10 OR .10
	FPT I PT1	/SAVE RESULT
	FEXT
	TAD DECEXP	/CHECK DECIMAL EXPONENT
	SNA
	JMP I DBCONV	/DONE
	SMA
	JMP .+4
	IAC		/NEGATIVE, SET UP TO FMY BY .10
	DCA DECEXP
	JMP .+5
	CLA CMA		/POSITIVE, SET UP TO FMY BY 10
	TAD DECEXP
	DCA DECEXP
	TAD M3
	TAD FLINST	/INSTRUCTION FMY FLTEN OR FLPTEN
	JMP DBLOOP
EINPUT,	GETC		/FOUND "E"
	JMS I SGNTST	/TEST FOR SIGN
	DCA FLOP0
	JMS I DECIN1	/INPUT A DECIMAL INTEGER
	TAD DECNUM
	ISZ FLOP0	/CHECK SIGN
	CIA
	TAD DECEXP
	DCA DECEXP
	JMP DBTERM
/ADD FLOP TO FLAC TRIPLE PRECISION WITH OVERFLOW
TRPLAD,	0
	CLA CLL
	TAD FLOP3
	TAD FLAC3
	DCA FLAC3
	RAL
	TAD FLOP2
	TAD FLAC2
	DCA FLAC2
	RAL
	TAD FLOP1
	TAD FLAC1
	DCA FLAC1
	RAL
	TAD REMAIN
	DCA REMAIN
	JMP I TRPLAD
/MULTIPLY FLAC BY 2
MULT2,	0
	JMS I MULT2I
	TAD REMAIN
	RAL
	DCA REMAIN
	JMP I MULT2
/MULTIPLY FLAC BY 10
MULT10,	0
	PUSHF		/FLAC=>FLOP
	 FLAC1
	POPF
	 FLOP1
	DCA REMAIN	/CLEAR OVERFLOW
	JMS MULT2	/FLAC*10 = (FLAC*2*2+FLAC)*2
	JMS MULT2
	JMS TRPLAD
	JMS MULT2
	JMP I MULT10
SGNTST,	TSTSGN
MULT2I,	RALAC
DECIN1,	DECINT
IRARAC,	RARAC
IOVRL,	OVCHEK
ROTRAC,	RARAC+5
C43,	43
DECEXP,	0	/IMPLICIT DECIMAL EXPONENT
INSIGN,	0	/SIGN OF MANTISSA
CFNR,	FNR
FLINST,	FMY .+4
FLTEN,	0004	/10(10) FLOATING
	2400
	0000
FLPTEN,	7775	/.10(10) FLOATING
	3146
	3147
REMAIN=TEMP1
/CHARACTER LIST FOR "ASK"
ASKLST,	215	/CR
	214	/FF
	337	/BA
	254	/COMMA
USERT,	0	/USER-SELECTED CHARACTER
	212	/LF
/POWER OF 10 TABLE
INTABL,	-1750	/1000
	-144	/100
	-12	/10
	-1	/1
/INPUT A DECIMAL INTEGER <2048
DECINT,	0
	DCA DECNUM
	TESTN		/GET A DIGIT
	NOP
	JMP I DECINT	/NONE FOUND
	GETC
	TAD DECNUM	/MULTIPLY PREV. # BY 10
	CLL RTL
	SPA SZL
	JMP .+5		/OVERFLOW (>2047)
	TAD DECNUM
	RAL
	TAD SORTCN	/ADD NEW DIGIT
	SPA SZL
	ERROR
	JMP DECINT+1
DECNUM=TEMP3
/TEST FOR A SIGN
TSTSGN,	0
	SPNOR
	DCA SORTCN
	SORTC		/LOOK FOR + OR -
	 SNLIST-1
	GETC		/SIGN FOUND
	SPNOR		/NOT FOUND
	CLA CMA
	TAD SORTCN	/SORTCN: 0=+, 1=-
	JMP I TSTSGN	/AC: 7777=+, 0=-
DIGIT=TEMP2
/PRINT A 2-4 DIGIT UNSIGNED DECIMAL INTEGER
/FIRST 2 LEADING ZEROES NOT PRINTED
INTOUT,	0
	DCA DECNUM
	TAD INTPTR	/POWER OF 10 POINTER
	DCA INTSUB
	DCA DECINT	/DECINT=0 MEANS SKIP 0 OUTPUT
	JMS INTDO	/1ST DIGIT (1000S)
	JMS INTDO	/2ND DIGIT (100S)
	ISZ DECINT	/DECINT>0 MEANS PRINT 0S
	JMS INTDO	/3RD DIGIT (10S)
	JMS INTDO	/4TH DIGIT (UNITS)
	JMP I INTOUT
INTDO,	0
	DCA DIGIT	/INITIALIZE
	TAD DECNUM
INTSUB,	TAD INTABL	/SUBTRACT A POWER OF 10
	SPA
	JMP INTNEG
	DCA DECNUM	/POSITIVE RESULT
	ISZ DIGIT	/NONZERO DIGIT, SO IGNORE NO
	ISZ DECINT	/FURTHER ZEROES
	JMP INTSUB-1
INTNEG,	CLA CLL		/NEGATIVE RESULT
	ISZ INTSUB	/SET UP NEXT POWER OF 10
	TAD DECINT	/IS IT A LEADING 0?
	SNA CLA
	JMP I INTDO	/YES, SKIP IT
	TAD DIGIT	/NO, PRINT DIGIT
	TAD C260
	PRINTC
	JMP I INTDO
/OUTPUT A SIGNED INTEGER IN AC
SIGOUT,	0
	DCA DECNUM	/SAVE NUMBER
	TAD DECNUM
	SPA CLA
	TAD P2		/MAKE A -
	TAD C253	/MAKE A +
	PRINTC
	TAD DECNUM	/OUTPUT ABSOLUTE VALUE
	SPA
	CIA
	JMS INTOUT	/OUTPUT THE NUMBER
	JMP I SIGOUT
INTPTR,	TAD INTABL
SNLIST=.	/FOR SIGN TESTING
C253,	253	/+
	255	/-
/E FORMAT OUTPUT ROUTINE
XXX,	CLA		/CONVERT TO E FORMAT ON OVERFLOW
	TAD TOTDIG
	SKP
FLOUT,	TAD DECP	/E FORMAT (%0) FLOATING OUTPUT
	CIA
	SNA
	TAD MDIG	/6 DIGITS IF 0 GIVEN
	DCA DECNUM	/DIGIT COUNTER
	TAD PER		/PERIOD
	PRINTC
FLDIG,	TAD I XRT2	/NEXT DIGIT
	ISZ T2		/OUT OF SIG DIGITS?
	JMP .+3		/NO, PRINT DIGIT
	CLA CMA		/YES, RESET POINTER AND PRINT 0
	DCA T2
	JMS I OUTP
	SKP		/FIELD NOW FILLED, PRINT EXPONENT
	JMP FLDIG
/B-D CONV EXPONENT OUTPUT
	TAD C305	/PRINT LETTER E
	PRINTC
	TAD T1		/OUTPUT THE EXPONENT
	JMS SIGOUT
BDEND,	JMP I BDCONV	/DONE
C305,	305		/E
MDIG,	-DIGITS
OUTP,	OUTA
/PRINT A LINE NUMBER - "PRNTLN"
XPRNTL,	0
	TAD LINENO
	RTL6
	AND P77
	JMS INTOUT	/2-DIGIT PART NUMBER
	TAD PER
	PRINTC		/DECIMAL POINT
	TAD LINENO
	AND P177	/2-DIGIT STEP NUMBER
	JMS INTOUT
	TAD C240	/SPACE
	DCA CHAR
	PRINTC
	JMP I XPRNTL

NEGSGN,	255-240
/BINARY TO DECIMAL CONVERSION AND OUTPUT
BDCONV,	0
	TAD FLAC1	/CHECK SIGN
	SMA CLA
	JMP .+3
	NEGATE		/NEGATIVE, TAKE ABSOLUTE VALUE
	TAD NEGSGN	/MAKE A -
	TAD C240	/MAKE A SPACE
	PRINTC
	CLA CMA		/DECREMENT BINARY EXPONENT
	TAD FLAC0
	DCA FLAC0
BDSCAL,	DCA T1		/INITIALIZE DECIMAL EXPONENT
	TAD FLAC0	/START SCALING: -4<EXP<0?
	SMA
	JMP SDOWN	/TOO BIG, SCALE DOWN
	TAD I TENPT
	SMA CLA
	JMP SCALED	/WITHIN LIMITS, DONE
	FENT		/TOO SMALL, SCALE UP
	FMY I TENPT
	FEXT
	CLA CMA
	TAD T1		/DECREMENT DECIMAL EXPONENT
	JMP BDSCAL
SDOWN,	FENT		/SCALE DOWN
	FMY I PTENPT
	FEXT
	IAC		/INCREMENT DECIMAL EXPONENT
	JMP .-6
/CONSTANTS
DCOUNT,	-DIGITS-1
MDIGIT,	-DIGITS
RND2,	DIGITS+1
M12,	-12
/POINTERS
TENPT,	FLTEN
PTENPT,	FLPTEN
MULT2P,	MULT2
MUL10P,	MULT10
BUFST,	DIGBUF-1
FLOUTP,	FLOUT
XXXP,	XXX
/ROUTINE TO DECREMENT THE DIGIT POINTER
DECR,	CMA
	TAD FLOP0
	DCA FLOP0
	JMP RET
/FINISHED SCALING, GENERATE DIGITS
