aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf2a02.a
blob: e9977b0f5025b29d26c36c5f0fdff81d584f7e64 (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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
-- CXF2A02.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 the operand and result types are the same.
--
--      Check that if the mathematical result is between multiples of the
--      small of the result type, the result is truncated toward zero.
--    
-- TEST DESCRIPTION:
--      The test verifies that decimal multiplication and division behave as
--      expected for types with various digits, delta, and Machine_Radix
--      values.
--
--      The iteration, operation, and operand counts in the foundation, and
--      the operations and operand tables in the test, are given values such
--      that, when the operations loop is complete, truncation of inexact
--      results should cause the result returned by the operations loop to be
--      the same as that used to initialize the loop's cumulator variable (in
--      this test, one).
--
-- TEST FILES:
--      This test consists of the following files:
--
--         FXF2A00.A
--      -> CXF2A02.A
--
-- APPLICABILITY CRITERIA:
--      This test is only applicable for a compiler attempting validation
--      for the Information Systems Annex.
--
--
-- CHANGE HISTORY:
--      13 Mar 96   SAIC    Prerelease version for ACVC 2.1.
--      04 Aug 96   SAIC    Updated prologue.
--
--!

package CXF2A02_0 is

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

   type Micro is delta 10.0**(-5) digits 6; -- range -9.99999 ..
   for Micro'Machine_Radix use 2;      --            +9.99999

   function Multiply (Left, Right : Micro) return Micro;
   function Divide   (Left, Right : Micro) return Micro;


   type Micro_Optr_Ptr is access function (Left, Right : Micro) return Micro;

   Micro_Mult : Micro_Optr_Ptr := Multiply'Access;
   Micro_Div  : Micro_Optr_Ptr := Divide'Access;

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

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

   function Multiply (Left, Right : Basic) return Basic;
   function Divide   (Left, Right : Basic) return Basic;


   type Basic_Optr_Ptr is access function (Left, Right : Basic) return Basic;

   Basic_Mult : Basic_Optr_Ptr := Multiply'Access;
   Basic_Div  : Basic_Optr_Ptr := Divide'Access;

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

   type Broad is delta 10.0**(-3) digits 10; -- range -9,999,999.999 ..
   for Broad'Machine_Radix use 2;            --       +9,999,999.999

   function Multiply (Left, Right : Broad) return Broad;
   function Divide   (Left, Right : Broad) return Broad;


   type Broad_Optr_Ptr is access function (Left, Right : Broad) return Broad;

   Broad_Mult : Broad_Optr_Ptr := Multiply'Access;
   Broad_Div  : Broad_Optr_Ptr := Divide'Access;

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

end CXF2A02_0;


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


package body CXF2A02_0 is

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

   function Multiply (Left, Right : Micro) return Micro is
   begin
      return (Left * Right); -- Decimal fixed multiplication.
   end Multiply;

   function Divide (Left, Right : Micro) return Micro is
   begin
      return (Left / Right); -- Decimal fixed division.
   end Divide;

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

   function Multiply (Left, Right : Basic) return Basic is
   begin
      return (Left * Right); -- Decimal fixed multiplication.
   end Multiply;

   function Divide (Left, Right : Basic) return Basic is
   begin
      return (Left / Right); -- Decimal fixed division.
   end Divide;

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

   function Multiply (Left, Right : Broad) return Broad is
   begin
      return (Left * Right); -- Decimal fixed multiplication.
   end Multiply;

   function Divide (Left, Right : Broad) return Broad is
   begin
      return (Left / Right); -- Decimal fixed division.
   end Divide;

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

end CXF2A02_0;


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


