aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf1001.a
blob: be7e50692528a2ca9d0124f821c62877f8d7a67a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
-- CXF1001.A
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that values of 2 and 10 are allowable values for Machine_Radix 
--      of a decimal first subtype.
--      Check that the value of Decimal.Max_Decimal_Digits is at least 18; 
--      the value of Decimal.Max_Scale is at least 18; the value of 
--      Decimal.Min_Scale is at most 0.
--
-- TEST DESCRIPTION:
--      This test examines the Machine_Radix attribute definition clause
--      and its effect on Decimal fixed point types, as well as several
--      constants from the package Ada.Decimal.
--      The first subtest checks that the Machine_Radix attribute will 
--      return the value set for Machine_Radix by an attribute definition
--      clause.  The second and third subtests examine differences between
--      the binary and decimal scaling of a type, based on the radix 
--      representation.  The final subtest examines the values
--      assigned to constants Min_Scale, Max_Scale, and Max_Decimal_Digits,
--      found in the package Ada.Decimal.
--
--       
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      29 Dec 94   SAIC    Restructured Radix 10 and Radix 2 test blocks.
--
--!

with Report;
with Ada.Decimal;

procedure CXF1001 is
begin

   Report.Test ("CXF1001", "Check that values of 2 and 10 are allowable " &
                           "values for Machine_Radix of a decimal first " &
                           "subtype.  Check that the value of "           &
                           "Decimal.Max_Decimal_Digits is at least 18; "  &
                           "the value of Decimal.Max_Scale is at least "  &
                           "18; the value of Decimal.Min_Scale is at "    &
                           "most 0");

   Attribute_Check_Block:
   declare

      Del          : constant := 1.0/10**2;
      Const_Digits : constant :=  3;
      Two          : constant :=  2;
      Ten          : constant := 10;

      type Radix_2_Type_1  is delta 0.01  digits 7;
      type Radix_2_Type_2  is delta Ada.Decimal.Min_Delta digits 10;        
      type Radix_2_Type_3  is
        delta 0.000_1 digits Ada.Decimal.Max_Decimal_Digits;

      type Radix_10_Type_1 is delta 10.0**(-Ada.Decimal.Max_Scale) digits 8;
      type Radix_10_Type_2 is delta 10.0**(-Ada.Decimal.Min_Scale) digits 6;
      type Radix_10_Type_3 is delta Ada.Decimal.Max_Delta digits 15;        
        

      -- Use an attribute definition clause to set the Machine_Radix for a
      -- decimal first subtype to either 2 or 10.
      for Radix_2_Type_1'Machine_Radix  use 2;                      
      for Radix_2_Type_2'Machine_Radix  use Two;                    
      for Radix_2_Type_3'Machine_Radix  use 10-8;                   

      for Radix_10_Type_1'Machine_Radix use 2*15/Const_Digits;     
      for Radix_10_Type_2'Machine_Radix use Ten;                             
      for Radix_10_Type_3'Machine_Radix use Radix_10_Type_2'Machine_Radix;


   begin

      -- Check that the attribute 'Machine_Radix returns the value assigned
      -- by the attribute definition clause.

      if Radix_2_Type_1'Machine_Radix /= 2  or else
         Radix_2_Type_2'Machine_Radix /= 2  or else
         Radix_2_Type_3'Machine_Radix /= 2  
      then
         Report.Failed("Incorrect radix value returned, 2 expected");
      end if;

      if Radix_10_Type_1'Machine_Radix /= 10  or else
         Radix_10_Type_2'Machine_Radix /= 10  or else
         Radix_10_Type_3'Machine_Radix /= 10  
      then
         Report.Failed("Incorrect radix value returned, 10 expected");
      end if;

   exception
      when others => Report.Failed ("Exception raised in Attr_Check_Block");
   end Attribute_Check_Block;



   Radix_Block:
   -- Premises:
   --   1) Choose several numbers, from types using either decimal scaling or
   --      binary scaling.
   --   1) Repetitively add these numbers to themselves.
   --   3) Validate that the result is the expected result, regardless of the
   --      scaling used in the definition of the type.
   declare

      Number_Of_Values : constant :=    3;
      Loop_Count       : constant := 1000;

      type Radix_2_Type  is delta 0.0001 digits 10;
      type Radix_10_Type is delta 0.0001 digits 10;
                                      
      for Radix_2_Type'Machine_Radix  use  2;
      for Radix_10_Type'Machine_Radix use 10;

      type Result_Record_Type is record
         Rad_2  : Radix_2_Type;
         Rad_10 : Radix_10_Type;
      end record;

      type Result_Array_Type is array (1..Number_Of_Values) 
        of Result_Record_Type;

      Result_Array : Result_Array_Type := ((50.00,  50.00), 
                                           (613.00, 613.00), 
                                           (72.70,  72.70));

      function Repetitive_Radix_2_Add (Value : in Radix_2_Type) 
        return Radix_2_Type is
         Result : Radix_2_Type := 0.0;
      begin
        for i in 1..Loop_Count loop
           Result := Result + Value;
        end loop;
        return Result;
      end Repetitive_Radix_2_Add;

      function Repetitive_Radix_10_Add (Value : in Radix_10_Type) 
        return Radix_10_Type is
         Result : Radix_10_Type := 0.0;
      begin
        for i in 1..Loop_Count loop
           Result := Result + Value;
        end loop;
        return Result;
      end Repetitive_Radix_10_Add;

   begin

      -- Radix 2 Cases, three different values.
      -- Compare the result of the repetitive addition with the expected
      -- Radix 2 result, as well as with the Radix 10 value after type 
      -- conversion.

      if Repetitive_Radix_2_Add(0.05) /= Result_Array(1).Rad_2  or
         Repetitive_Radix_2_Add(0.05) /= Radix_2_Type(Result_Array(1).Rad_10)
      then
         Report.Failed("Incorrect Radix 2 Result, Case 1");
      end if;

      if Repetitive_Radix_2_Add(0.613) /= 
         Result_Array(2).Rad_2            or
         Repetitive_Radix_2_Add(0.613) /= 
         Radix_2_Type(Result_Array(2).Rad_10)
      then
         Report.Failed("Incorrect Radix 2 Result, Case 2");
      end if;

      if Repetitive_Radix_2_Add(0.0727)  /= 
         Result_Array(3).Rad_2              or
         Repetitive_Radix_2_Add(0.0727)  /= 
         Radix_2_Type(Result_Array(3).Rad_10)
      then
         Report.Failed("Incorrect Radix 2 Result, Case 3");
      end if;

      -- Radix 10 Cases, three different values.
      -- Compare the result of the repetitive addition with the expected
      -- Radix 10 result, as well as with the Radix 2 value after type 
      -- conversion.

      if Repetitive_Radix_10_Add(0.05) /= Result_Array(1).Rad_10  or
         Repetitive_Radix_10_Add(0.05) /= Radix_10_Type(Result_Array(1).Rad_2)
      then
         Report.Failed("Incorrect Radix 10 Result, Case 1");
      end if;

      if Repetitive_Radix_10_Add(0.613) /= 
         Result_Array(2).Rad_10            or
         Repetitive_Radix_10_Add(0.613) /= 
         Radix_10_Type(Result_Array(2).Rad_2)
      then
         Report.Failed("Incorrect Radix 10 Result, Case 2");
      end if;

      if Repetitive_Radix_10_Add(0.0727) /= 
         Result_Array(3).Rad_10             or
         Repetitive_Radix_10_Add(0.0727) /= 
         Radix_10_Type(Result_Array(3).Rad_2)
      then
         Report.Failed("Incorrect Radix 10 Result, Case 3");
      end if;

   exception
      when others => Report.Failed ("Exception raised in Radix_Block");
   end Radix_Block;



   Size_Block:
   -- Check the implementation max/min values of constants declared in
   -- package Ada.Decimal.
   declare
      Minimum_Required_Size : constant := 18;
      Maximum_Allowed_Size  : constant :=  0;
   begin

      -- Check that the Max_Decimal_Digits value is at least 18.
      if not (Ada.Decimal.Max_Decimal_Digits >= Minimum_Required_Size) then
         Report.Failed("Insufficient size provided for Max_Decimal_Digits");
      end if;

      -- Check that the Max_Scale value is at least 18.
      if not (Ada.Decimal.Max_Scale >= Minimum_Required_Size) then
         Report.Failed("Insufficient size provided for Max_Scale");
      end if;

      -- Check that the Min_Scale value is at most 0.
      if not (Ada.Decimal.Min_Scale <= Maximum_Allowed_Size) then
         Report.Failed("Too large a value provided for Min_Scale");
      end if;

   exception
      when others => Report.Failed ("Exception raised in Size_Block");
   end Size_Block;

   Report.Result;

end CXF1001;