summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf2005.a
blob: 71cd5bb31b56dc6ac6058a65ef704b2ca067623b (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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
-- CXF2005.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 the multiplying operators for a decimal fixed point type
--      return values that are integral multiples of the small of the type.
--      Check the case where one operand is of the predefined type Integer.
--
-- TEST DESCRIPTION:
--      Two decimal fixed point types A and B are declared, one with a
--      Machine_Radix value of 2, and one with a value of 10. A variable of
--      each type is multiplied repeatedly by a series of different Integer
--      values. A cumulative result is kept and compared to an expected
--      final result. Similar checks are performed for division.
--
-- APPLICABILITY CRITERIA:
--      This test is only applicable for a compiler attempting validation
--      for the Information Systems Annex.
--
--
-- CHANGE HISTORY:
--      28 Mar 96   SAIC    Prerelease version for ACVC 2.1.
--
--!

generic
   type Decimal_Fixed  is delta <> digits <>;
package CXF2005_0 is

   function Multiply (Operand  : Decimal_Fixed;
                      Interval : Integer) return Decimal_Fixed;

   function Divide   (Operand  : Decimal_Fixed;
                      Interval : Integer) return Decimal_Fixed;

end CXF2005_0;


     --==================================================================--


package body CXF2005_0 is

   function Multiply (Operand  : Decimal_Fixed;
                      Interval : Integer) return Decimal_Fixed is
   begin
      return Operand * Interval;  -- Fixed-Integer multiplication.
   end Multiply;


   function Divide (Operand  : Decimal_Fixed;
                    Interval : Integer) return Decimal_Fixed is
   begin
      return Operand / Interval;  -- Fixed-Integer division.
   end Divide;

end CXF2005_0;


     --==================================================================--


package CXF2005_1 is

               ---=---=---=---=---=---=---=---=---=---=---

   type Interest_Rate is delta 0.001 range 0.0 .. 1_000.0;
   for Interest_Rate'Small use 0.001;            -- Power of 10.

               ---=---=---=---=---=---=---=---=---=---=---

   type Money_Radix2 is delta 0.01 digits 11;    -- range -999,999,999.99 ..
   for Money_Radix2'Machine_Radix use 2;         --       +999,999,999.99

   function Factor (Rate     : Interest_Rate;
                    Interval : Integer) return Money_Radix2;

               ---=---=---=---=---=---=---=---=---=---=---

   type Money_Radix10 is delta 0.01 digits 11;   -- range -999,999,999.99 ..
   for Money_Radix10'Machine_Radix use 10;       --       +999,999,999.99

   function Factor (Rate   : Interest_Rate;
                    Interval : Integer) return Money_Radix10;

               ---=---=---=---=---=---=---=---=---=---=---

end CXF2005_1;


     --==================================================================--


package body CXF2005_1 is

               ---=---=---=---=---=---=---=---=---=---=---

   function Factor (Rate   : Interest_Rate;
                    Interval : Integer) return Money_Radix2 is
   begin
      return Money_Radix2( Rate / Interval );
   end Factor;

               ---=---=---=---=---=---=---=---=---=---=---

   function Factor (Rate   : Interest_Rate;
                    Interval : Integer) return Money_Radix10 is
   begin
      return Money_Radix10( Rate / Interval );
   end Factor;

               ---=---=---=---=---=---=---=---=---=---=---

end CXF2005_1;


     --==================================================================--


with CXF2005_0;
with CXF2005_1;

with Report;
procedure CXF2005 is

   Loop_Count : constant := 25_000;
   type Loop_Range is range 1 .. Loop_Count;

begin

   Report.Test ("CXF2005", "Check decimal multiplication and division, " &
                           "where one operand type is Integer");


               ---=---=---=---=---=---=---=---=---=---=---


   RADIX_2_SUBTESTS:
   declare
      package Radix_2 is new CXF2005_0 (CXF2005_1.Money_Radix2);
      use type CXF2005_1.Money_Radix2;
   begin

      RADIX_2_MULTIPLICATION:
      declare
         Rate           : constant CXF2005_1.Interest_Rate := 0.127;
         Period         : constant Integer                 := 12;

         Expected       : constant CXF2005_1.Money_Radix2  := 2_624.88;
         Balance        :          CXF2005_1.Money_Radix2  := 1_000.00;

         Operand        :          CXF2005_1.Money_Radix2;
         Increment      :          CXF2005_1.Money_Radix2;
         Interval       :          Integer;
      begin

         for I in Loop_Range loop
            Interval  := (Integer(I) mod Period) + 1;  -- Range from 1 to 12.
            Operand   := CXF2005_1.Factor (Rate, Period);
            Increment := Radix_2.Multiply (Operand, Interval);
            Balance   := Balance + Increment;
         end loop;

         if Balance /= Expected then
            Report.Failed ("Error: Radix 2 multiply");
         end if;

      end RADIX_2_MULTIPLICATION;



      RADIX_2_DIVISION:
      declare
         Rate           : constant CXF2005_1.Interest_Rate := 0.377;
         Period         : constant Integer                 := 12;

         Expected       : constant CXF2005_1.Money_Radix2  :=  36_215.58;
         Balance        :          CXF2005_1.Money_Radix2  := 456_985.01;

         Operand        :          CXF2005_1.Money_Radix2;
         Increment      :          CXF2005_1.Money_Radix2;
         Interval       :          Integer;
      begin

         for I in Loop_Range loop
            Interval  := (Integer(I+1000) mod (200*Period)) + 1; -- 1 .. 2400.
            Operand   := CXF2005_1.Factor (Rate, Period);
            Increment := Radix_2.Divide (Balance, Interval);
            Balance   := Balance - (Operand * Increment);
         end loop;

         if Balance /= Expected then
            Report.Failed ("Error: Radix 2 divide");
         end if;

      end RADIX_2_DIVISION;

   end RADIX_2_SUBTESTS;


               ---=---=---=---=---=---=---=---=---=---=---


   RADIX_10_SUBTESTS:
   declare
      package Radix_10 is new CXF2005_0 (CXF2005_1.Money_Radix10);
      use type CXF2005_1.Money_Radix10;
   begin

      RADIX_10_MULTIPLICATION:
      declare
         Rate           : constant CXF2005_1.Interest_Rate := 0.721;
         Period         : constant Integer                 := 12;

         Expected       : constant CXF2005_1.Money_Radix10 := 9_875.62;
         Balance        :          CXF2005_1.Money_Radix10 :=   126.34;

         Operand        :          CXF2005_1.Money_Radix10;
         Increment      :          CXF2005_1.Money_Radix10;
         Interval       :          Integer;
      begin

         for I in Loop_Range loop
            Interval  := (Integer(I) mod Period) + 1;  -- Range from 1 to 12.
            Operand   := CXF2005_1.Factor (Rate, Period);
            Increment := Radix_10.Multiply (Operand, Interval);
            Balance   := Balance + Increment;
         end loop;

         if Balance /= Expected then
            Report.Failed ("Error: Radix 10 multiply");
         end if;

      end RADIX_10_MULTIPLICATION;


      RADIX_10_DIVISION:
      declare
         Rate           : constant CXF2005_1.Interest_Rate := 0.547;
         Period         : constant Integer                 := 12;

         Expected       : constant CXF2005_1.Money_Radix10 :=  26_116.37;
         Balance        :          CXF2005_1.Money_Radix10 := 770_082.46;

         Operand        :          CXF2005_1.Money_Radix10;
         Increment      :          CXF2005_1.Money_Radix10;
         Interval       :          Integer;
      begin

         for I in Loop_Range loop
            Interval  := (Integer(I+1000) mod (200*Period)) + 1; -- 1 .. 2400.
            Operand   := CXF2005_1.Factor (Rate, Period);
            Increment := Radix_10.Divide (Balance, Interval);
            Balance   := Balance - (Operand * Increment);
         end loop;

         if Balance /= Expected then
            Report.Failed ("Error: Radix 10 divide");
         end if;

      end RADIX_10_DIVISION;

   end RADIX_10_SUBTESTS;


               ---=---=---=---=---=---=---=---=---=---=---


   Report.Result;

end CXF2005;