2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / ada / acats / tests / cxg / cxg2023.a
blob0cdd5574e09b6f456e4f1d20b78f44f5365168ad
1 -- CXG2023.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.
16 -- DISCLAIMER
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 --*
26 -- OBJECTIVE:
27 -- Check that multiplication and division of decimal fixed point
28 -- numbers produce exact results.
30 -- TEST DESCRIPTION:
31 -- Check that multiplication and division of decimal fixed point
32 -- numbers produce exact results.
34 -- SPECIAL REQUIREMENTS
35 -- The Strict Mode for the numerical accuracy must be
36 -- selected. The method by which this mode is selected
37 -- is implementation dependent.
39 -- APPLICABILITY CRITERIA:
40 -- This test applies only to implementations supporting the
41 -- Numerics Annex.
42 -- This test only applies to the Strict Mode for numerical
43 -- accuracy.
44 -- This test applies only to implementations supporting
45 -- decimal fixed point types of at least 9 digits.
48 -- CHANGE HISTORY:
49 -- 3 Apr 96 SAIC Initial release for 2.1
51 --!
53 with System;
54 with Report;
55 procedure CXG2023 is
56 Verbose : constant Boolean := False;
58 procedure Check_1 is
59 Num_Digits : constant := 6;
60 type Pennies is delta 0.01 digits Num_Digits;
61 type Franklins is delta 100.0 digits Num_Digits;
62 type Dollars is delta 1.0 digits Num_Digits;
64 P1 : Pennies;
65 F1 : Franklins;
66 D1 : Dollars;
68 -- optimization thwarting functions
70 function P (X : Pennies) return Pennies is
71 begin
72 if Report.Ident_Bool (True) then
73 return X;
74 else
75 return 3.21; -- never executed
76 end if;
77 end P;
80 function F (X : Franklins) return Franklins is
81 begin
82 if Report.Ident_Bool (True) then
83 return X;
84 else
85 return 32100.0; -- never executed
86 end if;
87 end F;
90 function D (X : Dollars) return Dollars is
91 begin
92 if Report.Ident_Bool (True) then
93 return X;
94 else
95 return 321.0; -- never executed
96 end if;
97 end D;
100 begin
101 -- multiplication where one operand is universal real
103 P1 := P(0.05) * 200.0;
104 if P1 /= 10.00 then
105 Report.Failed ("1 - expected 10.00 got " & Pennies'Image (P1));
106 end if;
108 D1 := P(0.05) * 100.0;
109 if D1 /= 5.00 then
110 Report.Failed ("2 - expected 5.00 got " & Dollars'Image (D1));
111 end if;
113 F1 := P(0.05) * 50_000.0;
114 if F1 /= 2500.00 then
115 Report.Failed ("3 - expected 2500.0 got " & Franklins'Image (F1));
116 end if;
118 -- multiplication where both operands are decimal fixed
120 P1 := P(0.05) * D(-200.0);
121 if P1 /= -10.00 then
122 Report.Failed ("4 - expected -10.00 got " & Pennies'Image (P1));
123 end if;
125 D1 := P(0.05) * P(-100.0);
126 if D1 /= -5.00 then
127 Report.Failed ("5 - expected -5.00 got " & Dollars'Image (D1));
128 end if;
130 F1 := P(-0.05) * F(50_000.0);
131 if F1 /= -2500.00 then
132 Report.Failed ("6 - expected -2500.0 got " & Franklins'Image (F1));
133 end if;
135 -- division where one operand is universal real
137 P1 := P(0.05) / 0.001;
138 if P1 /= 50.00 then
139 Report.Failed ("7 - expected 50.00 got " & Pennies'Image (P1));
140 end if;
142 D1 := D(1000.0) / 3.0;
143 if D1 /= 333.00 then
144 Report.Failed ("8 - expected 333.00 got " & Dollars'Image (D1));
145 end if;
147 F1 := P(1234.56) / 0.0001;
148 if F1 /= 12345600.00 then
149 Report.Failed ("9 - expected 12345600.0 got " & Franklins'Image (F1));
150 end if;
153 -- division where both operands are decimal fixed
155 P1 := P(0.05) / D(1.0);
156 if P1 /= 0.05 then
157 Report.Failed ("10 - expected 0.05 got " & Pennies'Image (P1));
158 end if;
160 -- check for truncation toward 0
161 D1 := P(-101.00) / P(2.0);
162 if D1 /= -50.00 then
163 Report.Failed ("11 - expected -50.00 got " & Dollars'Image (D1));
164 end if;
166 P1 := P(-102.03) / P(-0.5);
167 if P1 /= 204.06 then
168 Report.Failed ("12 - expected 204.06 got " & Pennies'Image (P1));
169 end if;
171 F1 := P(876.54) / P(0.03);
172 if F1 /= 29200.00 then
173 Report.Failed ("13 - expected 29200.0 got " & Franklins'Image (F1));
174 end if;
176 exception
177 when others =>
178 Report.Failed ("unexpected exception in Check_1");
179 end Check_1;
181 generic
182 type Pennies is delta<> digits<>;
183 type Dollars is delta<> digits<>;
184 type Franklins is delta<> digits<>;
185 procedure Generic_Check;
186 procedure Generic_Check is
188 -- the following code is copied directly from the
189 -- above procedure Check_1
191 P1 : Pennies;
192 F1 : Franklins;
193 D1 : Dollars;
195 -- optimization thwarting functions
197 function P (X : Pennies) return Pennies is
198 begin
199 if Report.Ident_Bool (True) then
200 return X;
201 else
202 return 3.21; -- never executed
203 end if;
204 end P;
207 function F (X : Franklins) return Franklins is
208 begin
209 if Report.Ident_Bool (True) then
210 return X;
211 else
212 return 32100.0; -- never executed
213 end if;
214 end F;
217 function D (X : Dollars) return Dollars is
218 begin
219 if Report.Ident_Bool (True) then
220 return X;
221 else
222 return 321.0; -- never executed
223 end if;
224 end D;
227 begin
228 -- multiplication where one operand is universal real
230 P1 := P(0.05) * 200.0;
231 if P1 /= 10.00 then
232 Report.Failed ("1 - expected 10.00 got " & Pennies'Image (P1));
233 end if;
235 D1 := P(0.05) * 100.0;
236 if D1 /= 5.00 then
237 Report.Failed ("2 - expected 5.00 got " & Dollars'Image (D1));
238 end if;
240 F1 := P(0.05) * 50_000.0;
241 if F1 /= 2500.00 then
242 Report.Failed ("3 - expected 2500.0 got " & Franklins'Image (F1));
243 end if;
245 -- multiplication where both operands are decimal fixed
247 P1 := P(0.05) * D(-200.0);
248 if P1 /= -10.00 then
249 Report.Failed ("4 - expected -10.00 got " & Pennies'Image (P1));
250 end if;
252 D1 := P(0.05) * P(-100.0);
253 if D1 /= -5.00 then
254 Report.Failed ("5 - expected -5.00 got " & Dollars'Image (D1));
255 end if;
257 F1 := P(-0.05) * F(50_000.0);
258 if F1 /= -2500.00 then
259 Report.Failed ("6 - expected -2500.0 got " & Franklins'Image (F1));
260 end if;
262 -- division where one operand is universal real
264 P1 := P(0.05) / 0.001;
265 if P1 /= 50.00 then
266 Report.Failed ("7 - expected 50.00 got " & Pennies'Image (P1));
267 end if;
269 D1 := D(1000.0) / 3.0;
270 if D1 /= 333.00 then
271 Report.Failed ("8 - expected 333.00 got " & Dollars'Image (D1));
272 end if;
274 F1 := P(1234.56) / 0.0001;
275 if F1 /= 12345600.00 then
276 Report.Failed ("9 - expected 12345600.0 got " & Franklins'Image (F1));
277 end if;
280 -- division where both operands are decimal fixed
282 P1 := P(0.05) / D(1.0);
283 if P1 /= 0.05 then
284 Report.Failed ("10 - expected 0.05 got " & Pennies'Image (P1));
285 end if;
287 -- check for truncation toward 0
288 D1 := P(-101.00) / P(2.0);
289 if D1 /= -50.00 then
290 Report.Failed ("11 - expected -50.00 got " & Dollars'Image (D1));
291 end if;
293 P1 := P(-102.03) / P(-0.5);
294 if P1 /= 204.06 then
295 Report.Failed ("12 - expected 204.06 got " & Pennies'Image (P1));
296 end if;
298 F1 := P(876.54) / P(0.03);
299 if F1 /= 29200.00 then
300 Report.Failed ("13 - expected 29200.0 got " & Franklins'Image (F1));
301 end if;
303 end Generic_Check;
306 procedure Check_G6 is
307 Num_Digits : constant := 6;
308 type Pennies is delta 0.01 digits Num_Digits;
309 type Franklins is delta 100.0 digits Num_Digits;
310 type Dollars is delta 1.0 digits Num_Digits;
312 procedure G is new Generic_Check (Pennies, Dollars, Franklins);
313 begin
315 end Check_G6;
318 procedure Check_G9 is
319 Num_Digits : constant := 9;
320 type Pennies is delta 0.01 digits Num_Digits;
321 type Franklins is delta 100.0 digits Num_Digits;
322 type Dollars is delta 1.0 digits Num_Digits;
324 procedure G is new Generic_Check (Pennies, Dollars, Franklins);
325 begin
327 end Check_G9;
330 begin -- main
331 Report.Test ("CXG2023",
332 "Check the accuracy of multiplication and division" &
333 " of decimal fixed point numbers");
335 if Verbose then
336 Report.Comment ("starting Check_1");
337 end if;
338 Check_1;
340 if Verbose then
341 Report.Comment ("starting Check_G6");
342 end if;
343 Check_G6;
345 if Verbose then
346 Report.Comment ("starting Check_G9");
347 end if;
348 Check_G9;
350 Report.Result;
351 end CXG2023;