Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
 
Annotated Ada Reference Manual (Ada 202x Draft 22)Legal Information
Contents   Index   References   Search   Previous   Next 

A.5.7 Big Reals

Static Semantics

1/5
{AI12-0208-1} The library package Numerics.Big_Numbers.Big_Reals has the following declaration:
2/5
{AI12-0208-1} with Ada.Numerics.Big_Numbers.Big_Integers;
with Ada.Streams;
package Ada.Numerics.Big_Numbers.Big_Reals
   with Preelaborate, Nonblocking,
        Global => in out synchronized Big_Reals
   is
3/5
   type Optional_Big_Real is private
      with Default_Initial_Condition => not Is_Valid (Optional_Big_Real),
           Real_Literal => From_String,
           Put_Image => Put_Image;
4/5
   function Is_Valid (Arg : Optional_Big_Real) return Boolean;
5/5
   function No_Big_Real return Optional_Big_Real
      with Post => not Is_Valid (No_Big_Real'Result);
6/5
   subtype Big_Real is Optional_Big_Real
      with Dynamic_Predicate => Is_Valid (Big_Real),
           Predicate_Failure => (raise Constraint_Error);
7/5
   function "/" (Num, Den : Big_Integer) return Big_Real
      with Pre => (if Big_Integers."=" (Den, 0)
                   then raise Constraint_Error);
8/5
   function Numerator (Arg : Big_Real) return Big_Integer;
   function Denominator (Arg : Big_Real) return Big_Positive
      with Post =>
        (Arg = 0.0) or else
        (Big_Integers.Greatest_Common_Divisor
           (Numerator (Arg), Denominator'Result) = 1);
9/5
   function To_Big_Real (Arg : Big_Integer) return Big_Real is
      (Arg / 1);
10/5
   function To_Real (Arg : Integer) return Big_Real is
      (Big_Integers.To_Big_Integer (Arg) / 1);
11/5
   function "=" (L, R : Big_Real) return Boolean;
   function "<" (L, R : Big_Real) return Boolean;
   function "<=" (L, R : Big_Real) return Boolean;
   function ">" (L, R : Big_Real) return Boolean;
   function ">=" (L, R : Big_Real) return Boolean;
12/5
   function In_Range (Arg, Low, High : Big_Real) return Boolean is
      ((Low <= Arg) and (Arg <= High));
13/5
   generic
      type Num is digits <>;
   package Float_Conversions is
      function To_Big_Real (Arg : Num) return Big_Real;
      function From_Big_Real (Arg : Big_Real) return Num
         with Pre => In_Range (Arg,
                               Low  => To_Big_Real (Num'First),
                               High => To_Big_Real (Num'Last))
                     or else (raise Constraint_Error);
   end Float_Conversions;
14/5
   generic
      type Num is delta <>;
   package Fixed_Conversions is
      function To_Big_Real (Arg : Num) return Big_Real;
      function From_Big_Real (Arg : Big_Real) return Num
         with Pre => In_Range (Arg,
                               Low  => To_Big_Real (Num'First),
                               High => To_Big_Real (Num'Last))
                     or else (raise Constraint_Error);
   end Fixed_Conversions;
15/5
   function To_String (Arg  : Big_Real;
                       Fore : Field := 2;
                       Aft  : Field := 3;
                       Exp  : Field := 0) return String
      with Post => To_String'Result'First = 1;
   function From_String (Arg   : String) return Big_Real;
16/5
   function To_Quotient_String (Arg : Big_Real) return String is
      (To_String (Numerator (Arg)) & " / " & To_String (Denominator (Arg)));
   function From_Quotient_String (Arg : String) return Big_Real;
17/5
   procedure Put_Image
     (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
      Arg    : Big_Real);
18/5
   function "+" (L : Big_Real) return Big_Real;
   function "-" (L : Big_Real) return Big_Real;
   function "abs" (L : Big_Real) return Big_Real;
   function "+" (L, R : Big_Real) return Big_Real;
   function "-" (L, R : Big_Real) return Big_Real;
   function "*" (L, R : Big_Real) return Big_Real;
   function "/" (L, R : Big_Real) return Big_Real;
   function "**" (L : Big_Real; R : Integer)
      return Big_Real;
   function Min (L, R : Big_Real) return Big_Real;
   function Max (L, R : Big_Real) return Big_Real;
19/5
private
   ... -- not specified by the language
end Ada.Numerics.Big_Numbers.Big_Reals;
20/5
{AI12-0208-1} To_String and From_String behave analogously to the Put and Get procedures defined in Text_IO.Float_IO (in particular, with respect to the interpretation of the Fore, Aft, and Exp parameters), except that Constraint_Error (not Data_Error) is propagated in error cases. From_Quotient_String implements the inverse function of To_Quotient_String; Constraint_Error is propagated in error cases. Put_Image calls To_String, converts that String to a Wide_Wide_String using To_Wide_Wide_String, and the resulting value to the stream using Wide_Wide_String'Write.
21/5
{AI12-0208-1} For an instance of Float_Conversions or Fixed_Conversions, To_Big_Real is exact (that is, the result represents exactly the same mathematical value as the argument) and From_Big_Real is subject to the same precision rules as a type conversion of a value of type T to the target type Num, where T is a hypothetical floating point type whose model numbers include all of the model numbers of Num as well as the exact mathematical value of the argument.
22/5
{AI12-0208-1} The other functions have their usual mathematical meanings.
23/5
{AI12-0208-1} The type Optional_Big_Real needs finalization (see 7.6).

Implementation Requirements

24/5
{AI12-0208-1} No storage associated with an Optional_Big_Real object shall be lost upon assignment or scope exit.
24.a/5
Implementation Note: {AI12-0208-1} The “No storage ... shall be lost” requirement does not preclude implementation techniques such as caching or unique number tables. 
25/5
{AI12-0208-1} For purposes of determining whether predicate checks are performed as part of default initialization, the type Optional_Big_Real shall be considered to have a subcomponent that has a default_expression.
25.a/5
Ramification: {AI12-0208-1} This means that the elaboration of 
25.b/5
Default_Initialized_Object : Big_Real;
25.c/5
is required to propagate Assertion_Error. 

Extensions to Ada 2012

25.d/5
{AI12-0208-1} The package Numerics.Big_Numbers.Big_Reals is new. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe