OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxf/] [cxf2002.a] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
-- CXF2002.A
2
--
3
--                             Grant of Unlimited Rights
4
--
5
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7
--     unlimited rights in the software and documentation contained herein.
8
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making
9
--     this public release, the Government intends to confer upon all
10
--     recipients unlimited rights  equal to those held by the Government.
11
--     These rights include rights to use, duplicate, release or disclose the
12
--     released technical data and computer software in whole or in part, in
13
--     any manner and for any purpose whatsoever, and to have or permit others
14
--     to do so.
15
--
16
--                                    DISCLAIMER
17
--
18
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23
--     PARTICULAR PURPOSE OF SAID MATERIAL.
24
--*
25
--
26
-- OBJECTIVE:
27
--      Check that the multiplying operators for a decimal fixed point type
28
--      return values that are integral multiples of the small of the type.
29
--      Check the case where the operand and result types are the same.
30
--
31
--      Check that if the mathematical result is between multiples of the
32
--      small of the result type, the result is truncated toward zero.
33
--      Check that if the attribute 'Round is applied to the mathematical
34
--      result, however, the result is rounded to the nearest multiple of
35
--      the small (away from zero if the result is midway between two
36
--      multiples of the small).
37
--
38
-- TEST DESCRIPTION:
39
--      Two decimal fixed point types are declared, one with a Machine_Radix
40
--      value of 2, and one with a value of 10. For each type, checks are
41
--      performed on the following operations, where the operand and result
42
--      types are the same:
43
--
44
--         - Multiplication.
45
--         - Multiplication, where the attribute 'Round is applied to the
46
--           result.
47
--         - Division.
48
--         - Division, where the attribute 'Round is applied to the result.
49
--
50
--      Each operation is performed within a loop, where one operand is
51
--      always the same variable. After the loop completes, the cumulative
52
--      total contained in this variable is compared with the expected
53
--      result.
54
--
55
-- APPLICABILITY CRITERIA:
56
--      This test is only applicable for a compiler attempting validation
57
--      for the Information Systems Annex.
58
--
59
--
60
-- CHANGE HISTORY:
61
--      27 Mar 96   SAIC    Prerelease version for ACVC 2.1.
62
--
63
--!
64
 
65
generic
66
   type Decimal_Fixed is delta <> digits <>;
67
package CXF2002_0 is
68
 
69
   procedure Multiply_And_Truncate (Balance : in out Decimal_Fixed;
70
                                    Factor  : in     Decimal_Fixed);
71
 
72
   procedure Divide_And_Truncate   (Balance : in out Decimal_Fixed;
73
                                    Divisor : in     Decimal_Fixed);
74
 
75
   procedure Multiply_And_Round    (Balance : in out Decimal_Fixed;
76
                                    Factor  : in     Decimal_Fixed);
77
 
78
   procedure Divide_And_Round      (Balance : in out Decimal_Fixed;
79
                                    Divisor : in     Decimal_Fixed);
80
 
81
end CXF2002_0;
82
 
83
 
84
     --==================================================================--
85
 
86
 
87
package body CXF2002_0 is
88
 
89
   procedure Multiply_And_Truncate (Balance : in out Decimal_Fixed;
90
                                    Factor  : in     Decimal_Fixed) is
91
      Interest : Decimal_Fixed;
92
   begin
93
      Interest := Factor * Balance;      -- Fixed-fixed multiplication.
94
      Balance  := Balance + Interest;
95
   end Multiply_And_Truncate;
96
 
97
 
98
   procedure Divide_And_Truncate (Balance : in out Decimal_Fixed;
99
                                  Divisor : in     Decimal_Fixed) is
100
      Interest : Decimal_Fixed;
101
   begin
102
      Interest := Balance / Divisor;     -- Fixed-fixed division.
103
      Balance  := Balance + Interest;
104
   end Divide_And_Truncate;
105
 
106
 
107
   procedure Multiply_And_Round (Balance : in out Decimal_Fixed;
108
                                 Factor  : in     Decimal_Fixed) is
109
      Interest : Decimal_Fixed;
110
   begin
111
                                         -- Fixed-fixed multiplication.
112
      Interest := Decimal_Fixed'Round ( Factor * Balance );
113
      Balance  := Balance + Interest;
114
   end Multiply_And_Round;
115
 
116
 
117
   procedure Divide_And_Round (Balance : in out Decimal_Fixed;
118
                               Divisor : in     Decimal_Fixed) is
