1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . 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 ------------------------------------------------------------------------------
33 with Ada
.Text_IO
.Decimal_Aux
;
34 with System
.Img_Decimal_32
; use System
.Img_Decimal_32
;
35 with System
.Img_Decimal_64
; use System
.Img_Decimal_64
;
36 with System
.Img_Decimal_128
; use System
.Img_Decimal_128
;
37 with System
.Val_Decimal_32
; use System
.Val_Decimal_32
;
38 with System
.Val_Decimal_64
; use System
.Val_Decimal_64
;
39 with System
.Val_Decimal_128
; use System
.Val_Decimal_128
;
41 package body Ada
.Text_IO
.Decimal_IO
is
43 subtype Int32
is Interfaces
.Integer_32
;
44 subtype Int64
is Interfaces
.Integer_64
;
45 subtype Int128
is Interfaces
.Integer_128
;
48 Ada
.Text_IO
.Decimal_Aux
54 Ada
.Text_IO
.Decimal_Aux
60 Ada
.Text_IO
.Decimal_Aux
63 Set_Image_Decimal128
);
65 Need64
: constant Boolean := Num
'Size > 32;
66 Need128
: constant Boolean := Num
'Size > 64;
67 -- Throughout this generic body, we distinguish between the case where type
68 -- Int32 is acceptable, where type Int64 is acceptable and where an Int128
69 -- is needed. These boolean constants are used to test for these cases and
70 -- since it is a constant, only code for the relevant case will be included
73 Scale
: constant Integer := Num
'Scale;
84 pragma Unsuppress
(Range_Check
);
88 Item
:= Num
'Fixed_Value (Aux128
.Get
(File
, Width
, Scale
));
90 Item
:= Num
'Fixed_Value (Aux64
.Get
(File
, Width
, Scale
));
92 Item
:= Num
'Fixed_Value (Aux32
.Get
(File
, Width
, Scale
));
96 when Constraint_Error
=> raise Data_Error
;
104 Get
(Current_In
, Item
, Width
);
112 pragma Unsuppress
(Range_Check
);
116 Item
:= Num
'Fixed_Value (Aux128
.Gets
(From
, Last
, Scale
));
118 Item
:= Num
'Fixed_Value (Aux64
.Gets
(From
, Last
, Scale
));
120 Item
:= Num
'Fixed_Value (Aux32
.Gets
(From
, Last
, Scale
));
124 when Constraint_Error
=> raise Data_Error
;
134 Fore
: Field
:= Default_Fore
;
135 Aft
: Field
:= Default_Aft
;
136 Exp
: Field
:= Default_Exp
)
141 (File
, Int128
'Integer_Value (Item
), Fore
, Aft
, Exp
, Scale
);
144 (File
, Int64
'Integer_Value (Item
), Fore
, Aft
, Exp
, Scale
);
147 (File
, Int32
'Integer_Value (Item
), Fore
, Aft
, Exp
, Scale
);
153 Fore
: Field
:= Default_Fore
;
154 Aft
: Field
:= Default_Aft
;
155 Exp
: Field
:= Default_Exp
)
158 Put
(Current_Out
, Item
, Fore
, Aft
, Exp
);
164 Aft
: Field
:= Default_Aft
;
165 Exp
: Field
:= Default_Exp
)
169 Aux128
.Puts
(To
, Int128
'Integer_Value (Item
), Aft
, Exp
, Scale
);
171 Aux64
.Puts
(To
, Int64
'Integer_Value (Item
), Aft
, Exp
, Scale
);
173 Aux32
.Puts
(To
, Int32
'Integer_Value (Item
), Aft
, Exp
, Scale
);
177 end Ada
.Text_IO
.Decimal_IO
;