]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/libgnat/a-nbnbin.ads
[Ada] Add detection of uninitialized big reals
[thirdparty/gcc.git] / gcc / ada / libgnat / a-nbnbin.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- ADA.NUMERICS.BIG_NUMBERS.BIG_INTEGERS --
6 -- --
7 -- S p e c --
8 -- --
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. --
13 -- --
14 ------------------------------------------------------------------------------
15
16 with Ada.Streams;
17
18 private with Ada.Finalization;
19 private with System;
20
21 -- Note that some Ada 2020 aspects are commented out since they are not
22 -- supported yet.
23
24 package Ada.Numerics.Big_Numbers.Big_Integers
25 with Preelaborate
26 -- Nonblocking
27 is
28 type Big_Integer is private;
29 -- with Integer_Literal => From_String,
30 -- Put_Image => Put_Image;
31
32 function Is_Valid (Arg : Big_Integer) return Boolean
33 with Convention => Intrinsic;
34
35 function "=" (L, R : Big_Integer) return Boolean;
36
37 function "<" (L, R : Big_Integer) return Boolean;
38
39 function "<=" (L, R : Big_Integer) return Boolean;
40
41 function ">" (L, R : Big_Integer) return Boolean;
42
43 function ">=" (L, R : Big_Integer) return Boolean;
44
45 function To_Big_Integer (Arg : Integer) return Big_Integer;
46
47 subtype Big_Positive is Big_Integer
48 with Dynamic_Predicate => Big_Positive > To_Big_Integer (0),
49 Predicate_Failure => (raise Constraint_Error);
50
51 subtype Big_Natural is Big_Integer
52 with Dynamic_Predicate => Big_Natural >= To_Big_Integer (0),
53 Predicate_Failure => (raise Constraint_Error);
54
55 function In_Range (Arg, Low, High : Big_Integer) return Boolean is
56 ((Low <= Arg) and (Arg <= High));
57
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);
63
64 generic
65 type Int is range <>;
66 package Signed_Conversions is
67
68 function To_Big_Integer (Arg : Int) return Big_Integer;
69
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);
75
76 end Signed_Conversions;
77
78 generic
79 type Int is mod <>;
80 package Unsigned_Conversions is
81
82 function To_Big_Integer (Arg : Int) return Big_Integer;
83
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);
89
90 end Unsigned_Conversions;
91
92 function To_String (Arg : Big_Integer;
93 Width : Field := 0;
94 Base : Number_Base := 10) return String
95 with Post => To_String'Result'First = 1;
96
97 function From_String (Arg : String) return Big_Integer;
98
99 procedure Put_Image
100 (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
101 Arg : Big_Integer);
102
103 function "+" (L : Big_Integer) return Big_Integer;
104
105 function "-" (L : Big_Integer) return Big_Integer;
106
107 function "abs" (L : Big_Integer) return Big_Integer;
108
109 function "+" (L, R : Big_Integer) return Big_Integer;
110
111 function "-" (L, R : Big_Integer) return Big_Integer;
112
113 function "*" (L, R : Big_Integer) return Big_Integer;
114
115 function "/" (L, R : Big_Integer) return Big_Integer;
116
117 function "mod" (L, R : Big_Integer) return Big_Integer;
118
119 function "rem" (L, R : Big_Integer) return Big_Integer;
120
121 function "**" (L : Big_Integer; R : Natural) return Big_Integer;
122
123 function Min (L, R : Big_Integer) return Big_Integer;
124
125 function Max (L, R : Big_Integer) return Big_Integer;
126
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);
131
132 private
133
134 type Controlled_Bignum is new Ada.Finalization.Controlled with record
135 C : System.Address := System.Null_Address;
136 end record;
137
138 procedure Adjust (This : in out Controlled_Bignum);
139 procedure Finalize (This : in out Controlled_Bignum);
140
141 type Big_Integer is record
142 Value : Controlled_Bignum;
143 end record;
144
145 end Ada.Numerics.Big_Numbers.Big_Integers;