Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Numbers/multprec_natural_numbers.ads, Revision 1.1
1.1 ! maekawa 1: package Multprec_Natural_Numbers is
! 2:
! 3: -- DESCRIPTION :
! 4: -- This package allows to manipulate natural numbers of arbitrary length.
! 5:
! 6: -- DATA STRUCTURES :
! 7:
! 8: type Array_of_Naturals is array ( natural range <> ) of natural;
! 9: type Natural_Number is private;
! 10:
! 11: -- CREATORS :
! 12:
! 13: function Create ( n : natural ) return Array_of_Naturals;
! 14:
! 15: -- DESCRIPTION :
! 16: -- Returns the representation of the natural number as coefficient vector.
! 17:
! 18: function Create ( n : natural ) return Natural_Number;
! 19:
! 20: -- DESCRIPTION :
! 21: -- Returns the representation of n as a natural number.
! 22:
! 23: function Create ( n : Array_of_Naturals ) return Natural_Number;
! 24:
! 25: -- DESCRIPTION :
! 26: -- Creates a number from the coefficients in n.
! 27:
! 28: -- REQUIRED : n'range = 0..n'last and n(i) < Base, for i in n'range.
! 29:
! 30: function Create ( n : Natural_Number ) return natural;
! 31:
! 32: -- DESCRIPTION :
! 33: -- Returns the representation of n as a standard natural.
! 34:
! 35: -- REQUIRED : n < Base.
! 36:
! 37: -- SELECTORS :
! 38:
! 39: function Base return natural;
! 40:
! 41: -- DESCRIPTION :
! 42: -- Returns the base of the number representation.
! 43:
! 44: function Exponent return natural;
! 45:
! 46: -- DESCRIPTION :
! 47: -- Returns the exponent: the number of decimal places in the base.
! 48:
! 49: function Empty ( n : Natural_Number ) return boolean;
! 50:
! 51: -- DESCRIPTION :
! 52: -- Returns true if the number has not been created yet, or when it has
! 53: -- been destroyed by the operation Clear; otherwise false is returned.
! 54: -- An empty number is considered as zero.
! 55:
! 56: function Size ( n : Natural_Number ) return natural;
! 57:
! 58: -- DESCRIPTION :
! 59: -- Returns the index of the last entry in the coefficient representation.
! 60:
! 61: function Decimal_Places ( n : natural ) return natural;
! 62:
! 63: -- DESCRIPTION :
! 64: -- Returns the number of decimal places n occupies, Decimal_Places(0) = 0.
! 65:
! 66: function Decimal_Places ( n : Natural_Number ) return natural;
! 67:
! 68: -- DESCRIPTION :
! 69: -- Returns the number of decimal places n occupies, Decimal_Places(0) = 0.
! 70: -- Since n can be arbitrarily large, also the number of return should
! 71: -- have no constraints on its size. However, the current implementation
! 72: -- would not support the manipulation of numbers whose size causes this
! 73: -- function to crash.
! 74:
! 75: function Coefficient ( n : Natural_Number; i : natural ) return natural;
! 76:
! 77: -- DESCRIPTION :
! 78: -- Returns the ith entry in the coefficient representation.
! 79:
! 80: function Coefficients ( n : Natural_Number ) return Array_of_Naturals;
! 81:
! 82: -- DESCRIPTION :
! 83: -- Returns the coefficient representation of n, of range 0..Size(n).
! 84: -- The number n equals then the sum of Coefficient(n,i)*Base**i,
! 85: -- for i in 0..Size(n).
! 86:
! 87: -- COMPARISON AND COPYING :
! 88:
! 89: function Equal ( n1 : Natural_Number; n2 : natural ) return boolean;
! 90: function Equal ( n1,n2 : Natural_Number ) return boolean;
! 91:
! 92: -- DESCRIPTION :
! 93: -- Returns true when both numbers n1 and n2 are equal, false otherwise.
! 94:
! 95: function "<" ( n1 : Natural_Number; n2 : natural ) return boolean;
! 96: function "<" ( n1 : natural; n2 : Natural_Number ) return boolean;
! 97: function "<" ( n1,n2 : Natural_Number ) return boolean;
! 98:
! 99: -- DESCRIPTION :
! 100: -- Returns true if n1 < n2, false otherwise.
! 101:
! 102: function ">" ( n1 : Natural_Number; n2 : natural ) return boolean;
! 103: function ">" ( n1 : natural; n2 : Natural_Number ) return boolean;
! 104: function ">" ( n1,n2 : Natural_Number ) return boolean;
! 105:
! 106: -- DESCRIPTION :
! 107: -- Returns true if n1 > n2, false otherwise.
! 108:
! 109: procedure Copy ( n1 : in natural; n2 : in out Natural_Number );
! 110: procedure Copy ( n1 : in Natural_Number; n2 : in out Natural_Number );
! 111:
! 112: -- DESCRIPTION :
! 113: -- Clears n2 and makes a copy of n1 to be equal to n2.
! 114: -- Note that n2 := n1 leads to data sharing.
! 115:
! 116: -- ARITHMETIC OPERATIONS as functions (no data sharing) :
! 117: -- Note that n1 >= n2 is required for subtraction, and n2 /= 0 for division.
! 118: -- The unary "-" operations have been added to make it ring-like.
! 119:
! 120: function "+" ( n1 : Natural_Number; n2 : natural ) return Natural_Number;
! 121: function "+" ( n1 : natural; n2 : Natural_Number ) return Natural_Number;
! 122: function "+" ( n1,n2 : Natural_Number ) return Natural_Number;
! 123:
! 124: function "-" ( n1 : Natural_Number; n2 : natural ) return Natural_Number;
! 125: function "-" ( n1 : natural; n2 : Natural_Number ) return Natural_Number;
! 126: function "-" ( n1,n2 : Natural_Number ) return Natural_Number;
! 127:
! 128: function "+" ( n : Natural_Number ) return Natural_Number; -- copies n
! 129: function "-" ( n : Natural_Number ) return Natural_Number; -- copies n
! 130:
! 131: function "*" ( n1 : Natural_Number; n2 : natural ) return Natural_Number;
! 132: function "*" ( n1 : natural; n2 : Natural_Number ) return Natural_Number;
! 133: function "*" ( n1,n2 : Natural_Number ) return Natural_Number;
! 134:
! 135: function "**" ( n1 : Natural_Number; n2 : natural ) return Natural_Number;
! 136: function "**" ( n1 : natural; n2 : Natural_Number ) return Natural_Number;
! 137: function "**" ( n1,n2 : Natural_Number ) return Natural_Number;
! 138:
! 139: function "/" ( n1 : Natural_Number; n2 : natural ) return Natural_Number;
! 140: function "/" ( n1 : natural; n2 : Natural_Number ) return natural;
! 141: function "/" ( n1,n2 : Natural_Number ) return Natural_Number;
! 142:
! 143: function Rmd ( n1 : Natural_Number; n2 : natural ) return natural;
! 144: function Rmd ( n1 : natural; n2 : Natural_Number ) return natural;
! 145: function Rmd ( n1,n2 : Natural_Number ) return Natural_Number;
! 146:
! 147: -- ARITHMETIC OPERATIONS as procedures for memory management :
! 148:
! 149: procedure Add ( n1 : in out Natural_Number; n2 : in natural ); -- "+"
! 150: procedure Add ( n1 : in out Natural_Number; n2 : in Natural_Number );
! 151:
! 152: procedure Sub ( n1 : in out Natural_Number; n2 : in natural ); -- "-"
! 153: procedure Sub ( n1 : in out Natural_Number; n2 : in Natural_Number );
! 154: procedure Min ( n : in out Natural_Number );
! 155:
! 156: procedure Mul ( n1 : in out Natural_Number; n2 : in natural ); -- "*"
! 157: procedure Mul ( n1 : in out Natural_Number; n2 : in Natural_Number );
! 158:
! 159: procedure Div ( n1 : in out Natural_Number; n2 : in natural ); -- "/"
! 160: procedure Div ( n1 : in out Natural_Number; n2 : in Natural_Number );
! 161:
! 162: procedure Div ( n1 : in Natural_Number; n2 : in natural; -- n1 = n2*q+r
! 163: q : out Natural_Number; r : out natural );
! 164: procedure Div ( n1 : in out Natural_Number; n2 : in natural;
! 165: r : out natural );
! 166: procedure Div ( n1,n2 : in Natural_Number; q,r : out Natural_Number );
! 167: procedure Div ( n1 : in out Natural_Number; n2 : in Natural_Number;
! 168: r : out Natural_Number );
! 169:
! 170: -- DESTRUCTOR :
! 171:
! 172: procedure Clear ( n : in out Natural_Number );
! 173:
! 174: -- DESCRIPTION :
! 175: -- Deallocation of the memory space. Empty(n) is true on return.
! 176:
! 177: private
! 178:
! 179: type Natural_Number_Rep;
! 180: type Natural_Number is access Natural_Number_Rep;
! 181:
! 182: end Multprec_Natural_Numbers;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>