119
      Interest : Decimal_Fixed;
120
   begin
121
                                         -- Fixed-fixed division.
122
      Interest := Decimal_Fixed'Round ( Balance / Divisor );
123
      Balance  := Balance + Interest;
124
   end Divide_And_Round;
125
 
126
end CXF2002_0;
127
 
128
 
129
     --==================================================================--
130
 
131
 
132
package CXF2002_1 is
133
 
134
   type Money_Radix2 is delta 0.01 digits 11;  -- range -999,999,999.99 ..
135
   for Money_Radix2'Machine_Radix use 2;       --       +999,999,999.99
136
 
137
 
138
   type Money_Radix10 is delta 0.01 digits 11; -- range -999,999,999.99 ..
139
   for Money_Radix10'Machine_Radix use 10;     --       +999,999,999.99
140
 
141
end CXF2002_1;
142
 
143
 
144
     --==================================================================--
145
 
146
 
147
with CXF2002_0;
148
with CXF2002_1;
149
 
150
with Report;
151
procedure CXF2002 is
152
 
153
   Loop_Count : constant := 300;
154
   type Loop_Range is range 1 .. Loop_Count;
155
 
156
begin
157
 
158
   Report.Test ("CXF2002", "Check decimal multiplication and division, and " &
159
                           "'Round, where the operand and result types are " &
160
                           "the same");
161
 
162
 
163
               ---=---=---=---=---=---=---=---=---=---=---
164
 
165
 
166
   RADIX_2_SUBTESTS:
167
   declare
168
      package Radix_2 is new CXF2002_0 (CXF2002_1.Money_Radix2);
169
      use type CXF2002_1.Money_Radix2;
170
   begin
171
 
172
      RADIX_2_MULTIPLICATION:
173
      declare
174
         Rate           : constant CXF2002_1.Money_Radix2 := 0.12;
175
         Period         : constant Integer                := 12;
176
         Factor         :          CXF2002_1.Money_Radix2 := Rate / Period;
177
 
178
         Initial        : constant CXF2002_1.Money_Radix2 :=   100_000.00;
179
         Trunc_Expected : constant CXF2002_1.Money_Radix2 := 1_978_837.50;
180
         Round_Expected : constant CXF2002_1.Money_Radix2 := 1_978_846.75;
181
 
182
         Balance        : CXF2002_1.Money_Radix2;
183
      begin
184
                       ---=---=---=---=---=---=---
185
 
186
         Balance := Initial;
187
 
188
         for I in Loop_Range loop
189
            Radix_2.Multiply_And_Truncate (Balance, Factor);
190
         end loop;
191
 
192
         if Balance /= Trunc_Expected then
193
            Report.Failed ("Wrong result: Radix 2 multiply and truncate");
194
         end if;
195
 
196
                       ---=---=---=---=---=---=---
197
 
198
         Balance := Initial;
199
 
200
         for I in Loop_Range loop
201
            Radix_2.Multiply_And_Round (Balance, Factor);
202
         end loop;
203
 
204
         if Balance /= Round_Expected then
205
            Report.Failed ("Wrong result: Radix 2 multiply and round");
206
         end if;
207
 
208
                       ---=---=---=---=---=---=---
209
      end RADIX_2_MULTIPLICATION;
210
 
211
 
212
      RADIX_2_DIVISION:
213
      declare
214
         Rate           : constant CXF2002_1.Money_Radix2 := 0.25;
215
         Period         : constant Integer                := 12;
216
         Factor         :          CXF2002_1.Money_Radix2 := Rate / Period;
217
         Divisor        : constant CXF2002_1.Money_Radix2 := 1.0 / Factor;
218
 
219
         Initial        : constant CXF2002_1.Money_Radix2 :=     5_500.36;
220
         Trunc_Expected : constant CXF2002_1.Money_Radix2 := 2_091_332.87;
221
         Round_Expected : constant CXF2002_1.Money_Radix2 := 2_091_436.88;
222
 
223
         Balance        : CXF2002_1.Money_Radix2;
224
      begin
225
                       ---=---=---=---=---=---=---
226
 
227
         Balance := Initial;
228
 
229
         for I in Loop_Range loop
230
            Radix_2.Divide_And_Truncate (Balance, Divisor);
231
         end loop;
232
 
233
         if Balance /= Trunc_Expected then
