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
16with Ada.Numerics.Big_Numbers.Big_Integers;
17with Ada.Streams;
18
19--  Note that some Ada 2020 aspects are commented out since they are not
20--  supported yet.
21
22package Ada.Numerics.Big_Numbers.Big_Reals
23  with Preelaborate
24--  Nonblocking, Global => in out synchronized Big_Reals
25is
26   type Big_Real is private;
27--   with Real_Literal => From_String,
28--        Put_Image    => Put_Image;
29
30   function Is_Valid (Arg : Big_Real) return Boolean;
31
32   function "/" (Num, Den : Big_Integers.Big_Integer) return Big_Real;
33--   with Pre => (if Big_Integers."=" (Den, Big_Integers.To_Big_Integer (0))
34--                then raise Constraint_Error);
35
36   function Numerator (Arg : Big_Real) return Big_Integers.Big_Integer;
37
38   function Denominator (Arg : Big_Real) return Big_Integers.Big_Positive
39     with Post =>
40       (Arg = To_Real (0)) or else
41       (Big_Integers."="
42         (Big_Integers.Greatest_Common_Divisor
43           (Numerator (Arg), Denominator'Result),
44          Big_Integers.To_Big_Integer (1)));
45
46   function To_Big_Real
47     (Arg : Big_Integers.Big_Integer)
48     return Big_Real is (Arg / Big_Integers.To_Big_Integer (1));
49
50   function To_Real (Arg : Integer) return Big_Real is
51     (Big_Integers.To_Big_Integer (Arg) / Big_Integers.To_Big_Integer (1));
52
53   function "=" (L, R : Big_Real) return Boolean;
54
55   function "<" (L, R : Big_Real) return Boolean;
56
57   function "<=" (L, R : Big_Real) return Boolean;
58
59   function ">" (L, R : Big_Real) return Boolean;
60
61   function ">=" (L, R : Big_Real) return Boolean;
62
63   function In_Range (Arg, Low, High : Big_Real) return Boolean is
64     (Low <= Arg and then Arg <= High);
65
66   generic
67      type Num is digits <>;
68   package Float_Conversions is
69
70      function To_Big_Real (Arg : Num) return Big_Real;
71
72      function From_Big_Real (Arg : Big_Real) return Num
73        with Pre => In_Range (Arg,
74                              Low  => To_Big_Real (Num'First),
75                              High => To_Big_Real (Num'Last))
76                    or else (raise Constraint_Error);
77
78   end Float_Conversions;
79
80   generic
81      type Num is delta <>;
82   package Fixed_Conversions is
83
84      function To_Big_Real (Arg : Num) return Big_Real;
85
86      function From_Big_Real (Arg : Big_Real) return Num
87        with Pre => In_Range (Arg,
88                              Low  => To_Big_Real (Num'First),
89                              High => To_Big_Real (Num'Last))
90                    or else (raise Constraint_Error);
91
92   end Fixed_Conversions;
93
94   function To_String (Arg  : Big_Real;
95                       Fore : Field := 2;
96                       Aft  : Field := 3;
97                       Exp  : Field := 0) return String
98      with Post => To_String'Result'First = 1;
99
100   function From_String (Arg : String) return Big_Real;
101
102   function To_Quotient_String (Arg : Big_Real) return String is
103     (Big_Integers.To_String (Numerator (Arg)) & " / "
104      & Big_Integers.To_String (Denominator (Arg)));
105
106   function From_Quotient_String (Arg : String) return Big_Real;
107
108   procedure Put_Image
109     (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
110      Arg    : Big_Real);
111
112   function "+" (L : Big_Real) return Big_Real;
113
114   function "-" (L : Big_Real) return Big_Real;
115
116   function "abs" (L : Big_Real) return Big_Real;
117
118   function "+" (L, R : Big_Real) return Big_Real;
119
120   function "-" (L, R : Big_Real) return Big_Real;
121
122   function "*" (L, R : Big_Real) return Big_Real;
123
124   function "/" (L, R : Big_Real) return Big_Real;
125
126   function "**" (L : Big_Real; R : Integer) return Big_Real;
127
128   function Min (L, R : Big_Real) return Big_Real;
129
130   function Max (L, R : Big_Real) return Big_Real;
131
132private
133
134   type Big_Real is record
135      Num, Den : Big_Integers.Big_Integer;
136   end record;
137
138end Ada.Numerics.Big_Numbers.Big_Reals;
139