Debian Codegraph @

gcc/ada/libgnat/a-nbnbre.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- ADA.NUMERICS.BIG_NUMBERS.BIG_REALS --
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.Numerics.Big_Numbers.Big_Integers;
17
18 with Ada.Strings.Text_Buffers; use Ada.Strings.Text_Buffers;
19
20 package Ada.Numerics.Big_Numbers.Big_Reals with
21 Preelaborate,
22 Always_Terminates
23 is
24
25 type Big_Real is private with
26 Real_Literal => From_Universal_Image,
27 Put_Image => Put_Image;
28
29 function Is_Valid (Arg : Big_Real) return Boolean
30 with
31 Convention => Intrinsic,
32 Global => null;
33
34 subtype Valid_Big_Real is Big_Real
35 with Dynamic_Predicate => Is_Valid (Valid_Big_Real),
36 Predicate_Failure => raise Program_Error;
37
38 function "/"
39 (Num, Den : Big_Integers.Valid_Big_Integer) return Valid_Big_Real
40 with Global => null;
41 -- with Pre => (Big_Integers."/=" (Den, Big_Integers.To_Big_Integer (0))
42 -- or else Constraint_Error);
43
44 function Numerator
45 (Arg : Valid_Big_Real) return Big_Integers.Valid_Big_Integer
46 with Global => null;
47
48 function Denominator (Arg : Valid_Big_Real) return Big_Integers.Big_Positive
49 with
50 Post =>
51 (if Arg = To_Real (0)
52 then Big_Integers."=" (Denominator'Result,
53 Big_Integers.To_Big_Integer (1))
54 else Big_Integers."="
55 (Big_Integers.Greatest_Common_Divisor
56 (Numerator (Arg), Denominator'Result),
57 Big_Integers.To_Big_Integer (1))),
58 Global => null;
59
60 function To_Big_Real
61 (Arg : Big_Integers.Big_Integer)
62 return Valid_Big_Real is (Arg / Big_Integers.To_Big_Integer (1))
63 with Global => null;
64
65 function To_Real (Arg : Integer) return Valid_Big_Real is
66 (Big_Integers.To_Big_Integer (Arg) / Big_Integers.To_Big_Integer (1))
67 with Global => null;
68
69 function "=" (L, R : Valid_Big_Real) return Boolean with Global => null;
70
71 function "<" (L, R : Valid_Big_Real) return Boolean with Global => null;
72
73 function "<=" (L, R : Valid_Big_Real) return Boolean with Global => null;
74
75 function ">" (L, R : Valid_Big_Real) return Boolean with Global => null;
76
77 function ">=" (L, R : Valid_Big_Real) return Boolean with Global => null;
78
79 function In_Range (Arg, Low, High : Big_Real) return Boolean is
80 (Low <= Arg and then Arg <= High)
81 with Global => null;
82
83 generic
84 type Num is digits <>;
85 package Float_Conversions is
86
87 function To_Big_Real (Arg : Num) return Valid_Big_Real
88 with Global => null;
89
90 function From_Big_Real (Arg : Big_Real) return Num
91 with
92 Pre => In_Range (Arg,
93 Low => To_Big_Real (Num'First),
94 High => To_Big_Real (Num'Last))
95 or else (raise Constraint_Error),
96 Global => null;
97
98 end Float_Conversions;
99
100 generic
101 type Num is delta <>;
102 package Fixed_Conversions is
103
104 function To_Big_Real (Arg : Num) return Valid_Big_Real
105 with Global => null;
106
107 function From_Big_Real (Arg : Big_Real) return Num
108 with
109 Pre => In_Range (Arg,
110 Low => To_Big_Real (Num'First),
111 High => To_Big_Real (Num'Last))
112 or else (raise Constraint_Error),
113 Global => null;
114
115 end Fixed_Conversions;
116
117 function To_String (Arg : Valid_Big_Real;
118 Fore : Field := 2;
119 Aft : Field := 3;
120 Exp : Field := 0) return String
121 with
122 Post => To_String'Result'First = 1,
123 Global => null;
124
125 function From_String (Arg : String) return Valid_Big_Real
126 with Global => null;
127
128 function From_Universal_Image (Arg : String) return Valid_Big_Real
129 renames From_String;
130 function From_Universal_Image (Num, Den : String) return Valid_Big_Real is
131 (Big_Integers.From_Universal_Image (Num) /
132 Big_Integers.From_Universal_Image (Den))
133 with Global => null;
134
135 function To_Quotient_String (Arg : Big_Real) return String is
136 (Big_Integers.To_String (Numerator (Arg)) & " / "
137 & Big_Integers.To_String (Denominator (Arg)))
138 with Global => null;
139
140 function From_Quotient_String (Arg : String) return Valid_Big_Real
141 with Global => null;
142
143 procedure Put_Image (S : in out Root_Buffer_Type'Class; V : Big_Real);
144
145 function "+" (L : Valid_Big_Real) return Valid_Big_Real
146 with Global => null;
147
148 function "-" (L : Valid_Big_Real) return Valid_Big_Real
149 with Global => null;
150
151 function "abs" (L : Valid_Big_Real) return Valid_Big_Real
152 with Global => null;
153
154 function "+" (L, R : Valid_Big_Real) return Valid_Big_Real
155 with Global => null;
156
157 function "-" (L, R : Valid_Big_Real) return Valid_Big_Real
158 with Global => null;
159
160 function "*" (L, R : Valid_Big_Real) return Valid_Big_Real
161 with Global => null;
162
163 function "/" (L, R : Valid_Big_Real) return Valid_Big_Real
164 with Global => null;
165
166 function "**" (L : Valid_Big_Real; R : Integer) return Valid_Big_Real
167 with Global => null;
168
169 function Min (L, R : Valid_Big_Real) return Valid_Big_Real
170 with Global => null;
171
172 function Max (L, R : Valid_Big_Real) return Valid_Big_Real
173 with Global => null;
174
175 private
176
177 type Big_Real is record
178 Num, Den : Big_Integers.Big_Integer;
179 end record;
180
181 end Ada.Numerics.Big_Numbers.Big_Reals;