with FXF2A00;
package CXF2A02_0.CXF2A02_1 is

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

   type Micro_Ops   is array (FXF2A00.Optr_Range) of Micro_Optr_Ptr;
   type Micro_Opnds is array (FXF2A00.Opnd_Range) of Micro;

   Micro_Mult_Operator_Table : Micro_Ops   := ( Micro_Mult, Micro_Mult,
                                                Micro_Mult, Micro_Mult,
                                                Micro_Mult, Micro_Mult );

   Micro_Div_Operator_Table  : Micro_Ops   := ( Micro_Div, Micro_Div,
                                                Micro_Div, Micro_Div,
                                                Micro_Div, Micro_Div   );

   Micro_Mult_Operand_Table  : Micro_Opnds := ( 2.35119,
                                                0.05892,
                                                9.58122,
                                                0.80613,
                                                0.93462 );

   Micro_Div_Operand_Table   : Micro_Opnds := ( 0.58739,
                                                4.90012,
                                                0.08765,
                                                0.71577,
                                                5.53768 );

   function Test_Micro_Ops is new FXF2A00.Operations_Loop
     (Decimal_Fixed  => Micro,
      Operator_Ptr   => Micro_Optr_Ptr,
      Operator_Table => Micro_Ops,
      Operand_Table  => Micro_Opnds);

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

   type Basic_Ops   is array (FXF2A00.Optr_Range) of Basic_Optr_Ptr;
   type Basic_Opnds is array (FXF2A00.Opnd_Range) of Basic;

   Basic_Mult_Operator_Table : Basic_Ops   := ( Basic_Mult, Basic_Mult,
                                                Basic_Mult, Basic_Mult,
                                                Basic_Mult, Basic_Mult );

   Basic_Div_Operator_Table  : Basic_Ops   := ( Basic_Div, Basic_Div,
                                                Basic_Div, Basic_Div,
                                                Basic_Div, Basic_Div   );

   Basic_Mult_Operand_Table  : Basic_Opnds := (       127.10,
                                                        0.02,
                                                        0.87,
                                                       45.67,
                                                        0.01  );

   Basic_Div_Operand_Table   : Basic_Opnds := (         0.03,
                                                        0.08,
                                                       23.57,
                                                        0.11,
                                                      159.11  );

   function Test_Basic_Ops is new FXF2A00.Operations_Loop
     (Decimal_Fixed  => Basic,
      Operator_Ptr   => Basic_Optr_Ptr,
      Operator_Table => Basic_Ops,
      Operand_Table  => Basic_Opnds);

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

   type Broad_Ops   is array (FXF2A00.Optr_Range) of Broad_Optr_Ptr;
   type Broad_Opnds is array (FXF2A00.Opnd_Range) of Broad;

   Broad_Mult_Operator_Table : Broad_Ops   := ( Broad_Mult, Broad_Mult,
                                                Broad_Mult, Broad_Mult,
                                                Broad_Mult, Broad_Mult );

   Broad_Div_Operator_Table  : Broad_Ops   := ( Broad_Div,  Broad_Div,
                                                Broad_Div,  Broad_Div,
                                                Broad_Div,  Broad_Div  );

   Broad_Mult_Operand_Table  : Broad_Opnds := (     589.720,
                                                      0.106,
                                                     21.018,
                                                      0.002,
                                                      0.381  );

   Broad_Div_Operand_Table   : Broad_Opnds := (       0.008,
                                                      0.793,
                                                      9.092,
                                                    214.300,
                                                      0.080  );

   function Test_Broad_Ops is new FXF2A00.Operations_Loop
     (Decimal_Fixed  => Broad,
      Operator_Ptr   => Broad_Optr_Ptr,
      Operator_Table => Broad_Ops,
      Operand_Table  => Broad_Opnds);

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

end CXF2A02_0.CXF2A02_1;


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


with CXF2A02_0.CXF2A02_1;

with Report;
procedure CXF2A02 is
   package Data renames CXF2A02_0.CXF2A02_1;

   use type CXF2A02_0.Micro;
   use type CXF2A02_0.Basic;
   use type CXF2A02_0.Broad;

   Micro_Expected : constant CXF2A02_0.Micro := 1.0;
   Basic_Expected : constant CXF2A02_0.Basic := 1.0;
   Broad_Expected : constant CXF2A02_0.Broad := 1.0;

   Micro_Actual   : CXF2A02_0.Micro;
   Basic_Actual   : CXF2A02_0.Basic;
   Broad_Actual   : CXF2A02_0.Broad;
begin

   Report.Test ("CXF2A02", "Check decimal multiplication and division, " &
                "where the operand and result types are the same");

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

   Micro_Actual := 0.0;
   Micro_Actual := Data.Test_Micro_Ops (1.0,
                                        Data.Micro_Mult_Operator_Table,
                                        Data.Micro_Mult_Operand_Table);

   if Micro_Actual /= Micro_Expected then
      Report.Failed ("Wrong result for type Micro multiplication");
   end if;


   Micro_Actual := 0.0;
   Micro_Actual := Data.Test_Micro_Ops (1.0,
                                        Data.Micro_Div_Operator_Table,
                                        Data.Micro_Div_Operand_Table);

   if Micro_Actual /= Micro_Expected then
      Report.Failed ("Wrong result for type Micro division");
   end if;

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

   Basic_Actual := 0.0;
   Basic_Actual := Data.Test_Basic_Ops (1.0,
                                        Data.Basic_Mult_Operator_Table,
                                        Data.Basic_Mult_Operand_Table);

   if Basic_Actual /= Basic_Expected then
      Report.Failed ("Wrong result for type Basic multiplication");
   end if;


   Basic_Actual := 0.0;
   Basic_Actual := Data.Test_Basic_Ops (1.0,
                                        Data.Basic_Div_Operator_Table,
                                        Data.Basic_Div_Operand_Table);

   if Basic_Actual /= Basic_Expected then
      Report.Failed ("Wrong result for type Basic division");
   end if;

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

   Broad_Actual := 0.0;
   Broad_Actual := Data.Test_Broad_Ops (1.0,
                                        Data.Broad_Mult_Operator_Table,
                                        Data.Broad_Mult_Operand_Table);

   if Broad_Actual /= Broad_Expected then
      Report.Failed ("Wrong result for type Broad multiplication");
   end if;


   Broad_Actual := 0.0;
   Broad_Actual := Data.Test_Broad_Ops (1.0,
                                        Data.Broad_Div_Operator_Table,
                                        Data.Broad_Div_Operand_Table);

   if Broad_Actual /= Broad_Expected then
      Report.Failed ("Wrong result for type Broad division");
   end if;

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

   Report.Result;

end CXF2A02;