234
            Report.Failed ("Wrong result: Radix 2 divide and truncate");
235
         end if;
236
 
237
                       ---=---=---=---=---=---=---
238
 
239
         Balance := Initial;
240
 
241
         for I in Loop_Range loop
242
            Radix_2.Divide_And_Round (Balance, Divisor);
243
         end loop;
244
 
245
         if Balance /= Round_Expected then
246
            Report.Failed ("Wrong result: Radix 2 divide and round");
247
         end if;
248
 
249
                       ---=---=---=---=---=---=---
250
      end RADIX_2_DIVISION;
251
 
252
   end RADIX_2_SUBTESTS;
253
 
254
 
255
               ---=---=---=---=---=---=---=---=---=---=---
256
 
257
 
258
   RADIX_10_SUBTESTS:
259
   declare
260
      package Radix_10 is new CXF2002_0 (CXF2002_1.Money_Radix10);
261
      use type CXF2002_1.Money_Radix10;
262
   begin
263
 
264
      RADIX_10_MULTIPLICATION:
265
      declare
266
         Rate           : constant CXF2002_1.Money_Radix10 := 0.37;
267
         Period         : constant Integer                 := 12;
268
         Factor         :          CXF2002_1.Money_Radix10 := Rate / Period;
269
 
270
         Initial        : constant CXF2002_1.Money_Radix10 :=       459.33;
271
         Trunc_Expected : constant CXF2002_1.Money_Radix10 := 3_259_305.54;
272
         Round_Expected : constant CXF2002_1.Money_Radix10 := 3_260_544.11;
273
 
274
         Balance        : CXF2002_1.Money_Radix10;
275
      begin
276
                       ---=---=---=---=---=---=---
277
 
278
         Balance := Initial;
279
 
280
         for I in Loop_Range loop
281
            Radix_10.Multiply_And_Truncate (Balance, Factor);
282
         end loop;
283
 
284
         if Balance /= Trunc_Expected then
285
            Report.Failed ("Wrong result: Radix 10 multiply and truncate");
286
         end if;
287
 
288
                       ---=---=---=---=---=---=---
289
 
290
         Balance := Initial;
291
 
292
         for I in Loop_Range loop
293
            Radix_10.Multiply_And_Round (Balance, Factor);
294
         end loop;
295
 
296
         if Balance /= Round_Expected then
297
            Report.Failed ("Wrong result: Radix 10 multiply and round");
298
         end if;
299
 
300
                       ---=---=---=---=---=---=---
301
      end RADIX_10_MULTIPLICATION;
302
 
303
 
304
      RADIX_10_DIVISION:
305
      declare
306
         Rate           : constant CXF2002_1.Money_Radix10 := 0.15;
307
         Period         : constant Integer                 := 12;
308
         Factor         :          CXF2002_1.Money_Radix10 := Rate / Period;
309
         Divisor        : constant CXF2002_1.Money_Radix10 := 1.0 / Factor;
310
 
311
         Initial        : constant CXF2002_1.Money_Radix10 :=    29_842.08;
312
         Trunc_Expected : constant CXF2002_1.Money_Radix10 :=   590_519.47;
313
         Round_Expected : constant CXF2002_1.Money_Radix10 :=   590_528.98;
314
 
315
         Balance        : CXF2002_1.Money_Radix10;
316
      begin
317
                       ---=---=---=---=---=---=---
318
 
319
         Balance := Initial;
320
 
321
         for I in Loop_Range loop
322
            Radix_10.Divide_And_Truncate (Balance, Divisor);
323
         end loop;
324
 
325
         if Balance /= Trunc_Expected then
326
            Report.Failed ("Wrong result: Radix 10 divide and truncate");
327
         end if;
328
 
329
                       ---=---=---=---=---=---=---
330
 
331
         Balance := Initial;
332
 
333
         for I in Loop_Range loop
334
            Radix_10.Divide_And_Round (Balance, Divisor);
335
         end loop;
336
 
337
         if Balance /= Round_Expected then
338
            Report.Failed ("Wrong result: Radix 10 divide and round");
339
         end if;
340
 
341
                       ---=---=---=---=---=---=---
342
      end RADIX_10_DIVISION;
343
 
344
   end RADIX_10_SUBTESTS;
345
 
346
 
347
               ---=---=---=---=---=---=---=---=---=---=---
348
 
349
 
350
   Report.Result;
351
 
352
end CXF2002;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.