1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- ADA.NUMERICS.BIG_NUMBERS.BIG_REALS --
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 ------------------------------------------------------------------------------
16 with Ada.Numerics.Big_Numbers.Big_Integers;
18 with Ada.Strings.Text_Output; use Ada.Strings.Text_Output;
20 package Ada.Numerics.Big_Numbers.Big_Reals
23 type Big_Real is private with
24 Real_Literal => From_String,
25 Put_Image => Put_Image;
27 function Is_Valid (Arg : Big_Real) return Boolean
29 Convention => Intrinsic,
32 subtype Valid_Big_Real is Big_Real
33 with Dynamic_Predicate => Is_Valid (Valid_Big_Real),
34 Predicate_Failure => raise Program_Error;
37 (Num, Den : Big_Integers.Valid_Big_Integer) return Valid_Big_Real
39 -- with Pre => (Big_Integers."/=" (Den, Big_Integers.To_Big_Integer (0))
40 -- or else Constraint_Error);
43 (Arg : Valid_Big_Real) return Big_Integers.Valid_Big_Integer
46 function Denominator (Arg : Valid_Big_Real) return Big_Integers.Big_Positive
50 then Big_Integers."=" (Denominator'Result,
51 Big_Integers.To_Big_Integer (1))
53 (Big_Integers.Greatest_Common_Divisor
54 (Numerator (Arg), Denominator'Result),
55 Big_Integers.To_Big_Integer (1))),
59 (Arg : Big_Integers.Big_Integer)
60 return Valid_Big_Real is (Arg / Big_Integers.To_Big_Integer (1))
63 function To_Real (Arg : Integer) return Valid_Big_Real is
64 (Big_Integers.To_Big_Integer (Arg) / Big_Integers.To_Big_Integer (1))
67 function "=" (L, R : Valid_Big_Real) return Boolean with Global => null;
69 function "<" (L, R : Valid_Big_Real) return Boolean with Global => null;
71 function "<=" (L, R : Valid_Big_Real) return Boolean with Global => null;
73 function ">" (L, R : Valid_Big_Real) return Boolean with Global => null;
75 function ">=" (L, R : Valid_Big_Real) return Boolean with Global => null;
77 function In_Range (Arg, Low, High : Big_Real) return Boolean is
78 (Low <= Arg and then Arg <= High)
82 type Num is digits <>;
83 package Float_Conversions is
85 function To_Big_Real (Arg : Num) return Valid_Big_Real
88 function From_Big_Real (Arg : Big_Real) return Num
91 Low => To_Big_Real (Num'First),
92 High => To_Big_Real (Num'Last))
93 or else (raise Constraint_Error),
96 end Float_Conversions;
100 package Fixed_Conversions is
102 function To_Big_Real (Arg : Num) return Valid_Big_Real
105 function From_Big_Real (Arg : Big_Real) return Num
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),
113 end Fixed_Conversions;
115 function To_String (Arg : Valid_Big_Real;
118 Exp : Field := 0) return String
120 Post => To_String'Result'First = 1,
123 function From_String (Arg : String) return Big_Real
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)))
131 function From_Quotient_String (Arg : String) return Valid_Big_Real
134 procedure Put_Image (S : in out Sink'Class; V : Big_Real);
136 function "+" (L : Valid_Big_Real) return Valid_Big_Real
139 function "-" (L : Valid_Big_Real) return Valid_Big_Real
142 function "abs" (L : Valid_Big_Real) return Valid_Big_Real
145 function "+" (L, R : Valid_Big_Real) return Valid_Big_Real
148 function "-" (L, R : Valid_Big_Real) return Valid_Big_Real
151 function "*" (L, R : Valid_Big_Real) return Valid_Big_Real
154 function "/" (L, R : Valid_Big_Real) return Valid_Big_Real
157 function "**" (L : Valid_Big_Real; R : Integer) return Valid_Big_Real
160 function Min (L, R : Valid_Big_Real) return Valid_Big_Real
163 function Max (L, R : Valid_Big_Real) return Valid_Big_Real
168 type Big_Real is record
169 Num, Den : Big_Integers.Big_Integer;
172 end Ada.Numerics.Big_Numbers.Big_Reals;