DIRECTORY Rope, Basics, IO, BigCardinals, AlgebraClasses, Points; BigRats: CEDAR DEFINITIONS = BEGIN OPEN BC: BigCardinals, AC: AlgebraClasses, PTS: Points; CARD: TYPE = LONG CARDINAL; ROPE: TYPE = Rope.ROPE; BigCard: TYPE = BC.BigCARD; BigRat: TYPE = AC.Object; BigRatData: TYPE = REF BigRatDataRec; BigRatDataRec: TYPE = RECORD [ sign: Basics.Comparison _ equal, num: BigCard _ BigCardinals.Zero, den: BigCard _ BigCardinals.Zero ]; BigRats: AC.Structure; FromPairBC: PROC [num, den: BigCard, less: BOOL _ FALSE] RETURNS [BigRat]; FromPairLC: PROC [num, den: CARD, less: BOOL _ FALSE] RETURNS [BigRat]; FromBC: PROC [bc: BigCard, less: BOOL _ FALSE] RETURNS [BigRat]; FromLC: PROC [lc: CARD, less: BOOL _ FALSE] RETURNS [BigRat]; Read: AC.ReadOp; FromRope: AC.FromRopeOp; ToRope: AC.ToRopeOp; ToRopeApprox: PROC [rat: BigRat, places: NAT _ 3] RETURNS [ROPE]; Write: AC.WriteOp; WriteApprox: PROC [stream: IO.STREAM, in: BigRat]; FromReal: PROC [real: REAL] RETURNS [BigRat]; ToReal: PROC [rat: BigRat] RETURNS [REAL]; Truncate: PROC [rat: BigRat] RETURNS [fix: BigCard, rem: BigRat]; Add: AC.BinaryOp; Negate: AC.UnaryOp; Subtract: AC.BinaryOp; Multiply: AC.BinaryOp; Invert: AC.UnaryOp; Divide: AC.BinaryOp; Sign: AC.CompareToZeroOp; Abs: AC.UnaryOp; Compare: AC.BinaryCompareOp; Equal: AC.EqualityOp; Integer: PROC [in: BigRat] RETURNS [BOOLEAN]; ToTheX: PROC [rat: BigRat, x: INT] RETURNS [BigRat]; TwoToTheX: PROC [x: INT, less: BOOL _ FALSE] RETURNS [BigRat]; BCToTheX: PROC [bc: BigCard, x: INT, less: BOOL _ FALSE] RETURNS [BigRat]; END. @BigRats.mesa Last Edited by: Arnon, May 10, 1986 10:52:09 am PDT Types and Variables Creation Returns the rational number that corresponds to num/den (less => -num/den). Raises RuntimeError.ZeroDivisor when den = 0. Returns the rational number that corresponds to num/den (less => -num/den). Raises RuntimeError.ZeroDivisor when den = 0. Returns the rational number that corresponds to big (less => -bc). Returns the rational number that corresponds to big (less => -lc). I/O and Conversion Parses a decimal representation for a rational number. Letting N denote the decimal representation of a non-less integer, and S denote the decimal representation of a (possibly less) integer, Parse accepts the following syntax: rope = S -- where N is the decimal representation of a non-less integer rope = S "." N rope = S "/" N Returns a rope in the form S (if rat is an integer), or S/N (if rat is not an integer). Note that Equal[Parse[Unparse[rat]], rat] = TRUE. Returns a rope giving a decimal approximation to the rat. If the rat is a whole number, then the exact representation is given. If the rat is not a whole number then 'places' gives the number of places after the decimal point. Scaling is the user's responsibility. Returns the rational number corresponding to the given REAL number. (will raise Real.RealException if real is not a number) Returns the REAL number closest to the given rational number. (will raise Real.RealException if rat is outside the range covered by REAL) Returns fix: the largest non-less integer not greater than ABS[rat], rem: the remainder after subtracting fix from rat. rat.num > rat.den => fix = rat.num / rat.den, rem = FromPair[rat.num MOD rat.den, rat.den] rat.num = rat.den => fix = 1, rem = 0 rat.num = rat.den => fix = 1, rem = 0 Arithmetic Comparison Compares two rationals for equality only (faster than Compare). Test if a BigRat is an integer Extras Returns rat**x. Returns the rational number corresponding to 2**x. Much faster than ToTheX. Returns the rational number corresponding to bc**x (less => - bc**x). Note that BCToTheX[0, 0] = 1. Κw˜Jšœ ™ J™3J˜šΟk ˜ Jšœ˜J˜Jšœ˜J˜ Jšœ˜Jšœ˜—J˜Ihead2šœ œ ˜Jš œœœœœœ ˜@J˜headšΟn™Icodešœœœœ˜šœœœ˜M˜—šœ œœ ˜M˜—Mšœœœ˜M˜Mšœ œœ˜%šœœœ˜Mšœ ˜ Mšœ!˜!Mšœ ˜ Mšœ˜M˜—Jšœ œ ˜—šœ™š ž œœœœœ ˜JMšœz™zM˜—š ž œœ œœœœ ˜GMšœz™zM˜—š žœœœœœ ˜@MšœB™BM˜—š žœœœœœœ ˜=MšœB™B——šœ™šžœœ˜J˜—šžœœ ˜šœδ™δMšœG™GMšœ™Mšœ™—J˜—šžœœ ˜Mšœ…œ™ŠJ˜—š ž œœœœœ˜AMšœ‹™‹J˜—šžœœ ˜J˜—šž œœ œœ˜3J˜—šžœœœœ ˜-šœ7œ™CMšœ7™7—J˜—šžœœœœ˜*šœ œ-™=MšœFœ™K—J™—šžœœœ˜Ašœw™wMšœEœ™ZM™%M™%——J™—šž ™ šžœœ ˜J˜—šžœœ ˜J˜—šžœœ ˜J˜—Jšžœœ ˜J˜šžœœ ˜J˜—šžœœ ˜J˜——šœ ™ šžœœ˜J™—šžœœ ˜J˜—šžœœ˜J˜—šžœœ ˜Mšœ?™?—J˜šžœœœœ˜-Jšœ™——™šžœœœœ ˜4Mšœ™M˜—š ž œœœœœœ ˜>MšœL™LM˜—š žœœœœœœ ˜JMšœd™d—L™™J™——J™J˜Jšœ˜—…—,γ