1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . W I D E _ W I D E _ T E X T _ I O . F L O A T _ I O --
9 -- Copyright (C) 1992-2023, 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 with Ada
.Wide_Wide_Text_IO
.Float_Aux
;
33 with System
.Img_Flt
; use System
.Img_Flt
;
34 with System
.Img_LFlt
; use System
.Img_LFlt
;
35 with System
.Img_LLF
; use System
.Img_LLF
;
36 with System
.Val_Flt
; use System
.Val_Flt
;
37 with System
.Val_LFlt
; use System
.Val_LFlt
;
38 with System
.Val_LLF
; use System
.Val_LLF
;
39 with System
.WCh_Con
; use System
.WCh_Con
;
40 with System
.WCh_WtS
; use System
.WCh_WtS
;
42 package body Ada
.Wide_Wide_Text_IO
.Float_IO
is
44 package Aux_Float
is new
45 Ada
.Wide_Wide_Text_IO
.Float_Aux
(Float, Scan_Float
, Set_Image_Float
);
47 package Aux_Long_Float
is new
48 Ada
.Wide_Wide_Text_IO
.Float_Aux
49 (Long_Float, Scan_Long_Float
, Set_Image_Long_Float
);
51 package Aux_Long_Long_Float
is new
52 Ada
.Wide_Wide_Text_IO
.Float_Aux
53 (Long_Long_Float, Scan_Long_Long_Float
, Set_Image_Long_Long_Float
);
55 -- Throughout this generic body, we distinguish between the case where type
56 -- Float is OK, where type Long_Float is OK and where type Long_Long_Float
57 -- is needed. These boolean constants are used to test for this, such that
58 -- only code for the relevant case is included in the instance.
60 OK_Float
: constant Boolean := Num
'Base'Digits <= Float'Digits;
62 OK_Long_Float : constant Boolean := Num'Base'Digits <= Long_Float'Digits;
73 pragma Unsuppress
(Range_Check
);
77 Aux_Float
.Get
(File
, Float (Item
), Width
);
78 elsif OK_Long_Float
then
79 Aux_Long_Float
.Get
(File
, Long_Float (Item
), Width
);
81 Aux_Long_Long_Float
.Get
(File
, Long_Long_Float (Item
), Width
);
84 -- In the case where the type is unconstrained (e.g. Standard'Float),
85 -- the above conversion may result in an infinite value, which is
86 -- normally fine for a conversion, but in this case, we want to treat
87 -- that as a data error.
89 if not Item
'Valid then
94 when Constraint_Error
=> raise Data_Error
;
102 Get
(Current_In
, Item
, Width
);
106 (From
: Wide_Wide_String
;
110 pragma Unsuppress
(Range_Check
);
112 S
: constant String := Wide_Wide_String_To_String
(From
, WCEM_Upper
);
113 -- String on which we do the actual conversion. Note that the method
114 -- used for wide character encoding is irrelevant, since if there is
115 -- a character outside the Standard.Character range then the call to
116 -- Aux.Gets will raise Data_Error in any case.
120 Aux_Float
.Gets
(S
, Float (Item
), Last
);
121 elsif OK_Long_Float
then
122 Aux_Long_Float
.Gets
(S
, Long_Float (Item
), Last
);
124 Aux_Long_Long_Float
.Gets
(S
, Long_Long_Float (Item
), Last
);
127 -- In the case where the type is unconstrained (e.g. Standard'Float),
128 -- the above conversion may result in an infinite value, which is
129 -- normally fine for a conversion, but in this case, we want to treat
130 -- that as a data error.
132 if not Item
'Valid then
137 when Constraint_Error
=> raise Data_Error
;
147 Fore
: Field
:= Default_Fore
;
148 Aft
: Field
:= Default_Aft
;
149 Exp
: Field
:= Default_Exp
)
153 Aux_Float
.Put
(File
, Float (Item
), Fore
, Aft
, Exp
);
154 elsif OK_Long_Float
then
155 Aux_Long_Float
.Put
(File
, Long_Float (Item
), Fore
, Aft
, Exp
);
157 Aux_Long_Long_Float
.Put
158 (File
, Long_Long_Float (Item
), Fore
, Aft
, Exp
);
164 Fore
: Field
:= Default_Fore
;
165 Aft
: Field
:= Default_Aft
;
166 Exp
: Field
:= Default_Exp
)
169 Put
(Current_Out
, Item
, Fore
, Aft
, Exp
);
173 (To
: out Wide_Wide_String
;
175 Aft
: Field
:= Default_Aft
;
176 Exp
: Field
:= Default_Exp
)
178 S
: String (To
'First .. To
'Last);
182 Aux_Float
.Puts
(S
, Float (Item
), Aft
, Exp
);
183 elsif OK_Long_Float
then
184 Aux_Long_Float
.Puts
(S
, Long_Float (Item
), Aft
, Exp
);
186 Aux_Long_Long_Float
.Puts
(S
, Long_Long_Float (Item
), Aft
, Exp
);
189 for J
in S
'Range loop
190 To
(J
) := Wide_Wide_Character
'Val (Character'Pos (S
(J
)));
194 end Ada
.Wide_Wide_Text_IO
.Float_IO
;