summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf2a01.a
blob: 002c59d6c8e5d78fdf57c4519e4c45708544356c (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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
-- CXF2A01.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 binary adding operators for a decimal fixed point type
--      return values that are integral multiples of the small of the type.
--    
-- TEST DESCRIPTION:
--      The test verifies that decimal addition and subtraction behave as
--      expected for types with various digits, delta, and Machine_Radix
--      values. Types with the minimum values for Decimal.Max_Digits and
--      Decimal.Max_Scale (18) are included.
--
--      Two kinds of checks are performed for each type. In the first check,
--      the iteration, operation, and operand counts in the foundation and
--      the operation tables in this test are given values such that, when the
--      operations loop is complete, each operand will have been added to and
--      subtracted from the loop's cumulator variable the same number of times,
--      albeit in varying order. Thus, the result returned by the operations
--      loop should have the same value as that used to initialize the
--      cumulator (in this test, zero).
--
--      In the second check, the same operation (addition for some types and
--      subtraction for others) is performed during each loop iteration,
--      resulting in a cumulative total which is checked against an expected
--      value.
--
-- TEST FILES:
--      The following files comprise this test:
--
--         FXF2A00.A
--      -> CXF2A01.A
--
-- APPLICABILITY CRITERIA:
--      This test is only applicable for a compiler attempting validation
--      for the Information Systems Annex.
--
--
-- CHANGE HISTORY:
--      08 Apr 96   SAIC    Prerelease version for ACVC 2.1.
--
--!

package CXF2A01_0 is

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

   type Micro is delta 10.0**(-18) digits 18; -- range -0.999999999999999999 ..
   for Micro'Machine_Radix use 10;     --              +0.999999999999999999

   function Add      (Left, Right : Micro) return Micro;
   function Subtract (Left, Right : Micro) return Micro;


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

   Micro_Add : Micro_Optr_Ptr := Add'Access;
   Micro_Sub : Micro_Optr_Ptr := Subtract'Access;

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

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

   function Add      (Left, Right : Money) return Money;
   function Subtract (Left, Right : Money) return Money;


   type Money_Optr_Ptr is access function (Left, Right : Money) return Money;

   Money_Add : Money_Optr_Ptr := Add'Access;
   Money_Sub : Money_Optr_Ptr := Subtract'Access;

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

   -- Same as Money, but with Radix 10:

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

   function Add      (Left, Right : Cash) return Cash;
   function Subtract (Left, Right : Cash) return Cash;


   type Cash_Optr_Ptr is access function (Left, Right : Cash) return Cash;

   Cash_Add : Cash_Optr_Ptr := Add'Access;
   Cash_Sub : Cash_Optr_Ptr := Subtract'Access;

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

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

   function Add      (Left, Right : Broad) return Broad;
   function Subtract (Left, Right : Broad) return Broad;


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

   Broad_Add : Broad_Optr_Ptr := Add'Access;
   Broad_Sub : Broad_Optr_Ptr := Subtract'Access;

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

end CXF2A01_0;


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


package body CXF2A01_0 is

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

   function Add (Left, Right : Micro) return Micro is
   begin
      return (Left + Right); -- Decimal fixed addition.
   end Add;

   function Subtract (Left, Right : Micro) return Micro is
   begin
      return (Left - Right); -- Decimal fixed subtraction.
   end Subtract;

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

   function Add (Left, Right : Money) return Money is
   begin
      return (Left + Right); -- Decimal fixed addition.
   end Add;

   function Subtract (Left, Right : Money) return Money is
   begin
      return (Left - Right); -- Decimal fixed subtraction.
   end Subtract;

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

   function Add (Left, Right : Cash) return Cash is
   begin
      return (Left + Right); -- Decimal fixed addition.
   end Add;

   function Subtract (Left, Right : Cash) return Cash is
   begin
      return (Left - Right); -- Decimal fixed subtraction.
   end Subtract;

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

   function Add (Left, Right : Broad) return Broad is
   begin
      return (Left + Right); -- Decimal fixed addition.
   end Add;

   function Subtract (Left, Right : Broad) return Broad is
   begin
      return (Left - Right); -- Decimal fixed subtraction.
   end Subtract;

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

end CXF2A01_0;


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


with FXF2A00;
package CXF2A01_0.CXF2A01_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_Optr_Table_Cancel : Micro_Ops   := ( Micro_Add, Micro_Sub,
                                              Micro_Add, Micro_Sub,
                                              Micro_Add, Micro_Sub );

   Micro_Optr_Table_Cumul  : Micro_Ops   := ( others => Micro_Add );

   Micro_Opnd_Table_Cancel : Micro_Opnds := ( 0.001025000235111997,
                                              0.000000000000000003,
                                              0.724902903219925400,
                                              0.000459228020000011,
                                              0.049832104921096533 );

   Micro_Opnd_Table_Cumul  : Micro_Opnds := ( 0.000002309540000000,
                                              0.000000278060000000,
                                              0.000000000000070000,
                                              0.000010003000000000,
                                              0.000000023090000000 );

   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 Money_Ops   is array (FXF2A00.Optr_Range) of Money_Optr_Ptr;
   type Money_Opnds is array (FXF2A00.Opnd_Range) of Money;

   Money_Optr_Table_Cancel : Money_Ops   := ( Money_Add, Money_Add,
                                              Money_Sub, Money_Add,
                                              Money_Sub, Money_Sub );

   Money_Optr_Table_Cumul  : Money_Ops   := ( others => Money_Sub );

   Money_Opnd_Table_Cancel  : Money_Opnds := (       127.10,
                                                    5600.44,
                                                       0.05,
                                                  189662.78,
                                               226900402.99  );

   Money_Opnd_Table_Cumul   : Money_Opnds := (        17.99,
                                                     500.41,
                                                      92.78,
                                                       0.38,
                                                    2942.99  );

   function Test_Money_Ops is new FXF2A00.Operations_Loop
     (Decimal_Fixed  => Money,
      Operator_Ptr   => Money_Optr_Ptr,
      Operator_Table => Money_Ops,
      Operand_Table  => Money_Opnds);

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

   type Cash_Ops   is array (FXF2A00.Optr_Range) of Cash_Optr_Ptr;
   type Cash_Opnds is array (FXF2A00.Opnd_Range) of Cash;

   Cash_Optr_Table_Cancel : Cash_Ops   := ( Cash_Add, Cash_Add,
                                            Cash_Sub, Cash_Add,
                                            Cash_Sub, Cash_Sub );

   Cash_Optr_Table_Cumul  : Cash_Ops   := ( others => Cash_Add );

   Cash_Opnd_Table_Cancel : Cash_Opnds := (       127.10,
                                                 5600.44,
                                                    0.05,
                                               189662.78,
                                            226900402.99  );

   Cash_Opnd_Table_Cumul  : Cash_Opnds := (         3.33,
                                               100056.14,
                                                   22.87,
                                                 3901.55,
                                                  111.21  );

   function Test_Cash_Ops is new FXF2A00.Operations_Loop
     (Decimal_Fixed  => Cash,
      Operator_Ptr   => Cash_Optr_Ptr,
      Operator_Table => Cash_Ops,
      Operand_Table  => Cash_Opnds);

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

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

   Broad_Optr_Table_Cancel : Broad_Ops   := ( Broad_Sub, Broad_Add,
                                              Broad_Add, Broad_Sub,
                                              Broad_Sub, Broad_Add );

   Broad_Optr_Table_Cumul  : Broad_Ops   := ( others => Broad_Sub );

   Broad_Opnd_Table_Cancel : Broad_Opnds := (         1.000009092,
                                              732919479.445022293,
                                                  89662.787000006,
                                                    660.101010133,
                                                1121127.999905594  );

   Broad_Opnd_Table_Cumul  : Broad_Opnds := (        12.000450223,
                                                    479.430320780,
                                                      0.003492096,
                                                      8.112888400,
                                                   1002.994937800  );

   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 CXF2A01_0.CXF2A01_1;


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


with CXF2A01_0.CXF2A01_1;

with Report;
procedure CXF2A01 is
   package Data renames CXF2A01_0.CXF2A01_1;

   use type CXF2A01_0.Micro;
   use type CXF2A01_0.Money;
   use type CXF2A01_0.Cash;
   use type CXF2A01_0.Broad;

   Micro_Cancel_Expected : constant CXF2A01_0.Micro := 0.0;
   Money_Cancel_Expected : constant CXF2A01_0.Money := 0.0;
   Cash_Cancel_Expected  : constant CXF2A01_0.Cash  := 0.0;
   Broad_Cancel_Expected : constant CXF2A01_0.Broad := 0.0;

   Micro_Cumul_Expected  : constant CXF2A01_0.Micro :=  0.075682140420000000;
   Money_Cumul_Expected  : constant CXF2A01_0.Money := -21327300.00;
   Cash_Cumul_Expected   : constant CXF2A01_0.Cash  :=  624570600.00;
   Broad_Cumul_Expected  : constant CXF2A01_0.Broad := -9015252.535794000;

   Micro_Actual   : CXF2A01_0.Micro;
   Money_Actual   : CXF2A01_0.Money;
   Cash_Actual    : CXF2A01_0.Cash;
   Broad_Actual   : CXF2A01_0.Broad;
begin

   Report.Test ("CXF2A01", "Check decimal addition and subtraction");


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


   Micro_Actual := Data.Test_Micro_Ops (0.0,
                                        Data.Micro_Optr_Table_Cancel,
                                        Data.Micro_Opnd_Table_Cancel);

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

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


   Micro_Actual := Data.Test_Micro_Ops (0.0,
                                        Data.Micro_Optr_Table_Cumul,
                                        Data.Micro_Opnd_Table_Cumul);

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


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


   Money_Actual := Data.Test_Money_Ops (0.0,
                                        Data.Money_Optr_Table_Cancel,
                                        Data.Money_Opnd_Table_Cancel);

   if Money_Actual /= Money_Cancel_Expected then
      Report.Failed ("Wrong cancellation result for type Money");
   end if;

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


   Money_Actual := Data.Test_Money_Ops (0.0,
                                        Data.Money_Optr_Table_Cumul,
                                        Data.Money_Opnd_Table_Cumul);

   if Money_Actual /= Money_Cumul_Expected then
      Report.Failed ("Wrong cumulation result for type Money");
   end if;


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


   Cash_Actual := Data.Test_Cash_Ops (0.0,
                                      Data.Cash_Optr_Table_Cancel,
                                      Data.Cash_Opnd_Table_Cancel);

   if Cash_Actual /= Cash_Cancel_Expected then
      Report.Failed ("Wrong cancellation result for type Cash");
   end if;


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


   Cash_Actual := Data.Test_Cash_Ops (0.0,
                                      Data.Cash_Optr_Table_Cumul,
                                      Data.Cash_Opnd_Table_Cumul);

   if Cash_Actual /= Cash_Cumul_Expected then
      Report.Failed ("Wrong cumulation result for type Cash");
   end if;


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


   Broad_Actual := Data.Test_Broad_Ops (0.0,
                                        Data.Broad_Optr_Table_Cancel,
                                        Data.Broad_Opnd_Table_Cancel);

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


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


   Broad_Actual := Data.Test_Broad_Ops (0.0,
                                        Data.Broad_Optr_Table_Cumul,
                                        Data.Broad_Opnd_Table_Cumul);

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


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


   Report.Result;

end CXF2A01;