Text preview for : Double.mesa_Mar78.pdf part of xerox Double.mesa Mar78 xerox mesa 3.0_1977 listing Double.mesa_Mar78.pdf
Back to : Double.mesa_Mar78.pdf | Home
DOUBLE.MESA 30-MAR-78 14:47:33 Page 1
-- Double.Mesa Edited by Sandman on August 11. 1977 2:59 PM
DIRECTORY
DoubleDefs: FROM "doubledefs".
InlineDefs: FROM "inlinedefs".
StringDefs: FROM "StringDefs";
DEFINITIONS FROM InlineDefs. DoubleDefs;
Double: PROGRAM IMPORTS StringDefs EXPORTS DoubleDefs
PUBLIC BEGIN
DDivide: PROCEDURE [num. den: LongCARDINAL]
RETURNS [quotient. remainder: LongCARDINAL]
BEGIN
qq. count: CARDINAL;
lTemp: LongCARDINAL;
IF den.highbits = 0 THEN
BEGIN
[quotient.highbits. qq] ~
LongDivMod[[lowbits:num.highbits.highbits:O].den.lowbits];
[quotient.lowbits. remainder.lowbits] ~
LongDivMod[[lowbits:num.lowbits.highbits:qq].den.lowbits];
remainder.highbits ~ 0;
END
ELSE
BEGIN
count ~ 0;
quotient.highbits ~ 0;
lTemp ~ den;
WHILE lTemp.highbits # 0 DO -- normalize
lTemp.lowbits ~
BITSHIFT[lTemp.lowbits.-1] + BITSHIFT[lTemp.highbits.15];
lTemp.highbits ~ BITSHIFT[lTemp.highbits.-1];
count ~ count + 1;
ENDLOOP;
qq ~ LongDiv[num.1Temp.lowbits]; -- trial quotient
qq ~ BITSHIFT[qq.-count];
lTemp ~ LongMult[den.lowbits.qq]; -- multiply by trial quotient
lTemp.highbits ~ lTemp.highbits + den.highbits*qq;
UNTIL DCompare[lTemp. num] # greater DO
-- decrease quotient until product is small enough
lTemp ~ DSub[lTemp.den];
qq ~ qq - 1;
ENDLOOP;
quotient.lowbits ~ qq;
remainder ~ DSub[num.1Temp];
END;
RETURN
END;
DMultiply: PROCEDURE [a.b: LongCARDINAL]
RETURNS [product: LongCARDINAL] =
BEGIN
product ~ LongMult[a.lowbits. b.lowbits];
product.highbits ~
product.highbits + a.lowbits*b.highbits + a.highbits*b.lowbits;
RETURN
END;
DAdd: PROCEDURE [a.b: LongCARDINAL] RETURNS [LongCARDINAL]
BEGIN
t: CARDINAL = a.lowbits;
a. lowbits ~ a.lowbits + b.lowbits;
a.highbits ~ a.highbits + b.highbits;
IF a.lowbits < t THEN a.highbits ~ a.highbits+1;
RETURN[a]
END;
DSub: PROCEDURE [a.b: LongCARDINAL] RETURNS [LongCARDINAL]
BEGIN
t: CARDINAL = a.lowbits;
a. lowbits ~ a.lowbits - b.lowbits;
a.highbits ~ a.highbits - b.highbits;
IF a.lowbits > t THEN a.highbits ~ a.highbits-1;
RETURN[a]
DOUBLE. MESA 30-MAR-78 14:47:33 Page 2
END;
DNeg: PROCEDURE [a: LongCARDINAL] RETURNS [LongCARDINAL] =
BEGIN
IF (a.lowbits ~ -a.lowbits) = 0 THEN a.highbits ~ -a.highbits
ELSE a.highbits ~ BITNOT[a.highbits];
RETURN[a];
END;
DIne: PROCEDURE [a: LongCARDINAL] RETURNS [LongCARDINAL]
BEGIN
IF (a.lowbits ~ a.lowbits + 1) = 0 THEN
a.highbits ~ a.highbits + 1;
RETURN[a]
END;
DCompare: PROCEDURE [a,b: LongCARDINAL] RETURNS [Comparison]
BEGIN
IF a = b THEN RETURN[equal];
RETURN[SELECT a.highbits FROM
< b.highbits =) less,
) b.highbits =) greater,
ENDCASE =)
IF a.10wbits < b.10wbits THEN less ELSE greater]
END;
AppendDouble: PROCEDURE [s: STRING, a: LongCARDINAL]
BEGIN OPEN StringDefs;
10ngZero: LongCARDINAL = [highbits:O, 10wbits:0];
10ng10: LongCARDINAL [highbits:O, 10wbits:10];
xn: PROCEDURE =
BEGIN
eharZero: CARDINAL LOOPHOLE['O];
r: LongCARDINAL;
IF a # longZero THEN
BEGIN
[a, r] ~ DDivide[a, 10ng10];
xn[];
AppendChar[s, lOOPHOLE[r.1owbits+eharZero, CHARACTER]];
END;
END;
IF a = 10ngZero THEN AppendChar[s, '0] ELSE xn[];
RETURN
END; --AppendDouble
END ...