1 |
294 |
jeremybenn |
-- CXF2003.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 two operands are of different decimal
|
30 |
|
|
-- fixed point types.
|
31 |
|
|
--
|
32 |
|
|
-- Check that if the mathematical result is between multiples of the
|
33 |
|
|
-- small of the result type, the result is truncated toward zero.
|
34 |
|
|
-- Check that if the attribute 'Round is applied to the mathematical
|
35 |
|
|
-- result, however, the result is rounded to the nearest multiple of
|
36 |
|
|
-- the small (away from zero if the result is midway between two
|
37 |
|
|
-- multiples of the small).
|
38 |
|
|
--
|
39 |
|
|
-- TEST DESCRIPTION:
|
40 |
|
|
-- Two decimal fixed point types A and B are declared, one with a
|
41 |
|
|
-- Machine_Radix value of 2, and one with a value of 10. A third decimal
|
42 |
|
|
-- fixed point type C is declared with digits and delta values different
|
43 |
|
|
-- from those of A and B. For type A (and B), checks are performed
|
44 |
|
|
-- on the following operations, where one operand type is C, and the
|
45 |
|
|
-- other operand type and the result type is A (or B):
|
46 |
|
|
--
|
47 |
|
|
-- - Multiplication.
|
48 |
|
|
-- - Multiplication, where the attribute 'Round is applied to the
|
49 |
|
|
-- result.
|
50 |
|
|
-- - Division.
|
51 |
|
|
-- - Division, where the attribute 'Round is applied to the result.
|
52 |
|
|
--
|
53 |
|
|
-- Each operation is performed within a loop, where one operand is
|
54 |
|
|
-- always the same variable. After the loop completes, the cumulative
|
55 |
|
|
-- total contained in this variable is compared with the expected
|
56 |
|
|
-- result.
|
57 |
|
|
--
|
58 |
|
|
-- APPLICABILITY CRITERIA:
|
59 |
|
|
-- This test is only applicable for a compiler attempting validation
|
60 |
|
|
-- for the Information Systems Annex.
|
61 |
|
|
--
|
62 |
|
|
--
|
63 |
|
|
-- CHANGE HISTORY:
|
64 |
|
|
-- 22 Mar 96 SAIC Prerelease version for ACVC 2.1.
|
65 |
|
|
--
|
66 |
|
|
--!
|
67 |
|
|
|
68 |
|
|
generic
|
69 |
|
|
type Decimal_Fixed_1 is delta <> digits <>;
|
70 |
|
|
type Decimal_Fixed_2 is delta <> digits <>;
|
71 |
|
|
package CXF2003_0 is
|
72 |
|
|
|
73 |
|
|
procedure Multiply_And_Truncate (Balance : in out Decimal_Fixed_1;
|
74 |
|
|
Factor : in Decimal_Fixed_2);
|
75 |
|
|
|
76 |
|
|
procedure Divide_And_Truncate (Balance : in out Decimal_Fixed_1;
|
77 |
|
|
Divisor : in Decimal_Fixed_2);
|
78 |
|
|
|
79 |
|
|
procedure Multiply_And_Round (Balance : in out Decimal_Fixed_1;
|
80 |
|
|
Factor : in Decimal_Fixed_2);
|
81 |
|
|
|
82 |
|
|
procedure Divide_And_Round (Balance : in out Decimal_Fixed_1;
|
83 |
|
|
Divisor : in Decimal_Fixed_2);
|
84 |
|
|
|
85 |
|
|
end CXF2003_0;
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
--==================================================================--
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
package body CXF2003_0 is
|
92 |
|
|
|
93 |
|
|
procedure Multiply_And_Truncate (Balance : in out Decimal_Fixed_1;
|
94 |
|
|
Factor : in Decimal_Fixed_2) is
|
95 |
|
|
Interest : Decimal_Fixed_1;
|
96 |
|
|
begin
|
97 |
|
|
Interest := Factor * Balance; -- Fixed-fixed multiplication.
|
98 |
|
|
Balance := Balance + Interest;
|
99 |
|
|
end Multiply_And_Truncate;
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
procedure Divide_And_Truncate (Balance : in out Decimal_Fixed_1;
|
103 |
|
|
Divisor : in Decimal_Fixed_2) is
|
104 |
|
|
Interest : Decimal_Fixed_1;
|
105 |
|
|
begin
|
106 |
|
|
Interest := Balance / Divisor; -- Fixed-fixed division.
|
107 |
|
|
Balance := Balance + Interest;
|
108 |
|
|
end Divide_And_Truncate;
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
procedure Multiply_And_Round (Balance : in out Decimal_Fixed_1;
|
112 |
|
|
Factor : in Decimal_Fixed_2) is
|
113 |
|
|
Interest : Decimal_Fixed_1;
|
114 |
|
|
begin
|
115 |
|
|
-- Fixed-fixed multiplication.
|
116 |
|
|
Interest := Decimal_Fixed_1'Round ( Factor * Balance );
|
117 |
|
|
Balance := Balance + Interest;
|
118 |
|
|
end Multiply_And_Round;
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
procedure Divide_And_Round (Balance : in out Decimal_Fixed_1;
|
122 |
|
|
Divisor : in Decimal_Fixed_2) is
|
123 |
|
|
Interest : Decimal_Fixed_1;
|
124 |
|
|
begin
|
125 |
|
|
-- Fixed-fixed division.
|
126 |
|
|
Interest := Decimal_Fixed_1'Round ( Balance / Divisor );
|
127 |
|
|
Balance := Balance + Interest;
|
128 |
|
|
end Divide_And_Round;
|
129 |
|
|
|
130 |
|
|
end CXF2003_0;
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
--==================================================================--
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
package CXF2003_1 is
|
137 |
|
|
|
138 |
|
|
type Money_Radix2 is delta 0.01 digits 11; -- range -999,999,999.99 ..
|
139 |
|
|
for Money_Radix2'Machine_Radix use 2; -- +999,999,999.99
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
type Money_Radix10 is delta 0.01 digits 11; -- range -999,999,999.99 ..
|
143 |
|
|
for Money_Radix10'Machine_Radix use 10; -- +999,999,999.99
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
type Interest_Rate is delta 0.00001 digits 9; -- range -9999.99999 ..
|
147 |
|
|
-- +9999.99999
|
148 |
|
|
|
149 |
|
|
end CXF2003_1;
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
--==================================================================--
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
with CXF2003_0;
|
156 |
|
|
with CXF2003_1;
|
157 |
|
|
|
158 |
|
|
with Report;
|
159 |
|
|
procedure CXF2003 is
|
160 |
|
|
|
161 |
|
|
Loop_Count : constant := 1825;
|
162 |
|
|
type Loop_Range is range 1 .. Loop_Count;
|
163 |
|
|
|
164 |
|
|
begin
|
165 |
|
|
|
166 |
|
|
Report.Test ("CXF2003", "Check decimal multiplication and division, and " &
|
167 |
|
|
"'Round, where the operand types are different");
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
---=---=---=---=---=---=---=---=---=---=---
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
RADIX_2_SUBTESTS:
|
174 |
|
|
declare
|
175 |
|
|
package Radix_2 is new CXF2003_0 (CXF2003_1.Money_Radix2,
|
176 |
|
|
CXF2003_1.Interest_Rate);
|
177 |
|
|
use type CXF2003_1.Money_Radix2;
|
178 |
|
|
use type CXF2003_1.Interest_Rate;
|
179 |
|
|
begin
|
180 |
|
|
|
181 |
|
|
RADIX_2_MULTIPLICATION:
|
182 |
|
|
declare
|
183 |
|
|
Rate : CXF2003_1.Interest_Rate := 0.198;
|
184 |
|
|
Period : Integer := 365;
|
185 |
|
|
Factor : CXF2003_1.Interest_Rate := Rate / Period;
|
186 |
|
|
|
187 |
|
|
Initial : constant CXF2003_1.Money_Radix2 := 1_000.00;
|
188 |
|
|
Trunc_Expected : constant CXF2003_1.Money_Radix2 := 2_662.94;
|
189 |
|
|
Round_Expected : constant CXF2003_1.Money_Radix2 := 2_678.34;
|
190 |
|
|
|
191 |
|
|
Balance : CXF2003_1.Money_Radix2;
|
192 |
|
|
begin
|
193 |
|
|
---=---=---=---=---=---=---
|
194 |
|
|
|
195 |
|
|
Balance := Initial;
|
196 |
|
|
|
197 |
|
|
for I in Loop_Range loop
|
198 |
|
|
Radix_2.Multiply_And_Truncate (Balance, Factor);
|
199 |
|
|
end loop;
|
200 |
|
|
|
201 |
|
|
if Balance /= Trunc_Expected then
|
202 |
|
|
Report.Failed ("Wrong result: Radix 2 multiply and truncate");
|
203 |
|
|
end if;
|
204 |
|
|
|
205 |
|
|
---=---=---=---=---=---=---
|
206 |
|
|
|
207 |
|
|
Balance := Initial;
|
208 |
|
|
|
209 |
|
|
for I in Loop_Range loop
|
210 |
|
|
Radix_2.Multiply_And_Round (Balance, Factor);
|
211 |
|
|
end loop;
|
212 |
|
|
|
213 |
|
|
if Balance /= Round_Expected then
|
214 |
|
|
Report.Failed ("Wrong result: Radix 2 multiply and round");
|
215 |
|
|
end if;
|
216 |
|
|
|
217 |
|
|
---=---=---=---=---=---=---
|
218 |
|
|
end RADIX_2_MULTIPLICATION;
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
RADIX_2_DIVISION:
|
222 |
|
|
declare
|
223 |
|
|
Rate : CXF2003_1.Interest_Rate := 0.129;
|
224 |
|
|
Period : Integer := 365;
|
225 |
|
|
Factor : CXF2003_1.Interest_Rate := Rate / Period;
|
226 |
|
|
Divisor : CXF2003_1.Interest_Rate := 1.0 / Factor;
|
227 |
|
|
|
228 |
|
|
Initial : constant CXF2003_1.Money_Radix2 := 14_626.52;
|
229 |
|
|
Trunc_Expected : constant CXF2003_1.Money_Radix2 := 27_688.26;
|
230 |
|
|
Round_Expected : constant CXF2003_1.Money_Radix2 := 27_701.12;
|
231 |
|
|
|
232 |
|
|
Balance : CXF2003_1.Money_Radix2;
|
233 |
|
|
begin
|
234 |
|
|
---=---=---=---=---=---=---
|
235 |
|
|
|
236 |
|
|
Balance := Initial;
|
237 |
|
|
|
238 |
|
|
for I in Loop_Range loop
|
239 |
|
|
Radix_2.Divide_And_Truncate (Balance, Divisor);
|
240 |
|
|
end loop;
|
241 |
|
|
|
242 |
|
|
if Balance /= Trunc_Expected then
|
243 |
|
|
Report.Failed ("Wrong result: Radix 2 divide and truncate");
|
244 |
|
|
end if;
|
245 |
|
|
|
246 |
|
|
---=---=---=---=---=---=---
|
247 |
|
|
|
248 |
|
|
Balance := Initial;
|
249 |
|
|
|
250 |
|
|
for I in Loop_Range loop
|
251 |
|
|
Radix_2.Divide_And_Round (Balance, Divisor);
|
252 |
|
|
end loop;
|
253 |
|
|
|
254 |
|
|
if Balance /= Round_Expected then
|
255 |
|
|
Report.Failed ("Wrong result: Radix 2 divide and round");
|
256 |
|
|
end if;
|
257 |
|
|
|
258 |
|
|
---=---=---=---=---=---=---
|
259 |
|
|
end RADIX_2_DIVISION;
|
260 |
|
|
|
261 |
|
|
end RADIX_2_SUBTESTS;
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
---=---=---=---=---=---=---=---=---=---=---
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
RADIX_10_SUBTESTS:
|
268 |
|
|
declare
|
269 |
|
|
package Radix_10 is new CXF2003_0 (CXF2003_1.Money_Radix10,
|
270 |
|
|
CXF2003_1.Interest_Rate);
|
271 |
|
|
use type CXF2003_1.Money_Radix10;
|
272 |
|
|
use type CXF2003_1.Interest_Rate;
|
273 |
|
|
begin
|
274 |
|
|
|
275 |
|
|
RADIX_10_MULTIPLICATION:
|
276 |
|
|
declare
|
277 |
|
|
Rate : CXF2003_1.Interest_Rate := 0.063;
|
278 |
|
|
Period : Integer := 365;
|
279 |
|
|
Factor : CXF2003_1.Interest_Rate := Rate / Period;
|
280 |
|
|
|
281 |
|
|
Initial : constant CXF2003_1.Money_Radix10 := 314_036.10;
|
282 |
|
|
Trunc_Expected : constant CXF2003_1.Money_Radix10 := 428_249.48;
|
283 |
|
|
Round_Expected : constant CXF2003_1.Money_Radix10 := 428_260.52;
|
284 |
|
|
|
285 |
|
|
Balance : CXF2003_1.Money_Radix10;
|
286 |
|
|
begin
|
287 |
|
|
---=---=---=---=---=---=---
|
288 |
|
|
|
289 |
|
|
Balance := Initial;
|
290 |
|
|
|
291 |
|
|
for I in Loop_Range loop
|
292 |
|
|
Radix_10.Multiply_And_Truncate (Balance, Factor);
|
293 |
|
|
end loop;
|
294 |
|
|
|
295 |
|
|
if Balance /= Trunc_Expected then
|
296 |
|
|
Report.Failed ("Wrong result: Radix 10 multiply and truncate");
|
297 |
|
|
end if;
|
298 |
|
|
|
299 |
|
|
---=---=---=---=---=---=---
|
300 |
|
|
|
301 |
|
|
Balance := Initial;
|
302 |
|
|
|
303 |
|
|
for I in Loop_Range loop
|
304 |
|
|
Radix_10.Multiply_And_Round (Balance, Factor);
|
305 |
|
|
end loop;
|
306 |
|
|
|
307 |
|
|
if Balance /= Round_Expected then
|
308 |
|
|
Report.Failed ("Wrong result: Radix 10 multiply and round");
|
309 |
|
|
end if;
|
310 |
|
|
|
311 |
|
|
---=---=---=---=---=---=---
|
312 |
|
|
end RADIX_10_MULTIPLICATION;
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
RADIX_10_DIVISION:
|
316 |
|
|
declare
|
317 |
|
|
Rate : CXF2003_1.Interest_Rate := 0.273;
|
318 |
|
|
Period : Integer := 365;
|
319 |
|
|
Factor : CXF2003_1.Interest_Rate := Rate / Period;
|
320 |
|
|
Divisor : CXF2003_1.Interest_Rate := 1.0 / Factor;
|
321 |
|
|
|
322 |
|
|
Initial : constant CXF2003_1.Money_Radix10 := 25.72;
|
323 |
|
|
Trunc_Expected : constant CXF2003_1.Money_Radix10 := 79.05;
|
324 |
|
|
Round_Expected : constant CXF2003_1.Money_Radix10 := 97.46;
|
325 |
|
|
|
326 |
|
|
Balance : CXF2003_1.Money_Radix10;
|
327 |
|
|
begin
|
328 |
|
|
---=---=---=---=---=---=---
|
329 |
|
|
|
330 |
|
|
Balance := Initial;
|
331 |
|
|
|
332 |
|
|
for I in Loop_Range loop
|
333 |
|
|
Radix_10.Divide_And_Truncate (Balance, Divisor);
|
334 |
|
|
end loop;
|
335 |
|
|
|
336 |
|
|
if Balance /= Trunc_Expected then
|
337 |
|
|
Report.Failed ("Wrong result: Radix 10 divide and truncate");
|
338 |
|
|
end if;
|
339 |
|
|
|
340 |
|
|
---=---=---=---=---=---=---
|
341 |
|
|
|
342 |
|
|
Balance := Initial;
|
343 |
|
|
|
344 |
|
|
for I in Loop_Range loop
|
345 |
|
|
Radix_10.Divide_And_Round (Balance, Divisor);
|
346 |
|
|
end loop;
|
347 |
|
|
|
348 |
|
|
if Balance /= Round_Expected then
|
349 |
|
|
Report.Failed ("Wrong result: Radix 10 divide and round");
|
350 |
|
|
end if;
|
351 |
|
|
|
352 |
|
|
---=---=---=---=---=---=---
|
353 |
|
|
end RADIX_10_DIVISION;
|
354 |
|
|
|
355 |
|
|
end RADIX_10_SUBTESTS;
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
---=---=---=---=---=---=---=---=---=---=---
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
Report.Result;
|
362 |
|
|
|
363 |
|
|
end CXF2003;
|