1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . W I D E _ T E X T _ I O . D E C I M A L _ I O --
9 -- Copyright (C) 2020-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_Text_IO
.Decimal_Aux
;
33 with System
.Img_Decimal_32
; use System
.Img_Decimal_32
;
34 with System
.Img_Decimal_64
; use System
.Img_Decimal_64
;
35 with System
.Img_Decimal_128
; use System
.Img_Decimal_128
;
36 with System
.Val_Decimal_32
; use System
.Val_Decimal_32
;
37 with System
.Val_Decimal_64
; use System
.Val_Decimal_64
;
38 with System
.Val_Decimal_128
; use System
.Val_Decimal_128
;
39 with System
.WCh_Con
; use System
.WCh_Con
;
40 with System
.WCh_WtS
; use System
.WCh_WtS
;
42 package body Ada
.Wide_Text_IO
.Decimal_IO
is
44 subtype Int32
is Interfaces
.Integer_32
;
45 subtype Int64
is Interfaces
.Integer_64
;
46 subtype Int128
is Interfaces
.Integer_128
;
49 Ada
.Wide_Text_IO
.Decimal_Aux
55 Ada
.Wide_Text_IO
.Decimal_Aux
61 Ada
.Wide_Text_IO
.Decimal_Aux
64 Set_Image_Decimal128
);
66 Need64
: constant Boolean := Num
'Size > 32;
67 Need128
: constant Boolean := Num
'Size > 64;
68 -- Throughout this generic body, we distinguish between the case where type
69 -- Int32 is acceptable, where type Int64 is acceptable and where an Int128
70 -- is needed. These boolean constants are used to test for these cases and
71 -- since it is a constant, only code for the relevant case will be included
74 Scale
: constant Integer := Num
'Scale;
85 pragma Unsuppress
(Range_Check
);
89 Item
:= Num
'Fixed_Value (Aux128
.Get
(File
, Width
, Scale
));
91 Item
:= Num
'Fixed_Value (Aux64
.Get
(File
, Width
, Scale
));
93 Item
:= Num
'Fixed_Value (Aux32
.Get
(File
, Width
, Scale
));
97 when Constraint_Error
=> raise Data_Error
;
105 Get
(Current_In
, Item
, Width
);
113 pragma Unsuppress
(Range_Check
);
115 S
: constant String := Wide_String_To_String
(From
, WCEM_Upper
);
116 -- String on which we do the actual conversion. Note that the method
117 -- used for wide character encoding is irrelevant, since if there is
118 -- a character outside the Standard.Character range then the call to
119 -- Aux.Gets will raise Data_Error in any case.
123 Item
:= Num
'Fixed_Value (Aux128
.Gets
(S
, Last
, Scale
));
125 Item
:= Num
'Fixed_Value (Aux64
.Gets
(S
, Last
, Scale
));
127 Item
:= Num
'Fixed_Value (Aux32
.Gets
(S
, Last
, Scale
));
131 when Constraint_Error
=> raise Data_Error
;
141 Fore
: Field
:= Default_Fore
;
142 Aft
: Field
:= Default_Aft
;
143 Exp
: Field
:= Default_Exp
)
148 (File
, Int128
'Integer_Value (Item
), Fore
, Aft
, Exp
, Scale
);
151 (File
, Int64
'Integer_Value (Item
), Fore
, Aft
, Exp
, Scale
);
154 (File
, Int32
'Integer_Value (Item
), Fore
, Aft
, Exp
, Scale
);
160 Fore
: Field
:= Default_Fore
;
161 Aft
: Field
:= Default_Aft
;
162 Exp
: Field
:= Default_Exp
)
165 Put
(Current_Out
, Item
, Fore
, Aft
, Exp
);
169 (To
: out Wide_String;
171 Aft
: Field
:= Default_Aft
;
172 Exp
: Field
:= Default_Exp
)
174 S
: String (To
'First .. To
'Last);
178 Aux128
.Puts
(S
, Int128
'Integer_Value (Item
), Aft
, Exp
, Scale
);
180 Aux64
.Puts
(S
, Int64
'Integer_Value (Item
), Aft
, Exp
, Scale
);
182 Aux32
.Puts
(S
, Int32
'Integer_Value (Item
), Aft
, Exp
, Scale
);
185 for J
in S
'Range loop
186 To
(J
) := Wide_Character'Val (Character'Pos (S
(J
)));
190 end Ada
.Wide_Text_IO
.Decimal_IO
;