DIRECTORY Rope USING [ROPE], IO USING [STREAM, PutRope], BigCardinals; RatNums: CEDAR DEFINITIONS IMPORTS IO = BEGIN OPEN BC: BigCardinals; Sign: TYPE = { NEGATIVE, ZERO, POSITIVE }; RatNum: TYPE = RECORD [sign: Sign, numerator, denominator: BC.BigCARD ]; RatNumAdd: PROC [in1, in2: RatNum] RETURNS [out: RatNum]; RatNumNegate: PROC [in: RatNum] RETURNS [out: RatNum]; RatNumABS: PROC [in: RatNum] RETURNS [out: RatNum]; RatNumSubtract: PROC [in1, in2: RatNum] RETURNS [RatNum]; RatNumMultiply: PROC [in1, in2: RatNum] RETURNS [out: RatNum]; RatNumInverse: PROC [in: RatNum] RETURNS [out: RatNum]; RatNumDivide: PROC [dividend, divisor: RatNum] RETURNS [RatNum]; RatNumFromBigCards: PROC [sign: INTEGER[-1..1], num, den: BC.BigCARD] RETURNS [out: RatNum]; RatNumFromSmallCards: PROC [sign: INTEGER[-1..1], num, den: CARDINAL] RETURNS [out: RatNum]; MakeRatNumZero: PROC RETURNS [out: RatNum]; RatNumFromREALRope: PROC [in: Rope.ROPE] RETURNS [RatNum]; RatNumToRatRope: PROC [in: RatNum, reuse: BOOLEAN _ FALSE, showDenomOne: BOOL _ FALSE] RETURNS [Rope.ROPE]; RatNumFromREAL: PROC [in: REAL] RETURNS [RatNum]; RatNumToREAL: PROC [in: RatNum, reuse: BOOLEAN _ FALSE] RETURNS [REAL]; ReadRatNum: PROC [in: IO.STREAM] RETURNS [out: RatNum, ok: BOOL _ TRUE]; WriteRatNum: PROC [stream: IO.STREAM, in: RatNum] = INLINE { IO.PutRope[ stream, RatNumToRatRope[in] ] }; RatNumRelation: TYPE = {ratLess, ratEqual, ratGreater}; RatNumCompare: PROC [in1, in2: RatNum] RETURNS [RatNumRelation]; RatNumRelationToRope: PROC [inRelation: RatNumRelation] RETURNS[Rope.ROPE]; RatNumGreater: PROC [in1, in2: RatNum] RETURNS [BOOLEAN]; RatNumEqual: PROC [in1, in2: RatNum] RETURNS [BOOLEAN]; RatNumLess: PROC [in1, in2: RatNum] RETURNS [BOOLEAN]; RatNumPositive: PROC [in: RatNum] RETURNS [BOOLEAN]; RatNumZero: PROC [in: RatNum] RETURNS [BOOLEAN]; RatNumNegative: PROC [in: RatNum] RETURNS [BOOLEAN]; RatNumInteger: PROC [in: RatNum] RETURNS [BOOLEAN]; BigPowerOfTen: PROC [exponent: CARDINAL] RETURNS [power: BC.BigCARD]; BigToREAL: PROC [in: BC.BigCARD, reuse: BOOLEAN _ FALSE] RETURNS [out: REAL]; BigOne: PROC [in: BC.BigCARD] RETURNS [BOOLEAN]; END. ÌRatNums.mesa Last Edited by: Arnon, June 10, 1985 4:19:22 pm PDT ***** Data Structure ***** RatNum's equal to zero are expected to have sign ZER0 and zero numerator; their denominators are undefined. ***** Basic Arithmetic ***** Inverse of a non-zero RatNum. ***** Constructor Routines ***** Construct RatNum representation for zero ***** Conversion and I/O Routines ***** Intended to allow decimal notation input of RatNums. Used for displaying the values of RatNums. If in is positive, then the output Rope is unsigned. The default of reuse: FALSE preserves the input RatNum. If in is an integer, then if showDenomOne = FALSE the denominator of one is not printed, if TRUE then it is. Convert a REAL to a RatNum. The REAL is viewed as a decimal fraction, whose numerator and denominator become the numerator and denominator of the resulting RatNum. Convert a RatNum to a real. For the time being, it is assumed that the RatNum is not so large in absolute value as to cause floating point overflow. ***** Comparison ***** Test if a RatNum is zero Test if a RatNum is zero Test if a RatNum is zero Test if a RatNum is an integer ***** Miscellaneous BigCardinal routines ***** Test if a BigCARD is the integer one. �Ê9˜Jšœ ™ J™3J˜šÏk ˜ Jšœ�œ�œ˜Jš�œ�œ�œ ˜J˜ —J˜šœ �œ� ˜Jš�œ�œ˜ —Jš�œ�œ�œ˜J˜JšÏc™J˜Jš œ�œ�œ�œ�œ˜*J˜šœ�œ�œ%�œ ˜HJšœk™k—J˜J˜J™J˜JšÏn œ�œ�œ˜9J˜JšŸ œ�œ�œ˜6J˜JšŸ œ�œ�œ˜3J˜JšŸœ�œ�œ ˜9J˜JšŸœ�œ�œ˜>J˜šŸ œ�œ�œ˜7Jšœ™—J˜JšŸ œ�œ�œ ˜@J˜J˜J™ J˜Jš Ÿœ�œ�œ�œ �œ˜\J˜Jš Ÿœ�œ�œ�œ�œ˜\J˜šŸœ�œ�œ˜+Jšœ(™(J™J™—J™'J™šŸœ�œ �œ�œ ˜:J™4—J™šŸœ�œ�œ�œ�œ�œ�œ�œ˜kJšœ.ŸœkŸœg™„—J˜šŸœ�œ�œ�œ ˜1Jšœ£™£—J˜š Ÿ œ�œ�œ�œ�œ�œ˜GJšœ•™•—J˜JšŸ œ�œ�œ�œ�œ�œ�œ˜HJ˜š Ÿ œ�œ �œ�œ�œ˜