1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- ADA.NUMERICS.BIG_NUMBERS.BIG_INTEGERS --
9 -- This specification is derived from the Ada Reference Manual for use with --
10 -- GNAT. In accordance with the copyright of that document, you can freely --
11 -- copy and modify this specification, provided that if you redistribute a --
12 -- modified version, any changes that you have made are clearly indicated. --
14 ------------------------------------------------------------------------------
18 private with Ada.Finalization;
21 -- Note that some Ada 2020 aspects are commented out since they are not
24 package Ada.Numerics.Big_Numbers.Big_Integers
28 type Big_Integer is private;
29 -- with Integer_Literal => From_String,
30 -- Put_Image => Put_Image;
32 function Is_Valid (Arg : Big_Integer) return Boolean
33 with Convention => Intrinsic;
35 function "=" (L, R : Big_Integer) return Boolean;
37 function "<" (L, R : Big_Integer) return Boolean;
39 function "<=" (L, R : Big_Integer) return Boolean;
41 function ">" (L, R : Big_Integer) return Boolean;
43 function ">=" (L, R : Big_Integer) return Boolean;
45 function To_Big_Integer (Arg : Integer) return Big_Integer;
47 subtype Big_Positive is Big_Integer
48 with Dynamic_Predicate => Big_Positive > To_Big_Integer (0),
49 Predicate_Failure => (raise Constraint_Error);
51 subtype Big_Natural is Big_Integer
52 with Dynamic_Predicate => Big_Natural >= To_Big_Integer (0),
53 Predicate_Failure => (raise Constraint_Error);
55 function In_Range (Arg, Low, High : Big_Integer) return Boolean is
56 ((Low <= Arg) and (Arg <= High));
58 function To_Integer (Arg : Big_Integer) return Integer
59 with Pre => In_Range (Arg,
60 Low => To_Big_Integer (Integer'First),
61 High => To_Big_Integer (Integer'Last))
62 or else (raise Constraint_Error);
66 package Signed_Conversions is
68 function To_Big_Integer (Arg : Int) return Big_Integer;
70 function From_Big_Integer (Arg : Big_Integer) return Int
71 with Pre => In_Range (Arg,
72 Low => To_Big_Integer (Int'First),
73 High => To_Big_Integer (Int'Last))
74 or else (raise Constraint_Error);
76 end Signed_Conversions;
80 package Unsigned_Conversions is
82 function To_Big_Integer (Arg : Int) return Big_Integer;
84 function From_Big_Integer (Arg : Big_Integer) return Int
85 with Pre => In_Range (Arg,
86 Low => To_Big_Integer (Int'First),
87 High => To_Big_Integer (Int'Last))
88 or else (raise Constraint_Error);
90 end Unsigned_Conversions;
92 function To_String (Arg : Big_Integer;
94 Base : Number_Base := 10) return String
95 with Post => To_String'Result'First = 1;
97 function From_String (Arg : String) return Big_Integer;
100 (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
103 function "+" (L : Big_Integer) return Big_Integer;
105 function "-" (L : Big_Integer) return Big_Integer;
107 function "abs" (L : Big_Integer) return Big_Integer;
109 function "+" (L, R : Big_Integer) return Big_Integer;
111 function "-" (L, R : Big_Integer) return Big_Integer;
113 function "*" (L, R : Big_Integer) return Big_Integer;
115 function "/" (L, R : Big_Integer) return Big_Integer;
117 function "mod" (L, R : Big_Integer) return Big_Integer;
119 function "rem" (L, R : Big_Integer) return Big_Integer;
121 function "**" (L : Big_Integer; R : Natural) return Big_Integer;
123 function Min (L, R : Big_Integer) return Big_Integer;
125 function Max (L, R : Big_Integer) return Big_Integer;
127 function Greatest_Common_Divisor
128 (L, R : Big_Integer) return Big_Positive
129 with Pre => (L /= To_Big_Integer (0) and R /= To_Big_Integer (0))
130 or else (raise Constraint_Error);
134 type Controlled_Bignum is new Ada.Finalization.Controlled with record
135 C : System.Address := System.Null_Address;
138 procedure Adjust (This : in out Controlled_Bignum);
139 procedure Finalize (This : in out Controlled_Bignum);
141 type Big_Integer is record
142 Value : Controlled_Bignum;
145 end Ada.Numerics.Big_Numbers.Big_Integers;