2015-09-28 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / ada / a-tideio.adb
blob5dceb128f90ea6d5bd6115885b2775f500fb61bd
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . D E C I M A L _ I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with Ada.Text_IO.Decimal_Aux;
34 package body Ada.Text_IO.Decimal_IO is
36 package Aux renames Ada.Text_IO.Decimal_Aux;
38 Scale : constant Integer := Num'Scale;
40 ---------
41 -- Get --
42 ---------
44 procedure Get
45 (File : File_Type;
46 Item : out Num;
47 Width : Field := 0)
49 pragma Unsuppress (Range_Check);
51 begin
52 if Num'Size > Integer'Size then
53 Item := Num'Fixed_Value (Aux.Get_LLD (File, Width, Scale));
54 else
55 Item := Num'Fixed_Value (Aux.Get_Dec (File, Width, Scale));
56 end if;
58 exception
59 when Constraint_Error => raise Data_Error;
60 end Get;
62 procedure Get
63 (Item : out Num;
64 Width : Field := 0)
66 begin
67 Get (Current_In, Item, Width);
68 end Get;
70 procedure Get
71 (From : String;
72 Item : out Num;
73 Last : out Positive)
75 pragma Unsuppress (Range_Check);
77 begin
78 if Num'Size > Integer'Size then
79 Item := Num'Fixed_Value
80 (Aux.Gets_LLD (From, Last'Unrestricted_Access, Scale));
81 else
82 Item := Num'Fixed_Value
83 (Aux.Gets_Dec (From, Last'Unrestricted_Access, Scale));
84 end if;
86 exception
87 when Constraint_Error => raise Data_Error;
88 end Get;
90 ---------
91 -- Put --
92 ---------
94 procedure Put
95 (File : File_Type;
96 Item : Num;
97 Fore : Field := Default_Fore;
98 Aft : Field := Default_Aft;
99 Exp : Field := Default_Exp)
101 begin
102 if Num'Size > Integer'Size then
103 Aux.Put_LLD
104 (File, Long_Long_Integer'Integer_Value (Item),
105 Fore, Aft, Exp, Scale);
106 else
107 Aux.Put_Dec
108 (File, Integer'Integer_Value (Item), Fore, Aft, Exp, Scale);
109 end if;
110 end Put;
112 procedure Put
113 (Item : Num;
114 Fore : Field := Default_Fore;
115 Aft : Field := Default_Aft;
116 Exp : Field := Default_Exp)
118 begin
119 Put (Current_Out, Item, Fore, Aft, Exp);
120 end Put;
122 procedure Put
123 (To : out String;
124 Item : Num;
125 Aft : Field := Default_Aft;
126 Exp : Field := Default_Exp)
128 begin
129 if Num'Size > Integer'Size then
130 Aux.Puts_LLD
131 (To, Long_Long_Integer'Integer_Value (Item), Aft, Exp, Scale);
132 else
133 Aux.Puts_Dec (To, Integer'Integer_Value (Item), Aft, Exp, Scale);
134 end if;
135 end Put;
137 end Ada.Text_IO.Decimal_IO;