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