Debian Codegraph @

gcc/ada/libgnat/a-ticoio.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . C O M P L E X _ I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with Ada.Text_IO.Complex_Aux;
33 with Ada.Text_IO.Float_Aux;
34 with System.Img_Flt; use System.Img_Flt;
35 with System.Img_LFlt; use System.Img_LFlt;
36 with System.Img_LLF; use System.Img_LLF;
37 with System.Val_Flt; use System.Val_Flt;
38 with System.Val_LFlt; use System.Val_LFlt;
39 with System.Val_LLF; use System.Val_LLF;
40
41 package body Ada.Text_IO.Complex_IO is
42
43 use Complex_Types;
44
45 package Scalar_Float is new
46 Ada.Text_IO.Float_Aux (Float, Scan_Float, Set_Image_Float);
47
48 package Scalar_Long_Float is new
49 Ada.Text_IO.Float_Aux
50 (Long_Float, Scan_Long_Float, Set_Image_Long_Float);
51
52 package Scalar_Long_Long_Float is new
53 Ada.Text_IO.Float_Aux
54 (Long_Long_Float, Scan_Long_Long_Float, Set_Image_Long_Long_Float);
55
56 package Aux_Float is new
57 Ada.Text_IO.Complex_Aux (Float, Scalar_Float);
58
59 package Aux_Long_Float is new
60 Ada.Text_IO.Complex_Aux (Long_Float, Scalar_Long_Float);
61
62 package Aux_Long_Long_Float is new
63 Ada.Text_IO.Complex_Aux (Long_Long_Float, Scalar_Long_Long_Float);
64
65 -- Throughout this generic body, we distinguish between the case where type
66 -- Float is OK, where type Long_Float is OK and where type Long_Long_Float
67 -- is needed. These boolean constants are used to test for this, such that
68 -- only code for the relevant case is included in the instance.
69
70 OK_Float : constant Boolean := Real'Base'Digits <= Float'Digits;
71
72 OK_Long_Float : constant Boolean := Real'Base'Digits <= Long_Float'Digits;
73
74 ---------
75 -- Get --
76 ---------
77
78 procedure Get
79 (File : File_Type;
80 Item : out Complex;
81 Width : Field := 0)
82 is
83 Real_Item : Real'Base;
84 Imag_Item : Real'Base;
85
86 begin
87 if OK_Float then
88 Aux_Float.Get (File, Float (Real_Item), Float (Imag_Item), Width);
89 elsif OK_Long_Float then
90 Aux_Long_Float.Get
91 (File, Long_Float (Real_Item), Long_Float (Imag_Item), Width);
92 else
93 Aux_Long_Long_Float.Get
94 (File, Long_Long_Float (Real_Item), Long_Long_Float (Imag_Item),
95 Width);
96 end if;
97
98 Item := (Real_Item, Imag_Item);
99
100 exception
101 when Constraint_Error => raise Data_Error;
102 end Get;
103
104 ---------
105 -- Get --
106 ---------
107
108 procedure Get
109 (Item : out Complex;
110 Width : Field := 0)
111 is
112 begin
113 Get (Current_In, Item, Width);
114 end Get;
115
116 ---------
117 -- Get --
118 ---------
119
120 procedure Get
121 (From : String;
122 Item : out Complex;
123 Last : out Positive)
124 is
125 Real_Item : Real'Base;
126 Imag_Item : Real'Base;
127
128 begin
129 if OK_Float then
130 Aux_Float.Gets (From, Float (Real_Item), Float (Imag_Item), Last);
131 elsif OK_Long_Float then
132 Aux_Long_Float.Gets
133 (From, Long_Float (Real_Item), Long_Float (Imag_Item), Last);
134 else
135 Aux_Long_Long_Float.Gets
136 (From, Long_Long_Float (Real_Item), Long_Long_Float (Imag_Item),
137 Last);
138 end if;
139
140 Item := (Real_Item, Imag_Item);
141
142 exception
143 when Data_Error => raise Constraint_Error;
144 end Get;
145
146 ---------
147 -- Put --
148 ---------
149
150 procedure Put
151 (File : File_Type;
152 Item : Complex;
153 Fore : Field := Default_Fore;
154 Aft : Field := Default_Aft;
155 Exp : Field := Default_Exp)
156 is
157 begin
158 if OK_Float then
159 Aux_Float.Put
160 (File, Float (Re (Item)), Float (Im (Item)), Fore, Aft, Exp);
161 elsif OK_Long_Float then
162 Aux_Long_Float.Put
163 (File, Long_Float (Re (Item)), Long_Float (Im (Item)), Fore, Aft,
164 Exp);
165 else
166 Aux_Long_Long_Float.Put
167 (File, Long_Long_Float (Re (Item)), Long_Long_Float (Im (Item)),
168 Fore, Aft, Exp);
169 end if;
170 end Put;
171
172 ---------
173 -- Put --
174 ---------
175
176 procedure Put
177 (Item : Complex;
178 Fore : Field := Default_Fore;
179 Aft : Field := Default_Aft;
180 Exp : Field := Default_Exp)
181 is
182 begin
183 Put (Current_Out, Item, Fore, Aft, Exp);
184 end Put;
185
186 ---------
187 -- Put --
188 ---------
189
190 procedure Put
191 (To : out String;
192 Item : Complex;
193 Aft : Field := Default_Aft;
194 Exp : Field := Default_Exp)
195 is
196 begin
197 if OK_Float then
198 Aux_Float.Puts (To, Float (Re (Item)), Float (Im (Item)), Aft, Exp);
199 elsif OK_Long_Float then
200 Aux_Long_Float.Puts
201 (To, Long_Float (Re (Item)), Long_Float (Im (Item)), Aft, Exp);
202 else
203 Aux_Long_Long_Float.Puts
204 (To, Long_Long_Float (Re (Item)), Long_Long_Float (Im (Item)),
205 Aft, Exp);
206 end if;
207 end Put;
208
209 end Ada.Text_IO.Complex_IO;