with PRECISE_TYPES ; use PRECISE_TYPES ; package RATIONAL_TYPES is -- This package defines the type RATIONAL for automatically sized fractions. -- Rational numbers can be much more accurate than even the longest -- floating point numbers. The RATIONAL objects are maintained in reduced form -- There is no limit on the size of integers except when memory runs out. -- -- The operations + - * / ** abs +(unary) -(unary) are defined -- -- Comparison operators > >= < <= are defined -- = and /= are predefined -- -- The constants RATIONAL_ZERO and RATIONAL_ONE are defined -- -- The function FRACTION is defined to create a RATIONAL object from a pair -- of integers over the available range of integer. -- -- The functions INTEGER_TO_RATIONAL and RATIONAL_TO_INTEGER are defined for -- the available range of single and pairs of INTEGER. -- -- The functions STRING_TO_RATIONAL and RATIONAL_TO_STRING are defined for -- a pair of strings of decimal digits. -- -- The functions FLOAT_TO_RATIONAL and RATIONAL_TO_FLOAT are approximate -- conversions for the available range of FLOAT. -- -- The function REDUCE is defined to minimize the size of numerator and -- denominator and thus the space needed by a RATIONAL object -- -- The function GCD computes the Greatest Common Divisor of two PRECISE numbers -- -- The function LCM computes the Least Common Multiple of two PRECISE numbers -- -- This package is used by RATIONAL_ARRAYS... that provides the -- so called "infinite precision" matrix arithmetic. -- -- Written 3/16/87 by Jon Squire -- Copyright 1987 Westinghouse Electric Corporation -- -- type RATIONAL is record P : PRECISE ; Q : PRECISE ; end record ; RATIONAL_ZERO : constant RATIONAL := ( PRECISE_ZERO , PRECISE_ONE ) ; RATIONAL_ONE : constant RATIONAL := ( PRECISE_ONE , PRECISE_ONE ) ; function "+" ( LEFT , RIGHT : RATIONAL ) return RATIONAL ; function "-" ( LEFT , RIGHT : RATIONAL ) return RATIONAL ; function "*" ( LEFT , RIGHT : RATIONAL ) return RATIONAL ; function "/" ( LEFT , RIGHT : RATIONAL ) return RATIONAL ; function "**" ( LEFT : RATIONAL ; RIGHT : INTEGER ) return RATIONAL ; function "+" ( RIGHT : RATIONAL ) return RATIONAL ; function "-" ( RIGHT : RATIONAL ) return RATIONAL ; function "abs" ( RIGHT : RATIONAL ) return RATIONAL ; function ">" ( LEFT , RIGHT : RATIONAL ) return BOOLEAN ; function ">=" ( LEFT , RIGHT : RATIONAL ) return BOOLEAN ; function "<" ( LEFT , RIGHT : RATIONAL ) return BOOLEAN ; function "<=" ( LEFT , RIGHT : RATIONAL ) return BOOLEAN ; function RATIONAL_TO_INTEGER ( ITEM : RATIONAL ) return INTEGER ; function INTEGER_TO_RATIONAL ( ITEM : INTEGER ) return RATIONAL ; procedure RATIONAL_TO_STRING ( ITEM : in RATIONAL; RESULT : out STRING; LAST : out NATURAL ); function STRING_TO_RATIONAL ( ITEM : STRING ) return RATIONAL ; function RATIONAL_TO_FLOAT ( ITEM : RATIONAL ) return FLOAT ; function FLOAT_TO_RATIONAL ( ITEM : FLOAT ) return RATIONAL ; function FRACTION ( LEFT , RIGHT : INTEGER ) return RATIONAL ; function GCD ( LEFT , RIGHT : PRECISE ) return PRECISE ; function LCM ( LEFT , RIGHT : PRECISE ) return PRECISE ; function REDUCE ( RIGHT : RATIONAL ) return RATIONAL ; end RATIONAL_TYPES ;