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-2008, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Ada.Wide_Text_IO.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
35 with Ada.Wide_Text_IO.Float_Aux; use Ada.Wide_Text_IO.Float_Aux;
37 with System.Img_Dec; use System.Img_Dec;
38 with System.Img_LLD; use System.Img_LLD;
39 with System.Val_Dec; use System.Val_Dec;
40 with System.Val_LLD; use System.Val_LLD;
42 package body Ada.Wide_Text_IO.Decimal_Aux is
51 Scale : Integer) return Integer
53 Buf : String (1 .. Field'Last);
54 Ptr : aliased Integer;
60 Load_Width (File, Width, Buf, Stop);
61 String_Skip (Buf, Ptr);
63 Load_Real (File, Buf, Stop);
67 Item := Scan_Decimal (Buf, Ptr'Access, Stop, Scale);
68 Check_End_Of_Field (Buf, Stop, Ptr, Width);
79 Scale : Integer) return Long_Long_Integer
81 Buf : String (1 .. Field'Last);
82 Ptr : aliased Integer;
84 Item : Long_Long_Integer;
88 Load_Width (File, Width, Buf, Stop);
89 String_Skip (Buf, Ptr);
91 Load_Real (File, Buf, Stop);
95 Item := Scan_Long_Long_Decimal (Buf, Ptr'Access, Stop, Scale);
96 Check_End_Of_Field (Buf, Stop, Ptr, Width);
106 Last : not null access Positive;
107 Scale : Integer) return Integer
109 Pos : aliased Integer;
113 String_Skip (From, Pos);
114 Item := Scan_Decimal (From, Pos'Access, From'Last, Scale);
119 when Constraint_Error =>
131 Last : not null access Positive;
132 Scale : Integer) return Long_Long_Integer
134 Pos : aliased Integer;
135 Item : Long_Long_Integer;
138 String_Skip (From, Pos);
139 Item := Scan_Long_Long_Decimal (From, Pos'Access, From'Last, Scale);
144 when Constraint_Error =>
162 Buf : String (1 .. Field'Last);
166 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
167 Put_Item (File, Buf (1 .. Ptr));
176 Item : Long_Long_Integer;
182 Buf : String (1 .. Field'Last);
186 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
187 Put_Item (File, Buf (1 .. Ptr));
201 Buf : String (1 .. Field'Last);
206 -- Compute Fore, allowing for Aft digits and the decimal dot
208 Fore := To'Length - Field'Max (1, Aft) - 1;
210 -- Allow for Exp and two more for E+ or E- if exponent present
213 Fore := Fore - 2 - Exp;
216 -- Make sure we have enough room
222 -- Do the conversion and check length of result
224 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
226 if Ptr > To'Length then
229 To := Buf (1 .. Ptr);
239 Item : Long_Long_Integer;
244 Buf : String (1 .. Field'Last);
250 Fore := To'Length - 1 - Aft;
252 Fore := To'Length - 2 - Aft - Exp;
259 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
261 if Ptr > To'Length then
264 To := Buf (1 .. Ptr);
268 end Ada.Wide_Text_IO.Decimal_Aux;