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˜š Ÿ œœ œœœ˜