Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


A.10.9 Input-Output for Real Types

Static Semantics
(1)
The following procedures are defined in the generic packages Float_IO, Fixed_IO, and Decimal_IO, which have to be instantiated for the appropriate floating point, ordinary fixed point, or decimal fixed point type respectively (indicated by Num in the specifications).
(2)
Values are output as decimal literals without low line characters. The format of each value output consists of a Fore field, a decimal point, an Aft field, and (if a nonzero Exp parameter is supplied) the letter E and an Exp field. The two possible formats thus correspond to:
(3)
       Fore  .  Aft
(4)
and to:
(5)
       Fore  .  Aft  E  Exp
(6)
without any spaces between these fields. The Fore field may include leading spaces, and a minus sign for negative values. The Aft field includes only decimal digits (possibly with trailing zeros). The Exp field includes the sign (plus or minus) and the exponent (possibly with leading zeros).
(7)
For floating point types, the default lengths of these fields are defined by the following variables that are declared in the generic package Float_IO:
(8)
       Default_Fore : Field := 2;
       Default_Aft  : Field := Num'Digits-1;
       Default_Exp  : Field := 3;
(9)
For ordinary or decimal fixed point types, the default lengths of these fields are defined by the following variables that are declared in the generic packages Fixed_IO and Decimal_IO, respectively:
(10)
       Default_Fore : Field := Num'Fore;
       Default_Aft  : Field := Num'Aft;
       Default_Exp  : Field := 0;
(11)
The following procedures are provided:
(12)
       procedure Get(File : in File_Type; Item : out Num; Width : in Field := 0);
       procedure Get(Item : out Num; Width : in Field := 0);
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
(21)
(22)
       procedure Put(File : in File_Type;
                     Item : in Num;
                     Fore : in Field := Default_Fore;
                     Aft  : in Field := Default_Aft;
                     Exp  : in Field := Default_Exp);

       procedure Put(Item : in Num;
                     Fore : in Field := Default_Fore;
                     Aft  : in Field := Default_Aft;
                     Exp  : in Field := Default_Exp);
(23)
(24)
(25)
(26)
(27)
       procedure Get(From : in String; Item : out Num; Last : out Positive);
(28)
(29)
(30)
       procedure Put(To   : out String;
                     Item : in Num;
                     Aft  : in Field := Default_Aft;
                     Exp  : in Field := Default_Exp);
(31)
(32)
Float_Text_IO is a library package that is a nongeneric equivalent to Text_IO.Float_IO for the predefined type Float:
(33)
       with Ada.Text_IO;
       package Ada.Float_Text_IO is new Ada.Text_IO.Float_IO(Float);
(34)
For each predefined floating point type, a nongeneric equivalent to Text_IO.Float_IO is provided, with names such as Ada.Long_Float_Text_IO.
Implementation Permissions
(35)
An implementation may extend Get and Put for floating point types to support special values such as infinities and NaNs.
(36)
The implementation of Put need not produce an output value with greater accuracy than is supported for the base subtype. The additional accuracy, if any, of the value produced by Put when the number of requested digits in the integer and fractional parts exceeds the required accuracy is implementation defined.
(37)
The nongeneric equivalent packages may, but need not, be actual instantiations of the generic package for the appropriate predefined type.

(38)
(39)
Examples
(40)
       -- (blank)
(41)
       package Real_IO is new Float_IO(Real); use Real_IO;
       -- default format used at instantiation, Default_Exp = 3
(42)
       X : Real := -123.4567;  --  digits 8      (see 3.5.7)
(43)
       Put(X);  -- default format                          "-1.2345670E+02"
       Put(X, Fore => 5, Aft => 3, Exp => 2);              -- "bbb-1.235E+2"
       Put(X, 5, 3, 0);                                    -- "b-123.457"

Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12