1 |
294 |
jeremybenn |
-- CXF2004.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 one operand is of an ordinary fixed point type.
|
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 A and B are declared, one with a
|
40 |
|
|
-- Machine_Radix value of 2, and one with a value of 10. An ordinary
|
41 |
|
|
-- fixed point type C is declared with a delta value different from
|
42 |
|
|
-- those of A and B (although still a power of 10). For type A (and B),
|
43 |
|
|
-- checks are performed on the following operations, where one operand
|
44 |
|
|
-- type is C, and the other operand type and the result type is A (or B):
|
45 |
|
|
--
|
46 |
|
|
-- - Multiplication.
|
47 |
|
|
-- - Multiplication, where the attribute 'Round is applied to the
|
48 |
|
|
-- result.
|
49 |
|
|
-- - Division.
|
50 |
|
|
-- - Division, where the attribute 'Round is applied to the result.
|
51 |
|
|
--
|
52 |
|
|
-- Each operation is performed within a loop, where one operand is
|
53 |
|
|
-- always the same variable. After the loop completes, the cumulative
|
54 |
|
|
-- total contained in this variable is compared with the expected
|
55 |
|
|
-- result.
|
56 |
|
|
--
|
57 |
|
|
-- APPLICABILITY CRITERIA:
|
58 |
|
|
-- This test is only applicable for a compiler attempting validation
|
59 |
|
|
-- for the Information Systems Annex.
|
60 |
|
|
--
|
61 |
|
|
--
|
62 |
|
|
-- CHANGE HISTORY:
|
63 |
|
|
-- 22 Mar 96 SAIC Prerelease version for ACVC 2.1.
|
64 |
|
|
-- 11 Aug 96 SAIC ACVC 2.1: In RADIX_2_MULTIPLICATION, corrected
|
65 |
|
|
-- value of Rate. Corrected associated commentary.
|
66 |
|
|
--
|
67 |
|
|
--!
|
68 |
|
|
|
69 |
|
|
generic
|
70 |
|
|
type Decimal_Fixed is delta <> digits <>;
|
71 |
|
|
type Ordinary_Fixed is delta <>;
|
72 |
|
|
package CXF2004_0 is
|
73 |
|
|
|
74 |
|
|
procedure Multiply_And_Truncate (Balance : in out Decimal_Fixed;
|
75 |
|
|
Factor : in Ordinary_Fixed);
|
76 |
|
|
|
77 |
|
|
procedure Divide_And_Truncate (Balance : in out Decimal_Fixed;
|
78 |
|
|
Divisor : in Ordinary_Fixed);
|
79 |
|
|
|
80 |
|
|
procedure Multiply_And_Round (Balance : in out Decimal_Fixed;
|
81 |
|
|
Factor : in Ordinary_Fixed);
|
82 |
|
|
|
83 |
|
|
procedure Divide_And_Round (Balance : in out Decimal_Fixed;
|
84 |
|
|
Divisor : in Ordinary_Fixed);
|
85 |
|
|
|
86 |
|
|
end CXF2004_0;
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
--==================================================================--
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
package body CXF2004_0 is
|
93 |
|
|
|
94 |
|
|
procedure Multiply_And_Truncate (Balance : in out Decimal_Fixed;
|
95 |
|
|
Factor : in Ordinary_Fixed) is
|
96 |
|
|
Interest : Decimal_Fixed;
|
97 |
|
|
begin
|
98 |
|
|
Interest := Factor * Balance; -- Fixed-fixed multiplication.
|
99 |
|
|
Balance := Balance + Interest;
|
100 |
|
|
end Multiply_And_Truncate;
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
procedure Divide_And_Truncate (Balance : in out Decimal_Fixed;
|
104 |
|
|
Divisor : in Ordinary_Fixed) is
|
105 |
|
|
Interest : Decimal_Fixed;
|
106 |
|
|
begin
|
107 |
|
|
Interest := Balance / Divisor; -- Fixed-fixed division.
|
108 |
|
|
Balance := Balance + Interest;
|
109 |
|
|
end Divide_And_Truncate;
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
procedure Multiply_And_Round (Balance : in out Decimal_Fixed;
|
113 |
|
|
Factor : in Ordinary_Fixed) is
|
114 |
|
|
Interest : Decimal_Fixed;
|
115 |
|
|
begin
|
116 |
|
|
-- Fixed-fixed multiplication.
|
117 |
|
|
Interest := Decimal_Fixed'Round ( Factor * Balance );
|
118 |
|
|
Balance := Balance + Interest;
|
119 |
|
|
end Multiply_And_Round;
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
procedure Divide_And_Round (Balance : in out Decimal_Fixed;
|
123 |
|
|
Divisor : in Ordinary_Fixed) is
|
124 |
|
|
Interest : Decimal_Fixed;
|
125 |
|
|
begin
|
126 |
|
|
-- Fixed-fixed division.
|
127 |
|
|
Interest := Decimal_Fixed'Round ( Balance / Divisor );
|
128 |
|
|
Balance := Balance + Interest;
|
129 |
|
|
end Divide_And_Round;
|
130 |
|
|
|
131 |
|
|
end CXF2004_0;
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
--==================================================================--
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
package CXF2004_1 is
|
138 |
|
|
|
139 |
|
|
type Money_Radix2 is delta 0.01 digits 11; -- range -999,999,999.99 ..
|
140 |
|
|
for Money_Radix2'Machine_Radix use 2; -- +999,999,999.99
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
type Money_Radix10 is delta 0.01 digits 11; -- range -999,999,999.99 ..
|
144 |
|
|
for Money_Radix10'Machine_Radix use 10; -- +999,999,999.99
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
type Interest_Rate is delta 0.001 range 0.0 .. 1_000.0;
|
148 |
|
|
for Interest_Rate'Small use 0.001; -- Power of 10.
|
149 |
|
|
|
150 |
|
|
end CXF2004_1;
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
--==================================================================--
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
with CXF2004_0;
|
157 |
|
|
with CXF2004_1;
|
158 |
|
|
|
159 |
|
|
with Report;
|
160 |
|
|
procedure CXF2004 is
|
161 |
|
|
|
162 |
|
|
Loop_Count : constant := 180;
|
163 |
|
|
type Loop_Range is range 1 .. Loop_Count;
|
164 |
|
|
|
165 |
|
|
type Rounding_Scheme is ( Rounds, Truncates );
|
166 |
|
|
Machine : Rounding_Scheme;
|
167 |
|
|
|
168 |
|
|
begin
|
169 |
|
|
|
170 |
|
|
Report.Test ("CXF2004", "Check decimal multiplication and division, and " &
|
171 |
|
|
"'Round, where one operand type is ordinary fixed");
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
---=---=---=---=---=---=---=---=---=---=---
|
175 |
|
|
|
176 |
|
|
if CXF2004_1.Interest_Rate'Machine_Rounds then -- Determine machine's
|
177 |
|
|
Machine := Rounds; -- rounding scheme.
|
178 |
|
|
else
|
179 |
|
|
Machine := Truncates;
|
180 |
|
|
end if;
|
181 |
|
|
|
182 |
|
|
---=---=---=---=---=---=---=---=---=---=---
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
RADIX_2_SUBTESTS:
|
186 |
|
|
declare
|
187 |
|
|
package Radix_2 is new CXF2004_0 (CXF2004_1.Money_Radix2,
|
188 |
|
|
CXF2004_1.Interest_Rate);
|
189 |
|
|
use type CXF2004_1.Money_Radix2;
|
190 |
|
|
use type CXF2004_1.Interest_Rate;
|
191 |
|
|
begin
|
192 |
|
|
|
193 |
|
|
RADIX_2_MULTIPLICATION:
|
194 |
|
|
declare
|
195 |
|
|
Rate : constant CXF2004_1.Interest_Rate := 0.154;
|
196 |
|
|
Period : constant Integer := 12;
|
197 |
|
|
Factor : CXF2004_1.Interest_Rate := Rate / Period;
|
198 |
|
|
|
199 |
|
|
-- The exact value of Factor is:
|
200 |
|
|
--
|
201 |
|
|
-- 0.154/12 = 0.01283333...
|
202 |
|
|
--
|
203 |
|
|
-- The adjacent multiples of small are 0.012 and 0.013. Since
|
204 |
|
|
-- Factor is of an ordinary fixed point type, it may contain either
|
205 |
|
|
-- of these values. However, since "Rate / Period" is a static
|
206 |
|
|
-- expression, the value Factor contains is determined by the
|
207 |
|
|
-- value of CXF2004_1.Interest_Rate'Machine_Rounds:
|
208 |
|
|
--
|
209 |
|
|
-- If Machine_Rounds = FALSE : Factor = 0.012
|
210 |
|
|
-- If Machine_Rounds = TRUE : Factor = 0.013
|
211 |
|
|
|
212 |
|
|
Initial : constant CXF2004_1.Money_Radix2 := 1_000.00;
|
213 |
|
|
|
214 |
|
|
Trunc_Expected_MachTrnc: constant CXF2004_1.Money_Radix2 := 8_557.07;
|
215 |
|
|
Round_Expected_MachTrnc: constant CXF2004_1.Money_Radix2 := 8_560.47;
|
216 |
|
|
|
217 |
|
|
Trunc_Expected_MachRnds: constant CXF2004_1.Money_Radix2 := 10_222.65;
|
218 |
|
|
Round_Expected_MachRnds: constant CXF2004_1.Money_Radix2 := 10_225.81;
|
219 |
|
|
|
220 |
|
|
Balance : CXF2004_1.Money_Radix2;
|
221 |
|
|
begin
|
222 |
|
|
---=---=---=---=---=---=---
|
223 |
|
|
|
224 |
|
|
Balance := Initial;
|
225 |
|
|
|
226 |
|
|
for I in Loop_Range loop
|
227 |
|
|
Radix_2.Multiply_And_Truncate (Balance, Factor);
|
228 |
|
|
end loop;
|
229 |
|
|
|
230 |
|
|
case (Machine) is
|
231 |
|
|
when Rounds =>
|
232 |
|
|
if Balance /= Trunc_Expected_MachRnds then
|
233 |
|
|
Report.Failed ("Error (R): Radix 2 multiply and truncate");
|
234 |
|
|
end if;
|
235 |
|
|
when Truncates =>
|
236 |
|
|
if Balance /= Trunc_Expected_MachTrnc then
|
237 |
|
|
Report.Failed ("Error (T): Radix 2 multiply and truncate");
|
238 |
|
|
end if;
|
239 |
|
|
end case;
|
240 |
|
|
|
241 |
|
|
---=---=---=---=---=---=---
|
242 |
|
|
|
243 |
|
|
Balance := Initial;
|
244 |
|
|
|
245 |
|
|
for I in Loop_Range loop
|
246 |
|
|
Radix_2.Multiply_And_Round (Balance, Factor);
|
247 |
|
|
end loop;
|
248 |
|
|
|
249 |
|
|
case (Machine) is
|
250 |
|
|
when Rounds =>
|
251 |
|
|
if Balance /= Round_Expected_MachRnds then
|
252 |
|
|
Report.Failed ("Error (R): Radix 2 multiply and round");
|
253 |
|
|
end if;
|
254 |
|
|
when Truncates =>
|
255 |
|
|
if Balance /= Round_Expected_MachTrnc then
|
256 |
|
|
Report.Failed ("Error (T): Radix 2 multiply and round");
|
257 |
|
|
end if;
|
258 |
|
|
end case;
|
259 |
|
|
|
260 |
|
|
---=---=---=---=---=---=---
|
261 |
|
|
end RADIX_2_MULTIPLICATION;
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
RADIX_2_DIVISION:
|
265 |
|
|
declare
|
266 |
|
|
Rate : constant CXF2004_1.Interest_Rate := 0.210;
|
267 |
|
|
Period : constant Integer := 12;
|
268 |
|
|
Factor : constant CXF2004_1.Interest_Rate := Rate / Period;
|
269 |
|
|
Divisor : CXF2004_1.Interest_Rate := 1.0 / Factor;
|
270 |
|
|
|
271 |
|
|
-- The exact value of Factor is:
|
272 |
|
|
--
|
273 |
|
|
-- 0.210/12 = 0.0175
|
274 |
|
|
--
|
275 |
|
|
-- The adjacent multiples of small are 0.017 and 0.018. Since
|
276 |
|
|
-- Factor is of an ordinary fixed point type, it may contain either
|
277 |
|
|
-- of these values. However, since "Rate / Period" is a static
|
278 |
|
|
-- expression, the value Factor contains is determined by the
|
279 |
|
|
-- value of CXF2004_1.Interest_Rate'Machine_Rounds:
|
280 |
|
|
--
|
281 |
|
|
-- If Machine_Rounds = FALSE : Factor = 0.017
|
282 |
|
|
-- If Machine_Rounds = TRUE : Factor = 0.018
|
283 |
|
|
--
|
284 |
|
|
-- The exact value of Divisor is one of the following values:
|
285 |
|
|
--
|
286 |
|
|
-- 1.0/0.017 = 58.82352... (Adjacent smalls 58.823 and 58.824)
|
287 |
|
|
-- 1.0/0.018 = 55.55555... (Adjacent smalls 55.555 and 55.556)
|
288 |
|
|
--
|
289 |
|
|
-- Again, since "1.0 / Factor" is static, the value Divisor contains
|
290 |
|
|
-- is determined by the value of CXF2004_1.Interest_Rate'Rounds:
|
291 |
|
|
--
|
292 |
|
|
-- If Machine_Rounds = FALSE : Divisor = 58.823
|
293 |
|
|
-- If Machine_Rounds = TRUE : Divisor = 55.556
|
294 |
|
|
|
295 |
|
|
Initial : constant CXF2004_1.Money_Radix2 := 260.13;
|
296 |
|
|
|
297 |
|
|
Trunc_Expected_MachTrnc: constant CXF2004_1.Money_Radix2 := 5_401.46;
|
298 |
|
|
Round_Expected_MachTrnc: constant CXF2004_1.Money_Radix2 := 5_406.95;
|
299 |
|
|
|
300 |
|
|
Trunc_Expected_MachRnds: constant CXF2004_1.Money_Radix2 := 6_446.56;
|
301 |
|
|
Round_Expected_MachRnds: constant CXF2004_1.Money_Radix2 := 6_453.78;
|
302 |
|
|
|
303 |
|
|
Balance : CXF2004_1.Money_Radix2;
|
304 |
|
|
begin
|
305 |
|
|
---=---=---=---=---=---=---
|
306 |
|
|
|
307 |
|
|
Balance := Initial;
|
308 |
|
|
|
309 |
|
|
for I in Loop_Range loop
|
310 |
|
|
Radix_2.Divide_And_Truncate (Balance, Divisor);
|
311 |
|
|
end loop;
|
312 |
|
|
|
313 |
|
|
case (Machine) is
|
314 |
|
|
when Rounds =>
|
315 |
|
|
if Balance /= Trunc_Expected_MachRnds then
|
316 |
|
|
Report.Failed ("Error (R): Radix 2 divide and truncate");
|
317 |
|
|
end if;
|
318 |
|
|
when Truncates =>
|
319 |
|
|
if Balance /= Trunc_Expected_MachTrnc then
|
320 |
|
|
Report.Failed ("Error (T): Radix 2 divide and truncate");
|
321 |
|
|
end if;
|
322 |
|
|
end case;
|
323 |
|
|
|
324 |
|
|
---=---=---=---=---=---=---
|
325 |
|
|
|
326 |
|
|
Balance := Initial;
|
327 |
|
|
|
328 |
|
|
for I in Loop_Range loop
|
329 |
|
|
Radix_2.Divide_And_Round (Balance, Divisor);
|
330 |
|
|
end loop;
|
331 |
|
|
|
332 |
|
|
case (Machine) is
|
333 |
|
|
when Rounds =>
|
334 |
|
|
if Balance /= Round_Expected_MachRnds then
|
335 |
|
|
Report.Failed ("Error (R): Radix 2 divide and round");
|
336 |
|
|
end if;
|
337 |
|
|
when Truncates =>
|
338 |
|
|
if Balance /= Round_Expected_MachTrnc then
|
339 |
|
|
Report.Failed ("Error (T): Radix 2 divide and round");
|
340 |
|
|
end if;
|
341 |
|
|
end case;
|
342 |
|
|
|
343 |
|
|
---=---=---=---=---=---=---
|
344 |
|
|
end RADIX_2_DIVISION;
|
345 |
|
|
|
346 |
|
|
end RADIX_2_SUBTESTS;
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
---=---=---=---=---=---=---=---=---=---=---
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
RADIX_10_SUBTESTS:
|
353 |
|
|
declare
|
354 |
|
|
package Radix_10 is new CXF2004_0 (CXF2004_1.Money_Radix10,
|
355 |
|
|
CXF2004_1.Interest_Rate);
|
356 |
|
|
use type CXF2004_1.Money_Radix10;
|
357 |
|
|
use type CXF2004_1.Interest_Rate;
|
358 |
|
|
begin
|
359 |
|
|
|
360 |
|
|
RADIX_10_MULTIPLICATION:
|
361 |
|
|
declare
|
362 |
|
|
Rate : constant CXF2004_1.Interest_Rate := 0.095;
|
363 |
|
|
Period : constant Integer := 12;
|
364 |
|
|
Factor : CXF2004_1.Interest_Rate := Rate / Period;
|
365 |
|
|
|
366 |
|
|
-- The exact value of Factor is:
|
367 |
|
|
--
|
368 |
|
|
-- 0.095/12 = 0.00791666...
|
369 |
|
|
--
|
370 |
|
|
-- The adjacent multiples of small are 0.007 and 0.008. Since
|
371 |
|
|
-- Factor is of an ordinary fixed point type, it may contain either
|
372 |
|
|
-- of these values. However, since "Rate / Period" is a static
|
373 |
|
|
-- expression, the value Factor contains can be determined based
|
374 |
|
|
-- on the value of CXF2004_1.Interest_Rate'Machine_Rounds:
|
375 |
|
|
--
|
376 |
|
|
-- If Machine_Rounds = FALSE : Factor = 0.007
|
377 |
|
|
-- If Machine_Rounds = TRUE : Factor = 0.008
|
378 |
|
|
|
379 |
|
|
Initial : constant CXF2004_1.Money_Radix10 := 2_125.00;
|
380 |
|
|
|
381 |
|
|
Trunc_Expected_MachTrnc: constant CXF2004_1.Money_Radix10 := 7_456.90;
|
382 |
|
|
Round_Expected_MachTrnc: constant CXF2004_1.Money_Radix10 := 7_458.77;
|
383 |
|
|
|
384 |
|
|
Trunc_Expected_MachRnds: constant CXF2004_1.Money_Radix10 := 8_915.74;
|
385 |
|
|
Round_Expected_MachRnds: constant CXF2004_1.Money_Radix10 := 8_917.84;
|
386 |
|
|
|
387 |
|
|
Balance : CXF2004_1.Money_Radix10;
|
388 |
|
|
begin
|
389 |
|
|
---=---=---=---=---=---=---
|
390 |
|
|
|
391 |
|
|
Balance := Initial;
|
392 |
|
|
|
393 |
|
|
for I in Loop_Range loop
|
394 |
|
|
Radix_10.Multiply_And_Truncate (Balance, Factor);
|
395 |
|
|
end loop;
|
396 |
|
|
|
397 |
|
|
case (Machine) is
|
398 |
|
|
when Rounds =>
|
399 |
|
|
if Balance /= Trunc_Expected_MachRnds then
|
400 |
|
|
Report.Failed ("Error (R): Radix 10 multiply and truncate");
|
401 |
|
|
end if;
|
402 |
|
|
when Truncates =>
|
403 |
|
|
if Balance /= Trunc_Expected_MachTrnc then
|
404 |
|
|
Report.Failed ("Error (T): Radix 10 multiply and truncate");
|
405 |
|
|
end if;
|
406 |
|
|
end case;
|
407 |
|
|
|
408 |
|
|
---=---=---=---=---=---=---
|
409 |
|
|
|
410 |
|
|
Balance := Initial;
|
411 |
|
|
|
412 |
|
|
for I in Loop_Range loop
|
413 |
|
|
Radix_10.Multiply_And_Round (Balance, Factor);
|
414 |
|
|
end loop;
|
415 |
|
|
|
416 |
|
|
case (Machine) is
|
417 |
|
|
when Rounds =>
|
418 |
|
|
if Balance /= Round_Expected_MachRnds then
|
419 |
|
|
Report.Failed ("Error (R): Radix 10 multiply and round");
|
420 |
|
|
end if;
|
421 |
|
|
when Truncates =>
|
422 |
|
|
if Balance /= Round_Expected_MachTrnc then
|
423 |
|
|
Report.Failed ("Error (T): Radix 10 multiply and round");
|
424 |
|
|
end if;
|
425 |
|
|
end case;
|
426 |
|
|
|
427 |
|
|
---=---=---=---=---=---=---
|
428 |
|
|
end RADIX_10_MULTIPLICATION;
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
RADIX_10_DIVISION:
|
432 |
|
|
declare
|
433 |
|
|
Rate : constant CXF2004_1.Interest_Rate := 0.295;
|
434 |
|
|
Period : constant Integer := 12;
|
435 |
|
|
Factor : constant CXF2004_1.Interest_Rate := Rate / Period;
|
436 |
|
|
Divisor : CXF2004_1.Interest_Rate := 1.0 / Factor;
|
437 |
|
|
|
438 |
|
|
-- The exact value of Factor is:
|
439 |
|
|
--
|
440 |
|
|
-- 0.295/12 = 0.02458333...
|
441 |
|
|
--
|
442 |
|
|
-- The adjacent multiples of small are 0.024 and 0.025. Thus, the
|
443 |
|
|
-- exact value of Divisor is one of the following:
|
444 |
|
|
--
|
445 |
|
|
-- 1.0/0.024 = 41.66666... (Adjacent smalls 41.666 and 41.667)
|
446 |
|
|
-- 1.0/0.025 = 40.0
|
447 |
|
|
--
|
448 |
|
|
-- The value of CXF2004_1.Interest_Rate'Machine_Rounds determines
|
449 |
|
|
-- what Divisor contains:
|
450 |
|
|
--
|
451 |
|
|
-- If Machine_Rounds = FALSE : Divisor = 41.666
|
452 |
|
|
-- If Machine_Rounds = TRUE : Divisor = 40.000
|
453 |
|
|
|
454 |
|
|
Initial : constant CXF2004_1.Money_Radix10 := 72.19;
|
455 |
|
|
|
456 |
|
|
Trunc_Expected_MachTrnc: constant CXF2004_1.Money_Radix10 := 5_144.60;
|
457 |
|
|
Round_Expected_MachTrnc: constant CXF2004_1.Money_Radix10 := 5_157.80;
|
458 |
|
|
|
459 |
|
|
Trunc_Expected_MachRnds: constant CXF2004_1.Money_Radix10 := 6_133.28;
|
460 |
|
|
Round_Expected_MachRnds: constant CXF2004_1.Money_Radix10 := 6_149.06;
|
461 |
|
|
|
462 |
|
|
Balance : CXF2004_1.Money_Radix10;
|
463 |
|
|
begin
|
464 |
|
|
---=---=---=---=---=---=---
|
465 |
|
|
|
466 |
|
|
Balance := Initial;
|
467 |
|
|
|
468 |
|
|
for I in Loop_Range loop
|
469 |
|
|
Radix_10.Divide_And_Truncate (Balance, Divisor);
|
470 |
|
|
end loop;
|
471 |
|
|
|
472 |
|
|
case (Machine) is
|
473 |
|
|
when Rounds =>
|
474 |
|
|
if Balance /= Trunc_Expected_MachRnds then
|
475 |
|
|
Report.Failed ("Error (R): Radix 10 divide and truncate");
|
476 |
|
|
end if;
|
477 |
|
|
when Truncates =>
|
478 |
|
|
if Balance /= Trunc_Expected_MachTrnc then
|
479 |
|
|
Report.Failed ("Error (T): Radix 10 divide and truncate");
|
480 |
|
|
end if;
|
481 |
|
|
end case;
|
482 |
|
|
|
483 |
|
|
---=---=---=---=---=---=---
|
484 |
|
|
|
485 |
|
|
Balance := Initial;
|
486 |
|
|
|
487 |
|
|
for I in Loop_Range loop
|
488 |
|
|
Radix_10.Divide_And_Round (Balance, Divisor);
|
489 |
|
|
end loop;
|
490 |
|
|
|
491 |
|
|
case (Machine) is
|
492 |
|
|
when Rounds =>
|
493 |
|
|
if Balance /= Round_Expected_MachRnds then
|
494 |
|
|
Report.Failed ("Error (R): Radix 10 divide and round");
|
495 |
|
|
end if;
|
496 |
|
|
when Truncates =>
|
497 |
|
|
if Balance /= Round_Expected_MachTrnc then
|
498 |
|
|
Report.Failed ("Error (T): Radix 10 divide and round");
|
499 |
|
|
end if;
|
500 |
|
|
end case;
|
501 |
|
|
|
502 |
|
|
---=---=---=---=---=---=---
|
503 |
|
|
end RADIX_10_DIVISION;
|
504 |
|
|
|
505 |
|
|
end RADIX_10_SUBTESTS;
|
506 |
|
|
|
507 |
|
|
|
508 |
|
|
---=---=---=---=---=---=---=---=---=---=---
|
509 |
|
|
|
510 |
|
|
|
511 |
|
|
Report.Result;
|
512 |
|
|
|
513 |
|
|
end CXF2004;
|