package PRECISE_TYPES is -- This package defines the type PRECISE for automatically sized integers. -- There is no limit on the size of integer except when memory runs out. -- -- The operations + - * / ** abs rem mod +(unary) -(unary) are defined -- -- Comparison operators > >= < <= are defined -- = and /= must use EQUAL -- -- The constants PRECISE_ZERO and PRECISE_ONE are defined -- -- The functions INTEGER_TO_PRECISE and PRECISE_TO_INTEGER are defined for -- the available range of INTEGER. -- -- The functions STRING_TO_PRECISE and PRECISE_TO_STRING are defined for -- a string of decimal digits with an optional plus or minus sign. -- -- The functions FLOAT_TO_PRECISE and PRECISE_TO_FLOAT are approximate -- conversions for the available range of FLOAT. -- -- The function TRIM is defined to minimize the space needed by a PRECISE -- object -- -- The function SIGN is defined to return +1 for positive, 0 for 0, and -- -1 for negative PRECISE values -- -- This package is used by RATIONAL_TYPES that provides the -- so called "infinite precision" arithmetic. -- -- Written 3/16/87 by Jon Squire -- Copyright 1987 Westinghouse Electric Corporation -- type PRECISE is private; -- PRECISE_ZERO : constant PRECISE; PRECISE_ONE : constant PRECISE; function "+" ( LEFT , RIGHT : PRECISE ) return PRECISE ; function "-" ( LEFT , RIGHT : PRECISE ) return PRECISE ; function "*" ( LEFT , RIGHT : PRECISE ) return PRECISE ; function "/" ( LEFT , RIGHT : PRECISE ) return PRECISE ; function "mod" ( LEFT , RIGHT : PRECISE ) return PRECISE ; function "rem" ( LEFT , RIGHT : PRECISE ) return PRECISE ; function "**" ( LEFT : PRECISE ; RIGHT : INTEGER ) return PRECISE ; function "+" ( RIGHT : PRECISE ) return PRECISE ; function "-" ( RIGHT : PRECISE ) return PRECISE ; function "abs" ( RIGHT : PRECISE ) return PRECISE ; function EQUAL ( LEFT , RIGHT : PRECISE ) return BOOLEAN ; function ">" ( LEFT , RIGHT : PRECISE ) return BOOLEAN ; function ">=" ( LEFT , RIGHT : PRECISE ) return BOOLEAN ; function "<" ( LEFT , RIGHT : PRECISE ) return BOOLEAN ; function "<=" ( LEFT , RIGHT : PRECISE ) return BOOLEAN ; function PRECISE_TO_INTEGER ( ITEM : PRECISE ) return INTEGER ; function INTEGER_TO_PRECISE ( ITEM : INTEGER ) return PRECISE ; procedure PRECISE_TO_STRING ( ITEM : in PRECISE; RESULT : out STRING; LAST : out NATURAL); function STRING_TO_PRECISE ( ITEM : STRING ) return PRECISE ; function PRECISE_TO_FLOAT ( ITEM : PRECISE ) return FLOAT ; function FLOAT_TO_PRECISE ( ITEM : FLOAT ) return PRECISE ; function TRIM ( RIGHT : PRECISE ) return PRECISE ; function GREATER_MAGNITUDE ( LEFT , RIGHT : PRECISE ) return BOOLEAN ; function SIGN ( ITEM : PRECISE ) return INTEGER; private type MY_INTEGER is range - 2 ** 30 .. 2 ** 30 ; type PRECISE_ARRAY is array ( INTEGER range <> ) of MY_INTEGER ; type PRECISE_SIGN is ( PLUS , MINUS ) ; type PRECISE_RECORD ( TERMS : INTEGER ) is record SIGN : PRECISE_SIGN := PLUS ; TERM : PRECISE_ARRAY ( 0 .. TERMS ) := ( 0 .. TERMS => MY_INTEGER( 0 )) ; end record ; type PRECISE is access PRECISE_RECORD ; PRECISE_BASE : constant := 10000 ; PRECISE_ZERO : constant PRECISE := new PRECISE_RECORD' (TERMS => 0 , SIGN => PLUS , TERM =>( 0 .. 0 => MY_INTEGER( 0 ))) ; PRECISE_ONE : constant PRECISE := new PRECISE_RECORD' (TERMS => 0 , SIGN => PLUS , TERM =>( 0 .. 0 => MY_INTEGER( 1 ))) ; end PRECISE_TYPES ;