DocAda(tm) is a productivity tool of KSCE

Prev | Up | Next | Back | Forward
About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News

A.10.9 Input-Output for Real Types

Static Semantics

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).

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:

   
       Fore  .  Aft

and to:

   
       Fore  .  Aft  E  Exp

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).

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:

   
       Default_Fore : Field := 2;
       Default_Aft  : Field := Num'Digits-1;
       Default_Exp  : Field := 3;

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:

    
       Default_Fore : Field := Num'Fore;
       Default_Aft  : Field := Num'Aft;
       Default_Exp  : Field := 0;

The following procedures are provided:

    
       procedure Get(File : in File_Type; Item : out Num; Width : in Field := 0);
       procedure Get(Item : out Num; Width : in Field := 0);
    
       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);
    
       procedure Get(From : in String; Item : out Num; Last : out Positive);
    
       procedure Put(To   : out String;
                     Item : in Num;
                     Aft  : in Field := Default_Aft;
                     Exp  : in Field := Default_Exp);

Float_Text_IO is a library package that is a nongeneric equivalent to Text_IO.Float_IO for the predefined type Float:

    
       with Ada.Text_IO;
       package Ada.Float_Text_IO is new Ada.Text_IO.Float_IO(Float);

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

An implementation may extend Get and Put for floating point types to support special values such as infinities and NaNs.

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.

The nongeneric equivalent packages may, but need not, be actual instantiations of the generic package for the appropriate predefined type.

Examples

    
       -- (blank)

       package Real_IO is new Float_IO(Real); use Real_IO;
       -- default format used at instantiation, Default_Exp = 3

       X : Real := -123.4567;  --  digits 8      (see 3.5.7)

       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"

About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News
Prev | Up | Next | Back | Forward


Copyright © 1994-1997 by Kempe Software Capital Enterprises. All Rights Reserved. For comments on this DocAda(tm) hypertext document, please write to KSCE, at docada@ksce.com