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 _ A U X --
9 -- Copyright (C) 1992-2009, 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.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
33 with Ada.Wide_Text_IO.Float_Aux; use Ada.Wide_Text_IO.Float_Aux;
35 with System.Img_Dec; use System.Img_Dec;
36 with System.Img_LLD; use System.Img_LLD;
37 with System.Val_Dec; use System.Val_Dec;
38 with System.Val_LLD; use System.Val_LLD;
40 package body Ada.Wide_Text_IO.Decimal_Aux is
49 Scale : Integer) return Integer
51 Buf : String (1 .. Field'Last);
52 Ptr : aliased Integer;
58 Load_Width (File, Width, Buf, Stop);
59 String_Skip (Buf, Ptr);
61 Load_Real (File, Buf, Stop);
65 Item := Scan_Decimal (Buf, Ptr'Access, Stop, Scale);
66 Check_End_Of_Field (Buf, Stop, Ptr, Width);
77 Scale : Integer) return Long_Long_Integer
79 Buf : String (1 .. Field'Last);
80 Ptr : aliased Integer;
82 Item : Long_Long_Integer;
86 Load_Width (File, Width, Buf, Stop);
87 String_Skip (Buf, Ptr);
89 Load_Real (File, Buf, Stop);
93 Item := Scan_Long_Long_Decimal (Buf, Ptr'Access, Stop, Scale);
94 Check_End_Of_Field (Buf, Stop, Ptr, Width);
104 Last : not null access Positive;
105 Scale : Integer) return Integer
107 Pos : aliased Integer;
111 String_Skip (From, Pos);
112 Item := Scan_Decimal (From, Pos'Access, From'Last, Scale);
117 when Constraint_Error =>
129 Last : not null access Positive;
130 Scale : Integer) return Long_Long_Integer
132 Pos : aliased Integer;
133 Item : Long_Long_Integer;
136 String_Skip (From, Pos);
137 Item := Scan_Long_Long_Decimal (From, Pos'Access, From'Last, Scale);
142 when Constraint_Error =>
160 Buf : String (1 .. Field'Last);
164 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
165 Put_Item (File, Buf (1 .. Ptr));
174 Item : Long_Long_Integer;
180 Buf : String (1 .. Field'Last);
184 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
185 Put_Item (File, Buf (1 .. Ptr));
199 Buf : String (1 .. Field'Last);
204 -- Compute Fore, allowing for Aft digits and the decimal dot
206 Fore := To'Length - Field'Max (1, Aft) - 1;
208 -- Allow for Exp and two more for E+ or E- if exponent present
211 Fore := Fore - 2 - Exp;
214 -- Make sure we have enough room
220 -- Do the conversion and check length of result
222 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
224 if Ptr > To'Length then
227 To := Buf (1 .. Ptr);
237 Item : Long_Long_Integer;
242 Buf : String (1 .. Field'Last);
249 then To'Length - 1 - Aft
250 else To'Length - 2 - Aft - Exp);
256 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
258 if Ptr > To'Length then
261 To := Buf (1 .. Ptr);
265 end Ada.Wide_Text_IO.Decimal_Aux;