1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . D I M . F L O A T _ I O --
9 -- Copyright (C) 2011-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package provides output routines for float dimensioned types. All Put
33 -- routines are modelled after those in package Ada.Text_IO.Float_IO with the
34 -- addition of an extra default parameter. All Put_Dim_Of routines
35 -- output the dimension of Item in a symbolic manner.
37 -- Parameter Symbol may be used in the following manner (all the examples are
38 -- based on the MKS system of units defined in package System.Dim.Mks):
40 -- type Mks_Type is new Long_Long_Float
42 -- Dimension_System => (
43 -- (Unit_Name => Meter, Unit_Symbol => 'm', Dim_Symbol => 'L'),
44 -- (Unit_Name => Kilogram, Unit_Symbol => "kg", Dim_Symbol => 'M'),
45 -- (Unit_Name => Second, Unit_Symbol => 's', Dim_Symbol => 'T'),
46 -- (Unit_Name => Ampere, Unit_Symbol => 'A', Dim_Symbol => 'I'),
47 -- (Unit_Name => Kelvin, Unit_Symbol => 'K', Dim_Symbol => '@'),
48 -- (Unit_Name => Mole, Unit_Symbol => "mol", Dim_Symbol => 'N'),
49 -- (Unit_Name => Candela, Unit_Symbol => "cd", Dim_Symbol => 'J'));
51 -- Case 1. A value is supplied for Symbol
53 -- * Put : The string appears as a suffix of Item
55 -- * Put_Dim_Of : The string appears alone
57 -- Obj : Mks_Type := 2.6;
58 -- Put (Obj, 1, 1, 0, " dimensionless");
59 -- Put_Dim_Of (Obj, "dimensionless");
61 -- The corresponding outputs are:
65 -- Case 2. No value is supplied for Symbol and Item is dimensionless
67 -- * Put : Item appears without a suffix
69 -- * Put_Dim_Of : the output is []
71 -- Obj : Mks_Type := 2.6;
72 -- Put (Obj, 1, 1, 0);
75 -- The corresponding outputs are:
79 -- Case 3. No value is supplied for Symbol and Item has a dimension
81 -- * Put : If the type of Item is a dimensioned subtype whose
82 -- symbol is not empty, then the symbol appears as a suffix.
83 -- Otherwise, a new string is created and appears as a
84 -- suffix of Item. This string results in the successive
85 -- concatenations between each unit symbol raised by its
86 -- corresponding dimension power from the dimensions of Item.
88 -- * Put_Dim_Of : The output is a new string resulting in the successive
89 -- concatenations between each dimension symbol raised by its
90 -- corresponding dimension power from the dimensions of Item.
92 -- subtype Length is Mks_Type
98 -- Obj : Length := 2.3 * dm;
99 -- Put (Obj, 1, 2, 0);
102 -- The corresponding outputs are:
106 -- subtype Random is Mks_Type
113 -- Obj : Random := 5.0;
117 -- The corresponding outputs are:
118 -- $5.0 m**3.cd**(-1)
121 -- Put (3.3 * km * dm * min, 5, 1, 0);
122 -- Put_Dim_Of (3.3 * km * dm * min);
124 -- The corresponding outputs are:
128 with Ada.Text_IO; use Ada.Text_IO;
131 type Num_Dim_Float is digits <>;
133 package System.Dim.Float_IO is
135 Default_Fore : Field := 2;
136 Default_Aft : Field := Num_Dim_Float'Digits - 1;
137 Default_Exp : Field := 3;
141 Item : Num_Dim_Float;
142 Fore : Field := Default_Fore;
143 Aft : Field := Default_Aft;
144 Exp : Field := Default_Exp;
145 Symbol : String := "");
148 (Item : Num_Dim_Float;
149 Fore : Field := Default_Fore;
150 Aft : Field := Default_Aft;
151 Exp : Field := Default_Exp;
152 Symbol : String := "");
156 Item : Num_Dim_Float;
157 Aft : Field := Default_Aft;
158 Exp : Field := Default_Exp;
159 Symbol : String := "");
163 Item : Num_Dim_Float;
164 Symbol : String := "");
167 (Item : Num_Dim_Float;
168 Symbol : String := "");
172 Item : Num_Dim_Float;
173 Symbol : String := "");
176 pragma Inline (Put_Dim_Of);
178 end System.Dim.Float_IO;