-- Local Subprograms --
-----------------------
- function Direct (U : Uint) return Boolean;
+ function Direct (U : Valid_Uint) return Boolean;
pragma Inline (Direct);
-- Returns True if U is represented directly
- function Direct_Val (U : Uint) return Int;
- -- U is a Uint for is represented directly. The returned result is the
+ function Direct_Val (U : Valid_Uint) return Int;
+ -- U is a Uint that is represented directly. The returned result is the
-- value represented.
function GCD (Jin, Kin : Int) return Int;
-- UI_Image, and false for UI_Write, and Format is copied from the Format
-- parameter to UI_Image or UI_Write.
- procedure Init_Operand (UI : Uint; Vec : out UI_Vector);
+ procedure Init_Operand (UI : Valid_Uint; Vec : out UI_Vector);
pragma Inline (Init_Operand);
-- This procedure puts the value of UI into the vector in canonical
-- multiple precision format. The parameter should be of the correct size
function Vector_To_Uint
(In_Vec : UI_Vector;
- Negative : Boolean) return Uint;
+ Negative : Boolean) return Valid_Uint;
-- Functions that calculate values in UI_Vectors, call this function to
-- create and return the Uint value. In_Vec contains the multiple precision
-- (Base) representation of a non-negative value. Leading zeroes are
-- processing of signs is something that is done by the caller before
-- calling Vector_To_Uint.
- function Least_Sig_Digit (Arg : Uint) return Int;
+ function Least_Sig_Digit (Arg : Valid_Uint) return Int;
pragma Inline (Least_Sig_Digit);
-- Returns the Least Significant Digit of Arg quickly. When the given Uint
-- is less than 2**15, the value returned is the input value, in this case
-- two.
procedure Most_Sig_2_Digits
- (Left : Uint;
- Right : Uint;
+ (Left : Valid_Uint;
+ Right : Valid_Uint;
Left_Hat : out Int;
Right_Hat : out Int);
-- Returns leading two significant digits from the given pair of Uint's.
-- K is as small as possible S.T. Right_Hat < Base * Base. It is required
-- that Left >= Right for the algorithm to work.
- function N_Digits (Input : Uint) return Int;
+ function N_Digits (Input : Valid_Uint) return Int;
pragma Inline (N_Digits);
-- Returns number of "digits" in a Uint
procedure UI_Div_Rem
- (Left, Right : Uint;
+ (Left, Right : Valid_Uint;
Quotient : out Uint;
Remainder : out Uint;
Discard_Quotient : Boolean := False;
Discard_Remainder : Boolean := False);
-- Compute Euclidean division of Left by Right. If Discard_Quotient is
- -- False then the quotient is returned in Quotient (otherwise Quotient is
- -- set to No_Uint). If Discard_Remainder is False, then the remainder is
- -- returned in Remainder (otherwise Remainder is set to No_Uint).
+ -- False then the quotient is returned in Quotient. If Discard_Remainder
+ -- is False, then the remainder is returned in Remainder.
--
- -- If Discard_Quotient is True, Quotient is set to No_Uint
- -- If Discard_Remainder is True, Remainder is set to No_Uint
+ -- If Discard_Quotient is True, Quotient is set to No_Uint.
+ -- If Discard_Remainder is True, Remainder is set to No_Uint.
+
+ function UI_Modular_Exponentiation
+ (B : Valid_Uint;
+ E : Valid_Uint;
+ Modulo : Valid_Uint) return Valid_Uint with Unreferenced;
+ -- Efficiently compute (B**E) rem Modulo
+
+ function UI_Modular_Inverse
+ (N : Valid_Uint; Modulo : Valid_Uint) return Valid_Uint with Unreferenced;
+ -- Compute the multiplicative inverse of N in modular arithmetics with the
+ -- given Modulo (uses Euclid's algorithm). Note: the call is considered
+ -- to be erroneous (and the behavior is undefined) if n is not invertible.
------------
-- Direct --
------------
- function Direct (U : Uint) return Boolean is
+ function Direct (U : Valid_Uint) return Boolean is
begin
return Int (U) <= Int (Uint_Direct_Last);
end Direct;
-- Direct_Val --
----------------
- function Direct_Val (U : Uint) return Int is
+ function Direct_Val (U : Valid_Uint) return Int is
begin
pragma Assert (Direct (U));
return Int (U) - Int (Uint_Direct_Bias);
Format : UI_Format)
is
Marks : constant Uintp.Save_Mark := Uintp.Mark;
- Base : Uint;
- Ainput : Uint;
+ Base : Valid_Uint;
+ Ainput : Valid_Uint;
Digs_Output : Natural := 0;
-- Counts digits output. In hex mode, but not in decimal mode, we
-- Output non-zero exponent. Note that we only use the exponent form in
-- the buffer case, so we know that To_Buffer is true.
- procedure Image_Uint (U : Uint);
+ procedure Image_Uint (U : Valid_Uint);
-- Internal procedure to output characters of non-negative Uint
-------------------
-------------------
function Better_In_Hex return Boolean is
- T16 : constant Uint := Uint_2**Int'(16);
- A : Uint;
+ T16 : constant Valid_Uint := Uint_2**Int'(16);
+ A : Valid_Uint;
begin
A := UI_Abs (Input);
-- Image_Uint --
----------------
- procedure Image_Uint (U : Uint) is
+ procedure Image_Uint (U : Valid_Uint) is
H : constant array (Int range 0 .. 15) of Character :=
"0123456789ABCDEF";
- Q, R : Uint;
+ Q, R : Valid_Uint;
begin
UI_Div_Rem (U, Base, Q, R);
-- Init_Operand --
-------------------
- procedure Init_Operand (UI : Uint; Vec : out UI_Vector) is
+ procedure Init_Operand (UI : Valid_Uint; Vec : out UI_Vector) is
Loc : Int;
pragma Assert (Vec'First = Int'(1));
-- Least_Sig_Digit --
---------------------
- function Least_Sig_Digit (Arg : Uint) return Int is
+ function Least_Sig_Digit (Arg : Valid_Uint) return Int is
V : Int;
begin
-----------------------
procedure Most_Sig_2_Digits
- (Left : Uint;
- Right : Uint;
+ (Left : Valid_Uint;
+ Right : Valid_Uint;
Left_Hat : out Int;
Right_Hat : out Int)
is
-- N_Digits --
---------------
- -- Note: N_Digits returns 1 for No_Uint
-
- function N_Digits (Input : Uint) return Int is
+ function N_Digits (Input : Valid_Uint) return Int is
begin
if Direct (Input) then
if Direct_Val (Input) >= Base then
-- Num_Bits --
--------------
- function Num_Bits (Input : Uint) return Nat is
+ function Num_Bits (Input : Valid_Uint) return Nat is
Bits : Nat;
Num : Nat;
procedure Release (M : Save_Mark) is
begin
- Uints.Set_Last (Uint'Max (M.Save_Uint, Uints_Min));
+ Uints.Set_Last (Valid_Uint'Max (M.Save_Uint, Uints_Min));
Udigits.Set_Last (Int'Max (M.Save_Udigit, Udigits_Min));
end Release;
-- Release_And_Save --
----------------------
- procedure Release_And_Save (M : Save_Mark; UI : in out Uint) is
+ procedure Release_And_Save (M : Save_Mark; UI : in out Valid_Uint) is
begin
if Direct (UI) then
Release (M);
end if;
end Release_And_Save;
- procedure Release_And_Save (M : Save_Mark; UI1, UI2 : in out Uint) is
+ procedure Release_And_Save (M : Save_Mark; UI1, UI2 : in out Valid_Uint) is
begin
if Direct (UI1) then
Release_And_Save (M, UI2);
-- UI_Abs --
-------------
- function UI_Abs (Right : Uint) return Uint is
+ function UI_Abs (Right : Valid_Uint) return Unat is
begin
if Right < Uint_0 then
return -Right;
-- UI_Add --
-------------
- function UI_Add (Left : Int; Right : Uint) return Uint is
+ function UI_Add (Left : Int; Right : Valid_Uint) return Valid_Uint is
begin
return UI_Add (UI_From_Int (Left), Right);
end UI_Add;
- function UI_Add (Left : Uint; Right : Int) return Uint is
+ function UI_Add (Left : Valid_Uint; Right : Int) return Valid_Uint is
begin
return UI_Add (Left, UI_From_Int (Right));
end UI_Add;
- function UI_Add (Left : Uint; Right : Uint) return Uint is
+ function UI_Add (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint is
begin
+ pragma Assert (Present (Left));
+ pragma Assert (Present (Right));
+ -- Assertions are here in case we're called from C++ code, which does
+ -- not check the predicates.
+
-- Simple cases of direct operands and addition of zero
if Direct (Left) then
-- UI_Decimal_Digits_Hi --
--------------------------
- function UI_Decimal_Digits_Hi (U : Uint) return Nat is
+ function UI_Decimal_Digits_Hi (U : Valid_Uint) return Nat is
begin
-- The maximum value of a "digit" is 32767, which is 5 decimal digits,
-- so an N_Digit number could take up to 5 times this number of digits.
-- UI_Decimal_Digits_Lo --
--------------------------
- function UI_Decimal_Digits_Lo (U : Uint) return Nat is
+ function UI_Decimal_Digits_Lo (U : Valid_Uint) return Nat is
begin
-- The maximum value of a "digit" is 32767, which is more than four
-- decimal digits, but not a full five digits. The easily computed
-- UI_Div --
------------
- function UI_Div (Left : Int; Right : Uint) return Uint is
+ function UI_Div (Left : Int; Right : Nonzero_Uint) return Valid_Uint is
begin
return UI_Div (UI_From_Int (Left), Right);
end UI_Div;
- function UI_Div (Left : Uint; Right : Int) return Uint is
+ function UI_Div
+ (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint
+ is
begin
return UI_Div (Left, UI_From_Int (Right));
end UI_Div;
- function UI_Div (Left, Right : Uint) return Uint is
- Quotient : Uint;
- Remainder : Uint;
- pragma Warnings (Off, Remainder);
+ function UI_Div
+ (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint
+ is
+ Quotient : Valid_Uint;
+ Ignored_Remainder : Uint;
begin
UI_Div_Rem
(Left, Right,
- Quotient, Remainder,
+ Quotient, Ignored_Remainder,
Discard_Remainder => True);
return Quotient;
end UI_Div;
----------------
procedure UI_Div_Rem
- (Left, Right : Uint;
+ (Left, Right : Valid_Uint;
Quotient : out Uint;
Remainder : out Uint;
Discard_Quotient : Boolean := False;
if not Discard_Remainder then
declare
Remainder_V : UI_Vector (1 .. R_Length);
- Discard_Int : Int;
- pragma Warnings (Off, Discard_Int);
+ Ignore : Int;
begin
pragma Assert (D /= Int'(0));
UI_Div_Vector
(Dividend (Dividend'Last - R_Length + 1 .. Dividend'Last),
D,
- Remainder_V, Discard_Int);
+ Remainder_V, Ignore);
Remainder := Vector_To_Uint (Remainder_V, L_Vec (1) < Int_0);
end;
end if;
-- UI_Eq --
------------
- function UI_Eq (Left : Int; Right : Uint) return Boolean is
+ function UI_Eq (Left : Int; Right : Valid_Uint) return Boolean is
begin
return not UI_Ne (UI_From_Int (Left), Right);
end UI_Eq;
- function UI_Eq (Left : Uint; Right : Int) return Boolean is
+ function UI_Eq (Left : Valid_Uint; Right : Int) return Boolean is
begin
return not UI_Ne (Left, UI_From_Int (Right));
end UI_Eq;
- function UI_Eq (Left : Uint; Right : Uint) return Boolean is
+ function UI_Eq (Left : Valid_Uint; Right : Valid_Uint) return Boolean is
begin
return not UI_Ne (Left, Right);
end UI_Eq;
-- UI_Expon --
--------------
- function UI_Expon (Left : Int; Right : Uint) return Uint is
+ function UI_Expon (Left : Int; Right : Unat) return Valid_Uint is
begin
return UI_Expon (UI_From_Int (Left), Right);
end UI_Expon;
- function UI_Expon (Left : Uint; Right : Int) return Uint is
+ function UI_Expon (Left : Valid_Uint; Right : Nat) return Valid_Uint is
begin
return UI_Expon (Left, UI_From_Int (Right));
end UI_Expon;
- function UI_Expon (Left : Int; Right : Int) return Uint is
+ function UI_Expon (Left : Int; Right : Nat) return Valid_Uint is
begin
return UI_Expon (UI_From_Int (Left), UI_From_Int (Right));
end UI_Expon;
- function UI_Expon (Left : Uint; Right : Uint) return Uint is
+ function UI_Expon
+ (Left : Valid_Uint; Right : Unat) return Valid_Uint
+ is
begin
pragma Assert (Right >= Uint_0);
-- If we fall through, then we have the general case (see Knuth 4.6.3)
declare
- N : Uint := Right;
- Squares : Uint := Left;
- Result : Uint := Uint_1;
+ N : Valid_Uint := Right;
+ Squares : Valid_Uint := Left;
+ Result : Valid_Uint := Uint_1;
M : constant Uintp.Save_Mark := Uintp.Mark;
begin
-- UI_From_CC --
----------------
- function UI_From_CC (Input : Char_Code) return Uint is
+ function UI_From_CC (Input : Char_Code) return Valid_Uint is
begin
return UI_From_Int (Int (Input));
end UI_From_CC;
-- UI_From_Int --
-----------------
- function UI_From_Int (Input : Int) return Uint is
+ function UI_From_Int (Input : Int) return Valid_Uint is
U : Uint;
begin
if Min_Direct <= Input and then Input <= Max_Direct then
- return Uint (Int (Uint_Direct_Bias) + Input);
+ return Valid_Uint (Int (Uint_Direct_Bias) + Input);
end if;
-- If already in the hash table, return entry
-- UI_From_Integral --
----------------------
- function UI_From_Integral (Input : In_T) return Uint is
+ function UI_From_Integral (Input : In_T) return Valid_Uint is
begin
-- If in range of our normal conversion function, use it so we can use
-- direct access and our cache.
-- Base is defined so that 3 Uint digits is sufficient to hold the
-- largest possible Int value.
- U : Uint;
+ U : Valid_Uint;
V : UI_Vector (1 .. Max_For_In_T);
begin
-- We use the same notation as Knuth (U_Hat standing for the obvious)
- function UI_GCD (Uin, Vin : Uint) return Uint is
- U, V : Uint;
+ function UI_GCD (Uin, Vin : Valid_Uint) return Valid_Uint is
+ U, V : Valid_Uint;
-- Copies of Uin and Vin
U_Hat, V_Hat : Int;
A, B, C, D, T, Q, Den1, Den2 : Int;
- Tmp_UI : Uint;
+ Tmp_UI : Valid_Uint;
Marks : constant Uintp.Save_Mark := Uintp.Mark;
Iterations : Integer := 0;
-- UI_Ge --
------------
- function UI_Ge (Left : Int; Right : Uint) return Boolean is
+ function UI_Ge (Left : Int; Right : Valid_Uint) return Boolean is
begin
return not UI_Lt (UI_From_Int (Left), Right);
end UI_Ge;
- function UI_Ge (Left : Uint; Right : Int) return Boolean is
+ function UI_Ge (Left : Valid_Uint; Right : Int) return Boolean is
begin
return not UI_Lt (Left, UI_From_Int (Right));
end UI_Ge;
- function UI_Ge (Left : Uint; Right : Uint) return Boolean is
+ function UI_Ge (Left : Valid_Uint; Right : Valid_Uint) return Boolean is
begin
return not UI_Lt (Left, Right);
end UI_Ge;
-- UI_Gt --
------------
- function UI_Gt (Left : Int; Right : Uint) return Boolean is
+ function UI_Gt (Left : Int; Right : Valid_Uint) return Boolean is
begin
return UI_Lt (Right, UI_From_Int (Left));
end UI_Gt;
- function UI_Gt (Left : Uint; Right : Int) return Boolean is
+ function UI_Gt (Left : Valid_Uint; Right : Int) return Boolean is
begin
return UI_Lt (UI_From_Int (Right), Left);
end UI_Gt;
- function UI_Gt (Left : Uint; Right : Uint) return Boolean is
+ function UI_Gt (Left : Valid_Uint; Right : Valid_Uint) return Boolean is
begin
return UI_Lt (Left => Right, Right => Left);
end UI_Gt;
pragma Assert (Uint_Int_First /= Uint_0);
+ if No (Input) then -- Preserve old behavior
+ return True;
+ end if;
+
if Direct (Input) then
return True;
else
- return Input >= Uint_Int_First
- and then Input <= Uint_Int_Last;
+ return Input >= Uint_Int_First and then Input <= Uint_Int_Last;
end if;
end UI_Is_In_Int_Range;
-- UI_Le --
------------
- function UI_Le (Left : Int; Right : Uint) return Boolean is
+ function UI_Le (Left : Int; Right : Valid_Uint) return Boolean is
begin
return not UI_Lt (Right, UI_From_Int (Left));
end UI_Le;
- function UI_Le (Left : Uint; Right : Int) return Boolean is
+ function UI_Le (Left : Valid_Uint; Right : Int) return Boolean is
begin
return not UI_Lt (UI_From_Int (Right), Left);
end UI_Le;
- function UI_Le (Left : Uint; Right : Uint) return Boolean is
+ function UI_Le (Left : Valid_Uint; Right : Valid_Uint) return Boolean is
begin
return not UI_Lt (Left => Right, Right => Left);
end UI_Le;
-- UI_Lt --
------------
- function UI_Lt (Left : Int; Right : Uint) return Boolean is
+ function UI_Lt (Left : Int; Right : Valid_Uint) return Boolean is
begin
return UI_Lt (UI_From_Int (Left), Right);
end UI_Lt;
- function UI_Lt (Left : Uint; Right : Int) return Boolean is
+ function UI_Lt (Left : Valid_Uint; Right : Int) return Boolean is
begin
return UI_Lt (Left, UI_From_Int (Right));
end UI_Lt;
- function UI_Lt (Left : Uint; Right : Uint) return Boolean is
+ function UI_Lt (Left : Valid_Uint; Right : Valid_Uint) return Boolean is
begin
+ pragma Assert (Present (Left));
+ pragma Assert (Present (Right));
+ -- Assertions are here in case we're called from C++ code, which does
+ -- not check the predicates.
+
-- Quick processing for identical arguments
if Int (Left) = Int (Right) then
-- UI_Max --
------------
- function UI_Max (Left : Int; Right : Uint) return Uint is
+ function UI_Max (Left : Int; Right : Valid_Uint) return Valid_Uint is
begin
return UI_Max (UI_From_Int (Left), Right);
end UI_Max;
- function UI_Max (Left : Uint; Right : Int) return Uint is
+ function UI_Max (Left : Valid_Uint; Right : Int) return Valid_Uint is
begin
return UI_Max (Left, UI_From_Int (Right));
end UI_Max;
- function UI_Max (Left : Uint; Right : Uint) return Uint is
+ function UI_Max (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint is
begin
if Left >= Right then
return Left;
-- UI_Min --
------------
- function UI_Min (Left : Int; Right : Uint) return Uint is
+ function UI_Min (Left : Int; Right : Valid_Uint) return Valid_Uint is
begin
return UI_Min (UI_From_Int (Left), Right);
end UI_Min;
- function UI_Min (Left : Uint; Right : Int) return Uint is
+ function UI_Min (Left : Valid_Uint; Right : Int) return Valid_Uint is
begin
return UI_Min (Left, UI_From_Int (Right));
end UI_Min;
- function UI_Min (Left : Uint; Right : Uint) return Uint is
+ function UI_Min (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint is
begin
if Left <= Right then
return Left;
-- UI_Mod --
-------------
- function UI_Mod (Left : Int; Right : Uint) return Uint is
+ function UI_Mod (Left : Int; Right : Nonzero_Uint) return Valid_Uint is
begin
return UI_Mod (UI_From_Int (Left), Right);
end UI_Mod;
- function UI_Mod (Left : Uint; Right : Int) return Uint is
+ function UI_Mod
+ (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint
+ is
begin
return UI_Mod (Left, UI_From_Int (Right));
end UI_Mod;
- function UI_Mod (Left : Uint; Right : Uint) return Uint is
- Urem : constant Uint := Left rem Right;
+ function UI_Mod
+ (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint
+ is
+ Urem : constant Valid_Uint := Left rem Right;
begin
if (Left < Uint_0) = (Right < Uint_0)
-------------------------------
function UI_Modular_Exponentiation
- (B : Uint;
- E : Uint;
- Modulo : Uint) return Uint
+ (B : Valid_Uint;
+ E : Valid_Uint;
+ Modulo : Valid_Uint) return Valid_Uint
is
M : constant Save_Mark := Mark;
- Result : Uint := Uint_1;
- Base : Uint := B;
- Exponent : Uint := E;
+ Result : Valid_Uint := Uint_1;
+ Base : Valid_Uint := B;
+ Exponent : Valid_Uint := E;
begin
while Exponent /= Uint_0 loop
-- UI_Modular_Inverse --
------------------------
- function UI_Modular_Inverse (N : Uint; Modulo : Uint) return Uint is
+ function UI_Modular_Inverse
+ (N : Valid_Uint; Modulo : Valid_Uint) return Valid_Uint
+ is
M : constant Save_Mark := Mark;
- U : Uint;
- V : Uint;
- Q : Uint;
- R : Uint;
- X : Uint;
- Y : Uint;
- T : Uint;
+ U : Valid_Uint;
+ V : Valid_Uint;
+ Q : Valid_Uint;
+ R : Valid_Uint;
+ X : Valid_Uint;
+ Y : Valid_Uint;
+ T : Valid_Uint;
S : Int := 1;
begin
-- UI_Mul --
------------
- function UI_Mul (Left : Int; Right : Uint) return Uint is
+ function UI_Mul (Left : Int; Right : Valid_Uint) return Valid_Uint is
begin
return UI_Mul (UI_From_Int (Left), Right);
end UI_Mul;
- function UI_Mul (Left : Uint; Right : Int) return Uint is
+ function UI_Mul (Left : Valid_Uint; Right : Int) return Valid_Uint is
begin
return UI_Mul (Left, UI_From_Int (Right));
end UI_Mul;
- function UI_Mul (Left : Uint; Right : Uint) return Uint is
+ function UI_Mul (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint is
begin
-- Case where product fits in the range of a 32-bit integer
-- UI_Ne --
------------
- function UI_Ne (Left : Int; Right : Uint) return Boolean is
+ function UI_Ne (Left : Int; Right : Valid_Uint) return Boolean is
begin
return UI_Ne (UI_From_Int (Left), Right);
end UI_Ne;
- function UI_Ne (Left : Uint; Right : Int) return Boolean is
+ function UI_Ne (Left : Valid_Uint; Right : Int) return Boolean is
begin
return UI_Ne (Left, UI_From_Int (Right));
end UI_Ne;
- function UI_Ne (Left : Uint; Right : Uint) return Boolean is
+ function UI_Ne (Left : Valid_Uint; Right : Valid_Uint) return Boolean is
begin
- -- Quick processing for identical arguments. Note that this takes
- -- care of the case of two No_Uint arguments.
+ pragma Assert (Present (Left));
+ pragma Assert (Present (Right));
+ -- Assertions are here in case we're called from C++ code, which does
+ -- not check the predicates.
+
+ -- Quick processing for identical arguments
if Int (Left) = Int (Right) then
return False;
-- UI_Negate --
----------------
- function UI_Negate (Right : Uint) return Uint is
+ function UI_Negate (Right : Valid_Uint) return Valid_Uint is
begin
-- Case where input is directly represented. Note that since the range
-- of Direct values is non-symmetrical, the result may not be directly
-- UI_Rem --
-------------
- function UI_Rem (Left : Int; Right : Uint) return Uint is
+ function UI_Rem (Left : Int; Right : Nonzero_Uint) return Valid_Uint is
begin
return UI_Rem (UI_From_Int (Left), Right);
end UI_Rem;
- function UI_Rem (Left : Uint; Right : Int) return Uint is
+ function UI_Rem
+ (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint
+ is
begin
return UI_Rem (Left, UI_From_Int (Right));
end UI_Rem;
- function UI_Rem (Left, Right : Uint) return Uint is
- Remainder : Uint;
- Quotient : Uint;
- pragma Warnings (Off, Quotient);
+ function UI_Rem
+ (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint
+ is
+ Remainder : Valid_Uint;
+ Ignored_Quotient : Uint;
begin
pragma Assert (Right /= Uint_0);
else
UI_Div_Rem
- (Left, Right, Quotient, Remainder, Discard_Quotient => True);
+ (Left, Right, Ignored_Quotient, Remainder,
+ Discard_Quotient => True);
return Remainder;
end if;
end UI_Rem;
-- UI_Sub --
------------
- function UI_Sub (Left : Int; Right : Uint) return Uint is
+ function UI_Sub (Left : Int; Right : Valid_Uint) return Valid_Uint is
begin
return UI_Add (Left, -Right);
end UI_Sub;
- function UI_Sub (Left : Uint; Right : Int) return Uint is
+ function UI_Sub (Left : Valid_Uint; Right : Int) return Valid_Uint is
begin
return UI_Add (Left, -Right);
end UI_Sub;
- function UI_Sub (Left : Uint; Right : Uint) return Uint is
+ function UI_Sub (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint is
begin
if Direct (Left) and then Direct (Right) then
return UI_From_Int (Direct_Val (Left) - Direct_Val (Right));
-- UI_To_CC --
--------------
- function UI_To_CC (Input : Uint) return Char_Code is
+ function UI_To_CC (Input : Valid_Uint) return Char_Code is
begin
if Direct (Input) then
return Char_Code (Direct_Val (Input));
function Vector_To_Uint
(In_Vec : UI_Vector;
- Negative : Boolean)
- return Uint
+ Negative : Boolean) return Valid_Uint
is
Size : Int;
Val : Int;
if Size = Int_1 then
if Negative then
- return Uint (Int (Uint_Direct_Bias) - In_Vec (J));
+ return Valid_Uint (Int (Uint_Direct_Bias) - In_Vec (J));
else
- return Uint (Int (Uint_Direct_Bias) + In_Vec (J));
+ return Valid_Uint (Int (Uint_Direct_Bias) + In_Vec (J));
end if;
-- Positive two digit values may be in direct representation range
Val := In_Vec (J) * Base + In_Vec (J + 1);
if Val <= Max_Direct then
- return Uint (Int (Uint_Direct_Bias) + Val);
+ return Valid_Uint (Int (Uint_Direct_Bias) + Val);
end if;
end if;
Uint_Minus_128 : constant Uint;
function No (X : Uint) return Boolean is (X = No_Uint);
+ -- Note that this is using the predefined "=", not the "=" declared below,
+ -- which would blow up on No_Uint.
+
function Present (X : Uint) return Boolean is (not No (X));
subtype Valid_Uint is Uint with Predicate => Present (Valid_Uint);
subtype Unat is Valid_Uint with Predicate => Unat >= Uint_0; -- natural
subtype Upos is Valid_Uint with Predicate => Upos >= Uint_1; -- positive
subtype Nonzero_Uint is Valid_Uint with Predicate => Nonzero_Uint /= Uint_0;
+ subtype Ubool is Valid_Uint with Predicate => Ubool in Uint_0 | Uint_1;
+ subtype Opt_Ubool is Uint with
+ Predicate => No (Opt_Ubool) or else Opt_Ubool in Ubool;
-----------------
-- Subprograms --
-- unit, these are among the few tables that can be expanded during
-- gigi processing.
- function UI_Abs (Right : Uint) return Uint;
+ function UI_Abs (Right : Valid_Uint) return Unat;
pragma Inline (UI_Abs);
-- Returns abs function of universal integer
- function UI_Add (Left : Uint; Right : Uint) return Uint;
- function UI_Add (Left : Int; Right : Uint) return Uint;
- function UI_Add (Left : Uint; Right : Int) return Uint;
+ function UI_Add (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint;
+ function UI_Add (Left : Int; Right : Valid_Uint) return Valid_Uint;
+ function UI_Add (Left : Valid_Uint; Right : Int) return Valid_Uint;
-- Returns sum of two integer values
- function UI_Decimal_Digits_Hi (U : Uint) return Nat;
+ function UI_Decimal_Digits_Hi (U : Valid_Uint) return Nat;
-- Returns an estimate of the number of decimal digits required to
-- represent the absolute value of U. This estimate is correct or high,
-- i.e. it never returns a value that is too low. The accuracy of the
-- estimate affects only the effectiveness of comparison optimizations
-- in Urealp.
- function UI_Decimal_Digits_Lo (U : Uint) return Nat;
+ function UI_Decimal_Digits_Lo (U : Valid_Uint) return Nat;
-- Returns an estimate of the number of decimal digits required to
-- represent the absolute value of U. This estimate is correct or low,
-- i.e. it never returns a value that is too high. The accuracy of the
-- estimate affects only the effectiveness of comparison optimizations
-- in Urealp.
- function UI_Div (Left : Uint; Right : Uint) return Uint;
- function UI_Div (Left : Int; Right : Uint) return Uint;
- function UI_Div (Left : Uint; Right : Int) return Uint;
+ function UI_Div (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint;
+ function UI_Div (Left : Int; Right : Nonzero_Uint) return Valid_Uint;
+ function UI_Div (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint;
-- Returns quotient of two integer values. Fatal error if Right = 0
- function UI_Eq (Left : Uint; Right : Uint) return Boolean;
- function UI_Eq (Left : Int; Right : Uint) return Boolean;
- function UI_Eq (Left : Uint; Right : Int) return Boolean;
+ function UI_Eq (Left : Valid_Uint; Right : Valid_Uint) return Boolean;
+ function UI_Eq (Left : Int; Right : Valid_Uint) return Boolean;
+ function UI_Eq (Left : Valid_Uint; Right : Int) return Boolean;
pragma Inline (UI_Eq);
-- Compares integer values for equality
- function UI_Expon (Left : Uint; Right : Uint) return Uint;
- function UI_Expon (Left : Int; Right : Uint) return Uint;
- function UI_Expon (Left : Uint; Right : Int) return Uint;
- function UI_Expon (Left : Int; Right : Int) return Uint;
+ function UI_Expon (Left : Valid_Uint; Right : Unat) return Valid_Uint;
+ function UI_Expon (Left : Int; Right : Unat) return Valid_Uint;
+ function UI_Expon (Left : Valid_Uint; Right : Nat) return Valid_Uint;
+ function UI_Expon (Left : Int; Right : Nat) return Valid_Uint;
-- Returns result of exponentiating two integer values.
-- Fatal error if Right is negative.
- function UI_GCD (Uin, Vin : Uint) return Uint;
+ function UI_GCD (Uin, Vin : Valid_Uint) return Valid_Uint;
-- Computes GCD of input values. Assumes Uin >= Vin >= 0
- function UI_Ge (Left : Uint; Right : Uint) return Boolean;
- function UI_Ge (Left : Int; Right : Uint) return Boolean;
- function UI_Ge (Left : Uint; Right : Int) return Boolean;
+ function UI_Ge (Left : Valid_Uint; Right : Valid_Uint) return Boolean;
+ function UI_Ge (Left : Int; Right : Valid_Uint) return Boolean;
+ function UI_Ge (Left : Valid_Uint; Right : Int) return Boolean;
pragma Inline (UI_Ge);
-- Compares integer values for greater than or equal
- function UI_Gt (Left : Uint; Right : Uint) return Boolean;
- function UI_Gt (Left : Int; Right : Uint) return Boolean;
- function UI_Gt (Left : Uint; Right : Int) return Boolean;
+ function UI_Gt (Left : Valid_Uint; Right : Valid_Uint) return Boolean;
+ function UI_Gt (Left : Int; Right : Valid_Uint) return Boolean;
+ function UI_Gt (Left : Valid_Uint; Right : Int) return Boolean;
pragma Inline (UI_Gt);
-- Compares integer values for greater than
function UI_Is_In_Int_Range (Input : Uint) return Boolean;
pragma Inline (UI_Is_In_Int_Range);
- -- Determines if universal integer is in Int range
+ -- Determines if universal integer is in Int range.
+ -- Input should probably be of type Valid_Uint.
- function UI_Le (Left : Uint; Right : Uint) return Boolean;
- function UI_Le (Left : Int; Right : Uint) return Boolean;
- function UI_Le (Left : Uint; Right : Int) return Boolean;
+ function UI_Le (Left : Valid_Uint; Right : Valid_Uint) return Boolean;
+ function UI_Le (Left : Int; Right : Valid_Uint) return Boolean;
+ function UI_Le (Left : Valid_Uint; Right : Int) return Boolean;
pragma Inline (UI_Le);
-- Compares integer values for less than or equal
- function UI_Lt (Left : Uint; Right : Uint) return Boolean;
- function UI_Lt (Left : Int; Right : Uint) return Boolean;
- function UI_Lt (Left : Uint; Right : Int) return Boolean;
+ function UI_Lt (Left : Valid_Uint; Right : Valid_Uint) return Boolean;
+ function UI_Lt (Left : Int; Right : Valid_Uint) return Boolean;
+ function UI_Lt (Left : Valid_Uint; Right : Int) return Boolean;
-- Compares integer values for less than
- function UI_Max (Left : Uint; Right : Uint) return Uint;
- function UI_Max (Left : Int; Right : Uint) return Uint;
- function UI_Max (Left : Uint; Right : Int) return Uint;
+ function UI_Max (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint;
+ function UI_Max (Left : Int; Right : Valid_Uint) return Valid_Uint;
+ function UI_Max (Left : Valid_Uint; Right : Int) return Valid_Uint;
-- Returns maximum of two integer values
- function UI_Min (Left : Uint; Right : Uint) return Uint;
- function UI_Min (Left : Int; Right : Uint) return Uint;
- function UI_Min (Left : Uint; Right : Int) return Uint;
+ function UI_Min (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint;
+ function UI_Min (Left : Int; Right : Valid_Uint) return Valid_Uint;
+ function UI_Min (Left : Valid_Uint; Right : Int) return Valid_Uint;
-- Returns minimum of two integer values
- function UI_Mod (Left : Uint; Right : Uint) return Uint;
- function UI_Mod (Left : Int; Right : Uint) return Uint;
- function UI_Mod (Left : Uint; Right : Int) return Uint;
+ function UI_Mod (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint;
+ function UI_Mod (Left : Int; Right : Nonzero_Uint) return Valid_Uint;
+ function UI_Mod (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint;
pragma Inline (UI_Mod);
-- Returns mod function of two integer values
- function UI_Mul (Left : Uint; Right : Uint) return Uint;
- function UI_Mul (Left : Int; Right : Uint) return Uint;
- function UI_Mul (Left : Uint; Right : Int) return Uint;
+ function UI_Mul (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint;
+ function UI_Mul (Left : Int; Right : Valid_Uint) return Valid_Uint;
+ function UI_Mul (Left : Valid_Uint; Right : Int) return Valid_Uint;
-- Returns product of two integer values
- function UI_Ne (Left : Uint; Right : Uint) return Boolean;
- function UI_Ne (Left : Int; Right : Uint) return Boolean;
- function UI_Ne (Left : Uint; Right : Int) return Boolean;
+ function UI_Ne (Left : Valid_Uint; Right : Valid_Uint) return Boolean;
+ function UI_Ne (Left : Int; Right : Valid_Uint) return Boolean;
+ function UI_Ne (Left : Valid_Uint; Right : Int) return Boolean;
pragma Inline (UI_Ne);
-- Compares integer values for inequality
- function UI_Negate (Right : Uint) return Uint;
+ function UI_Negate (Right : Valid_Uint) return Valid_Uint;
pragma Inline (UI_Negate);
-- Returns negative of universal integer
- function UI_Rem (Left : Uint; Right : Uint) return Uint;
- function UI_Rem (Left : Int; Right : Uint) return Uint;
- function UI_Rem (Left : Uint; Right : Int) return Uint;
+ function UI_Rem (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint;
+ function UI_Rem (Left : Int; Right : Nonzero_Uint) return Valid_Uint;
+ function UI_Rem (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint;
-- Returns rem of two integer values
- function UI_Sub (Left : Uint; Right : Uint) return Uint;
- function UI_Sub (Left : Int; Right : Uint) return Uint;
- function UI_Sub (Left : Uint; Right : Int) return Uint;
+ function UI_Sub (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint;
+ function UI_Sub (Left : Int; Right : Valid_Uint) return Valid_Uint;
+ function UI_Sub (Left : Valid_Uint; Right : Int) return Valid_Uint;
pragma Inline (UI_Sub);
-- Returns difference of two integer values
- function UI_Modular_Exponentiation
- (B : Uint;
- E : Uint;
- Modulo : Uint) return Uint;
- -- Efficiently compute (B**E) rem Modulo
-
- function UI_Modular_Inverse (N : Uint; Modulo : Uint) return Uint;
- -- Compute the multiplicative inverse of N in modular arithmetics with the
- -- given Modulo (uses Euclid's algorithm). Note: the call is considered
- -- to be erroneous (and the behavior is undefined) if n is not invertible.
-
- function UI_From_Int (Input : Int) return Uint;
+ function UI_From_Int (Input : Int) return Valid_Uint;
-- Converts Int value to universal integer form
generic
type In_T is range <>;
- function UI_From_Integral (Input : In_T) return Uint;
+ function UI_From_Integral (Input : In_T) return Valid_Uint;
-- Likewise, but converts from any integer type. Must not be applied to
-- biased types (instantiation will provide a warning if actual is a biased
-- type).
- function UI_From_CC (Input : Char_Code) return Uint;
+ function UI_From_CC (Input : Char_Code) return Valid_Uint;
-- Converts Char_Code value to universal integer form
function UI_To_Int (Input : Valid_Uint) return Int;
-- Converts universal integer value to Unsigned_64. Constraint_Error if
-- value is not in appropriate range.
- function UI_To_CC (Input : Uint) return Char_Code;
+ function UI_To_CC (Input : Valid_Uint) return Char_Code;
-- Converts universal integer value to Char_Code. Constraint_Error if value
-- is not in Char_Code range.
- function Num_Bits (Input : Uint) return Nat;
+ function Num_Bits (Input : Valid_Uint) return Nat;
-- Approximate number of binary bits in given universal integer. This
-- function is used for capacity checks, and it can be one bit off
-- without affecting its usage.
-- Operator Renamings --
------------------------
- function "+" (Left : Uint; Right : Uint) return Uint renames UI_Add;
- function "+" (Left : Int; Right : Uint) return Uint renames UI_Add;
- function "+" (Left : Uint; Right : Int) return Uint renames UI_Add;
-
- function "/" (Left : Uint; Right : Uint) return Uint renames UI_Div;
- function "/" (Left : Int; Right : Uint) return Uint renames UI_Div;
- function "/" (Left : Uint; Right : Int) return Uint renames UI_Div;
-
- function "*" (Left : Uint; Right : Uint) return Uint renames UI_Mul;
- function "*" (Left : Int; Right : Uint) return Uint renames UI_Mul;
- function "*" (Left : Uint; Right : Int) return Uint renames UI_Mul;
-
- function "-" (Left : Uint; Right : Uint) return Uint renames UI_Sub;
- function "-" (Left : Int; Right : Uint) return Uint renames UI_Sub;
- function "-" (Left : Uint; Right : Int) return Uint renames UI_Sub;
-
- function "**" (Left : Uint; Right : Uint) return Uint renames UI_Expon;
- function "**" (Left : Uint; Right : Int) return Uint renames UI_Expon;
- function "**" (Left : Int; Right : Uint) return Uint renames UI_Expon;
- function "**" (Left : Int; Right : Int) return Uint renames UI_Expon;
-
- function "abs" (Real : Uint) return Uint renames UI_Abs;
-
- function "mod" (Left : Uint; Right : Uint) return Uint renames UI_Mod;
- function "mod" (Left : Int; Right : Uint) return Uint renames UI_Mod;
- function "mod" (Left : Uint; Right : Int) return Uint renames UI_Mod;
-
- function "rem" (Left : Uint; Right : Uint) return Uint renames UI_Rem;
- function "rem" (Left : Int; Right : Uint) return Uint renames UI_Rem;
- function "rem" (Left : Uint; Right : Int) return Uint renames UI_Rem;
-
- function "-" (Real : Uint) return Uint renames UI_Negate;
-
- function "=" (Left : Uint; Right : Uint) return Boolean renames UI_Eq;
- function "=" (Left : Int; Right : Uint) return Boolean renames UI_Eq;
- function "=" (Left : Uint; Right : Int) return Boolean renames UI_Eq;
-
- function ">=" (Left : Uint; Right : Uint) return Boolean renames UI_Ge;
- function ">=" (Left : Int; Right : Uint) return Boolean renames UI_Ge;
- function ">=" (Left : Uint; Right : Int) return Boolean renames UI_Ge;
-
- function ">" (Left : Uint; Right : Uint) return Boolean renames UI_Gt;
- function ">" (Left : Int; Right : Uint) return Boolean renames UI_Gt;
- function ">" (Left : Uint; Right : Int) return Boolean renames UI_Gt;
-
- function "<=" (Left : Uint; Right : Uint) return Boolean renames UI_Le;
- function "<=" (Left : Int; Right : Uint) return Boolean renames UI_Le;
- function "<=" (Left : Uint; Right : Int) return Boolean renames UI_Le;
-
- function "<" (Left : Uint; Right : Uint) return Boolean renames UI_Lt;
- function "<" (Left : Int; Right : Uint) return Boolean renames UI_Lt;
- function "<" (Left : Uint; Right : Int) return Boolean renames UI_Lt;
+ function "+" (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint
+ renames UI_Add;
+ function "+" (Left : Int; Right : Valid_Uint) return Valid_Uint
+ renames UI_Add;
+ function "+" (Left : Valid_Uint; Right : Int) return Valid_Uint
+ renames UI_Add;
+
+ function "/" (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint
+ renames UI_Div;
+ function "/" (Left : Int; Right : Nonzero_Uint) return Valid_Uint
+ renames UI_Div;
+ function "/" (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint
+ renames UI_Div;
+
+ function "*" (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint
+ renames UI_Mul;
+ function "*" (Left : Int; Right : Valid_Uint) return Valid_Uint
+ renames UI_Mul;
+ function "*" (Left : Valid_Uint; Right : Int) return Valid_Uint
+ renames UI_Mul;
+
+ function "-" (Left : Valid_Uint; Right : Valid_Uint) return Valid_Uint
+ renames UI_Sub;
+ function "-" (Left : Int; Right : Valid_Uint) return Valid_Uint
+ renames UI_Sub;
+ function "-" (Left : Valid_Uint; Right : Int) return Valid_Uint
+ renames UI_Sub;
+
+ function "**" (Left : Valid_Uint; Right : Unat) return Valid_Uint
+ renames UI_Expon;
+ function "**" (Left : Valid_Uint; Right : Nat) return Valid_Uint
+ renames UI_Expon;
+ function "**" (Left : Int; Right : Unat) return Valid_Uint
+ renames UI_Expon;
+ function "**" (Left : Int; Right : Nat) return Valid_Uint
+ renames UI_Expon;
+
+ function "abs" (Real : Valid_Uint) return Unat
+ renames UI_Abs;
+
+ function "mod" (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint
+ renames UI_Mod;
+ function "mod" (Left : Int; Right : Nonzero_Uint) return Valid_Uint
+ renames UI_Mod;
+ function "mod" (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint
+ renames UI_Mod;
+
+ function "rem" (Left : Valid_Uint; Right : Nonzero_Uint) return Valid_Uint
+ renames UI_Rem;
+ function "rem" (Left : Int; Right : Nonzero_Uint) return Valid_Uint
+ renames UI_Rem;
+ function "rem" (Left : Valid_Uint; Right : Nonzero_Int) return Valid_Uint
+ renames UI_Rem;
+
+ function "-" (Real : Valid_Uint) return Valid_Uint
+ renames UI_Negate;
+
+ function "=" (Left : Valid_Uint; Right : Valid_Uint) return Boolean
+ renames UI_Eq;
+ function "=" (Left : Int; Right : Valid_Uint) return Boolean
+ renames UI_Eq;
+ function "=" (Left : Valid_Uint; Right : Int) return Boolean
+ renames UI_Eq;
+
+ function ">=" (Left : Valid_Uint; Right : Valid_Uint) return Boolean
+ renames UI_Ge;
+ function ">=" (Left : Int; Right : Valid_Uint) return Boolean
+ renames UI_Ge;
+ function ">=" (Left : Valid_Uint; Right : Int) return Boolean
+ renames UI_Ge;
+
+ function ">" (Left : Valid_Uint; Right : Valid_Uint) return Boolean
+ renames UI_Gt;
+ function ">" (Left : Int; Right : Valid_Uint) return Boolean
+ renames UI_Gt;
+ function ">" (Left : Valid_Uint; Right : Int) return Boolean
+ renames UI_Gt;
+
+ function "<=" (Left : Valid_Uint; Right : Valid_Uint) return Boolean
+ renames UI_Le;
+ function "<=" (Left : Int; Right : Valid_Uint) return Boolean
+ renames UI_Le;
+ function "<=" (Left : Valid_Uint; Right : Int) return Boolean
+ renames UI_Le;
+
+ function "<" (Left : Valid_Uint; Right : Valid_Uint) return Boolean
+ renames UI_Lt;
+ function "<" (Left : Int; Right : Valid_Uint) return Boolean
+ renames UI_Lt;
+ function "<" (Left : Valid_Uint; Right : Int) return Boolean
+ renames UI_Lt;
-----------------------------
-- Mark/Release Processing --
procedure Release (M : Save_Mark);
-- Release storage allocated since mark was noted
- procedure Release_And_Save (M : Save_Mark; UI : in out Uint);
+ procedure Release_And_Save (M : Save_Mark; UI : in out Valid_Uint);
-- Like Release, except that the given Uint value (which is typically among
-- the data being released) is recopied after the release, so that it is
-- the most recent item, and UI is updated to point to its copied location.
- procedure Release_And_Save (M : Save_Mark; UI1, UI2 : in out Uint);
+ procedure Release_And_Save (M : Save_Mark; UI1, UI2 : in out Valid_Uint);
-- Like Release, except that the given Uint values (which are typically
-- among the data being released) are recopied after the release, so that
-- they are the most recent items, and UI1 and UI2 are updated if necessary
-- UI_Mul to efficiently compute the product in this case.
type Save_Mark is record
- Save_Uint : Uint;
+ Save_Uint : Valid_Uint;
Save_Udigit : Int;
end record;