Debian Codegraph @

gcc/ada/libgnat/s-valuer.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . V A L U E _ R --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2020-2025, 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 ------------------------------------------------------------------------------
31
32 -- This package contains routines for scanning real values for use in
33 -- Text_IO.Decimal_IO, Fixed_IO, Float_IO and the Value attribute.
34
35 with System.Unsigned_Types; use System.Unsigned_Types;
36
37 generic
38
39 type Uns is mod <>;
40 -- Modular type used for the value
41
42 Parts : Positive;
43 -- Number of Uns parts in the value
44
45 Precision_Limit : Uns;
46 -- Precision limit for each part of the value
47
48 Round : Boolean;
49 -- If Parts = 1, True if the extra digit must be rounded
50
51 package System.Value_R is
52 pragma Preelaborate;
53
54 subtype Data_Index is Positive range 1 .. Parts;
55 -- The type indexing the value
56
57 type Scale_Array is array (Data_Index) of Integer;
58 -- The scale for each part of the value
59
60 type Value_Array is array (Data_Index) of Uns;
61 -- The value split into parts
62
63 function Scan_Raw_Real
64 (Str : String;
65 Ptr : not null access Integer;
66 Max : Integer;
67 Base : out Unsigned;
68 Scale : out Scale_Array;
69 Extra : out Unsigned;
70 Minus : out Boolean) return Value_Array;
71 -- This function scans the string starting at Str (Ptr.all) for a valid
72 -- real literal according to the syntax described in (RM 3.5(43)). The
73 -- substring scanned extends no further than Str (Max). There are three
74 -- cases for the return:
75 --
76 -- If a valid real is found after scanning past any initial spaces, then
77 -- Ptr.all is updated past the last character of the real (but trailing
78 -- spaces are not scanned out) and the Base, Scale, Extra and Minus out
79 -- parameters are set; if Val is the result of the call, then the real
80 -- represented by the literal is equal to
81 --
82 -- (Val (1) * Base + Extra) * (Base ** (Scale (1) - 1))
83 --
84 -- when Parts = 1 and
85 --
86 -- Sum [Val (N) * (Base ** Scale (N)), N in 1 .. Parts]
87 --
88 -- when Parts > 1, with the negative sign if Minus is true.
89 --
90 -- If no valid real is found, then Ptr.all points either to an initial
91 -- non-blank character, or to Max + 1 if the field is all spaces and the
92 -- exception Constraint_Error is raised.
93 --
94 -- If a syntactically valid real is scanned, but the value is out of
95 -- range, or, in the based case, the base value is out of range or there
96 -- is an out of range digit, then Ptr.all points past the real literal,
97 -- and Constraint_Error is raised.
98 --
99 -- Note: these rules correspond to the requirements for leaving the
100 -- pointer positioned in Text_Io.Get
101 --
102 -- Note: if Str is null, i.e. if Max is less than Ptr, then this is a
103 -- special case of an all-blank string, and Ptr is unchanged, and hence
104 -- is greater than Max as required in this case.
105 --
106 -- Note: this routine should not be called with Str'Last = Positive'Last.
107 -- If this occurs Program_Error is raised with a message noting that this
108 -- case is not supported. Most such cases are eliminated by the caller.
109
110 function Value_Raw_Real
111 (Str : String;
112 Base : out Unsigned;
113 Scale : out Scale_Array;
114 Extra : out Unsigned;
115 Minus : out Boolean) return Value_Array;
116 -- Used in computing X'Value (Str) where X is a real type. Str is the
117 -- string argument of the attribute. Constraint_Error is raised if the
118 -- string is malformed.
119
120 end System.Value_R;