annotate gcc/testsuite/ada/acats/tests/cxa/cxa5a02.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CXA5A02.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that the functions Cos and Cosh provide correct results.
kono
parents:
diff changeset
28 --
kono
parents:
diff changeset
29 -- TEST DESCRIPTION:
kono
parents:
diff changeset
30 -- This test examines both the version of Cos and Cosh resulting from
kono
parents:
diff changeset
31 -- the instantiation of the Ada.Numerics.Generic_Elementary_Functions
kono
parents:
diff changeset
32 -- with type derived from type Float, as well as the pre-instantiated
kono
parents:
diff changeset
33 -- version of this package for type Float.
kono
parents:
diff changeset
34 -- Prescribed results, including instances prescribed to raise
kono
parents:
diff changeset
35 -- exceptions, are examined in the test cases. In addition,
kono
parents:
diff changeset
36 -- certain evaluations are performed where the actual function result
kono
parents:
diff changeset
37 -- is compared with the expected result (within an epsilon range of
kono
parents:
diff changeset
38 -- accuracy).
kono
parents:
diff changeset
39 --
kono
parents:
diff changeset
40 -- TEST FILES:
kono
parents:
diff changeset
41 -- The following files comprise this test:
kono
parents:
diff changeset
42 --
kono
parents:
diff changeset
43 -- FXA5A00.A (foundation code)
kono
parents:
diff changeset
44 -- CXA5A02.A
kono
parents:
diff changeset
45 --
kono
parents:
diff changeset
46 --
kono
parents:
diff changeset
47 -- CHANGE HISTORY:
kono
parents:
diff changeset
48 -- 09 Mar 95 SAIC Initial prerelease version.
kono
parents:
diff changeset
49 -- 03 Apr 95 SAIC Removed reference to derived type.
kono
parents:
diff changeset
50 -- 13 Jun 95 SAIC Incorporated use of Dont_Optimize procedure, and
kono
parents:
diff changeset
51 -- use of Result_Within_Range function overloaded for
kono
parents:
diff changeset
52 -- FXA5A00.New_Float_Type.
kono
parents:
diff changeset
53 -- 28 Feb 97 PWB.CTA Removed checks specifying Cycle => 2.0 * Pi
kono
parents:
diff changeset
54 -- 26 Jun 98 EDS Protected exception checks by first testing
kono
parents:
diff changeset
55 -- for 'Machine_Overflows. Removed code deleted
kono
parents:
diff changeset
56 -- by comment.
kono
parents:
diff changeset
57 -- CHANGE NOTE:
kono
parents:
diff changeset
58 -- According to Ken Dritz, author of the Numerics Annex of the RM,
kono
parents:
diff changeset
59 -- one should never specify the cycle 2.0*Pi for the trigonometric
kono
parents:
diff changeset
60 -- functions. In particular, if the machine number for the first
kono
parents:
diff changeset
61 -- argument is not an exact multiple of the machine number for the
kono
parents:
diff changeset
62 -- explicit cycle, then the specified exact results cannot be
kono
parents:
diff changeset
63 -- reasonably expected. The affected checks have been deleted.
kono
parents:
diff changeset
64 --!
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 with Ada.Numerics.Elementary_Functions;
kono
parents:
diff changeset
67 with Ada.Numerics.Generic_Elementary_Functions;
kono
parents:
diff changeset
68 with FXA5A00;
kono
parents:
diff changeset
69 with Report;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 procedure CXA5A02 is
kono
parents:
diff changeset
72 begin
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 Report.Test ("CXA5A02", "Check that the functions Cos and Cosh provide " &
kono
parents:
diff changeset
75 "correct results");
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 Test_Block:
kono
parents:
diff changeset
78 declare
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 use Ada.Numerics;
kono
parents:
diff changeset
81 use FXA5A00;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 package GEF is new Ada.Numerics.Generic_Elementary_Functions(New_Float);
kono
parents:
diff changeset
84 package EF renames Ada.Numerics.Elementary_Functions;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 The_Result : Float;
kono
parents:
diff changeset
87 New_Float_Result : New_Float;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 procedure Dont_Optimize_Float is new Dont_Optimize(Float);
kono
parents:
diff changeset
90 procedure Dont_Optimize_New_Float is new Dont_Optimize(New_Float);
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 begin
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 -- Testing of Cos Function, both instantiated and pre-instantiated
kono
parents:
diff changeset
95 -- version.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- Check that no exception occurs on computing the Cos with very
kono
parents:
diff changeset
98 -- large (positive and negative) input values.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 begin
kono
parents:
diff changeset
101 New_Float_Result := GEF.Cos (New_Float(FXA5A00.Large));
kono
parents:
diff changeset
102 Dont_Optimize_New_Float(New_Float_Result, 1);
kono
parents:
diff changeset
103 exception
kono
parents:
diff changeset
104 when others =>
kono
parents:
diff changeset
105 Report.Failed("Unexpected exception on GEF.Cos with large " &
kono
parents:
diff changeset
106 "positive value");
kono
parents:
diff changeset
107 end;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 begin
kono
parents:
diff changeset
110 The_Result := EF.Cos (FXA5A00.Minus_Large);
kono
parents:
diff changeset
111 Dont_Optimize_Float(The_Result, 2);
kono
parents:
diff changeset
112 exception
kono
parents:
diff changeset
113 when others =>
kono
parents:
diff changeset
114 Report.Failed("Unexpected exception on GEF.Cos with large " &
kono
parents:
diff changeset
115 "negative value");
kono
parents:
diff changeset
116 end;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 -- Test of Cos for prescribed result at zero.
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 if GEF.Cos (0.0) /= 1.0 or
kono
parents:
diff changeset
122 EF.Cos (0.0) /= 1.0
kono
parents:
diff changeset
123 then
kono
parents:
diff changeset
124 Report.Failed("Incorrect value returned from Cos(0.0)");
kono
parents:
diff changeset
125 end if;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 -- Test of Cos with expected result value between 1.0 and -1.0.
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 if not (Result_Within_Range( EF.Cos(Ada.Numerics.Pi/3.0),
kono
parents:
diff changeset
131 0.500,
kono
parents:
diff changeset
132 0.001) and
kono
parents:
diff changeset
133 Result_Within_Range(GEF.Cos(0.6166), 0.816, 0.001) and
kono
parents:
diff changeset
134 Result_Within_Range(GEF.Cos(0.1949), 0.981, 0.001) and
kono
parents:
diff changeset
135 Result_Within_Range( EF.Cos(Ada.Numerics.Pi/2.0),
kono
parents:
diff changeset
136 0.00,
kono
parents:
diff changeset
137 0.001) and
kono
parents:
diff changeset
138 Result_Within_Range( EF.Cos(2.0*Ada.Numerics.Pi/3.0),
kono
parents:
diff changeset
139 -0.500,
kono
parents:
diff changeset
140 0.001) and
kono
parents:
diff changeset
141 Result_Within_Range(GEF.Cos(New_Float(Ada.Numerics.Pi)),
kono
parents:
diff changeset
142 -1.00,
kono
parents:
diff changeset
143 0.001))
kono
parents:
diff changeset
144 then
kono
parents:
diff changeset
145 Report.Failed("Incorrect value returned from Cos function when " &
kono
parents:
diff changeset
146 "the expected result is between 1.0 and -1.0");
kono
parents:
diff changeset
147 end if;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 -- Testing of the Cos function with Cycle parameter.
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 -- Check that Argument_Error is raised when the value of the Cycle
kono
parents:
diff changeset
153 -- parameter is zero.
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 begin
kono
parents:
diff changeset
156 New_Float_Result := GEF.Cos (X => 1.0, Cycle => 0.0);
kono
parents:
diff changeset
157 Report.Failed("Argument_Error not raised by GEF.Cos function " &
kono
parents:
diff changeset
158 "when the Cycle parameter is zero");
kono
parents:
diff changeset
159 Dont_Optimize_New_Float(New_Float_Result, 3);
kono
parents:
diff changeset
160 exception
kono
parents:
diff changeset
161 when Ada.Numerics.Argument_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
162 when others =>
kono
parents:
diff changeset
163 Report.Failed("Unexpected exception raised by GEF.cos function " &
kono
parents:
diff changeset
164 "when the Cycle parameter is zero");
kono
parents:
diff changeset
165 end;
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 begin
kono
parents:
diff changeset
168 The_Result := EF.Cos (X => 0.55, Cycle => 0.0);
kono
parents:
diff changeset
169 Report.Failed("Argument_Error not raised by EF.Cos function when " &
kono
parents:
diff changeset
170 "the Cycle parameter is zero");
kono
parents:
diff changeset
171 Dont_Optimize_Float(The_Result, 4);
kono
parents:
diff changeset
172 exception
kono
parents:
diff changeset
173 when Ada.Numerics.Argument_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
174 when others =>
kono
parents:
diff changeset
175 Report.Failed("Unexpected exception raised by EF.Cos function " &
kono
parents:
diff changeset
176 "when the Cycle parameter is zero");
kono
parents:
diff changeset
177 end;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 -- Check that Argument_Error is raised when the value of the Cycle
kono
parents:
diff changeset
180 -- parameter is negative.
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 begin
kono
parents:
diff changeset
183 New_Float_Result := GEF.Cos (X => 0.45, Cycle => -2.0*Pi);
kono
parents:
diff changeset
184 Report.Failed("Argument_Error not raised by GEF.Cos function " &
kono
parents:
diff changeset
185 "when the Cycle parameter is negative");
kono
parents:
diff changeset
186 Dont_Optimize_New_Float(New_Float_Result, 5);
kono
parents:
diff changeset
187 exception
kono
parents:
diff changeset
188 when Ada.Numerics.Argument_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
189 when others =>
kono
parents:
diff changeset
190 Report.Failed("Unexpected exception raised by GEF.Cos function " &
kono
parents:
diff changeset
191 "when the Cycle parameter is negative");
kono
parents:
diff changeset
192 end;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 begin
kono
parents:
diff changeset
195 The_Result := EF.Cos (X => 0.10, Cycle => -Pi/2.0);
kono
parents:
diff changeset
196 Report.Failed("Argument_Error not raised by EF.Cos function when " &
kono
parents:
diff changeset
197 "the Cycle parameter is negative");
kono
parents:
diff changeset
198 Dont_Optimize_Float(The_Result, 6);
kono
parents:
diff changeset
199 exception
kono
parents:
diff changeset
200 when Ada.Numerics.Argument_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
201 when others =>
kono
parents:
diff changeset
202 Report.Failed("Unexpected exception raised by EF.Cos function " &
kono
parents:
diff changeset
203 "when the Cycle parameter is negative");
kono
parents:
diff changeset
204 end;
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 -- Test of Cos with Cycle parameter for prescribed result at zero.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 if GEF.Cos (0.0, 360.0) /= 1.0 or
kono
parents:
diff changeset
209 EF.Cos (0.0, 360.0) /= 1.0
kono
parents:
diff changeset
210 then
kono
parents:
diff changeset
211 Report.Failed("Incorrect value returned from Cos function with " &
kono
parents:
diff changeset
212 "cycle parameter for a zero input parameter value");
kono
parents:
diff changeset
213 end if;
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 -- Tests of Cos function with specified Cycle, using various input
kono
parents:
diff changeset
217 -- parameter values for prescribed results.
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 if GEF.Cos(0.0, 360.0) /= 1.0 or
kono
parents:
diff changeset
220 EF.Cos(360.0, 360.0) /= 1.0 or
kono
parents:
diff changeset
221 GEF.Cos(90.0, 360.0) /= 0.0 or
kono
parents:
diff changeset
222 EF.Cos(270.0, 360.0) /= 0.0 or
kono
parents:
diff changeset
223 GEF.Cos(180.0, 360.0) /= -1.0 or
kono
parents:
diff changeset
224 EF.Cos(540.0, 360.0) /= -1.0
kono
parents:
diff changeset
225 then
kono
parents:
diff changeset
226 Report.Failed("Incorrect result from the Cos function with " &
kono
parents:
diff changeset
227 "specified cycle for prescribed results");
kono
parents:
diff changeset
228 end if;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 -- Testing of Cosh Function, both instantiated and pre-instantiated
kono
parents:
diff changeset
233 -- version.
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 -- Test for Constraint_Error on parameter with large positive magnitude.
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 begin
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 if New_Float'Machine_Overflows then
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 New_Float_Result := GEF.Cosh (New_Float(FXA5A00.Large));
kono
parents:
diff changeset
242 Report.Failed("Constraint_Error not raised when the GEF.Cosh " &
kono
parents:
diff changeset
243 "function is provided a parameter with a large " &
kono
parents:
diff changeset
244 "positive value");
kono
parents:
diff changeset
245 Dont_Optimize_New_Float(New_Float_Result, 9);
kono
parents:
diff changeset
246 end if;
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 exception
kono
parents:
diff changeset
249 when Constraint_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
250 when others =>
kono
parents:
diff changeset
251 Report.Failed("Constraint_Error not raised when the GEF.Cosh " &
kono
parents:
diff changeset
252 "function is provided a parameter with a large " &
kono
parents:
diff changeset
253 "positive value");
kono
parents:
diff changeset
254 end;
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 -- Test for Constraint_Error on parameter with large negative magnitude.
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 begin
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 if Float'Machine_Overflows then
kono
parents:
diff changeset
261 The_Result := EF.Cosh (FXA5A00.Minus_Large);
kono
parents:
diff changeset
262 Report.Failed("Constraint_Error not raised when the EF.Cosh " &
kono
parents:
diff changeset
263 "function is provided a parameter with a " &
kono
parents:
diff changeset
264 "large negative value");
kono
parents:
diff changeset
265 Dont_Optimize_Float(The_Result, 10);
kono
parents:
diff changeset
266 end if;
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 exception
kono
parents:
diff changeset
269 when Constraint_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
270 when others =>
kono
parents:
diff changeset
271 Report.Failed("Constraint_Error not raised when the EF.Cosh " &
kono
parents:
diff changeset
272 "function is provided a parameter with a " &
kono
parents:
diff changeset
273 "large negative value");
kono
parents:
diff changeset
274 end;
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 -- Test that no exception occurs when the Cosh function is provided a
kono
parents:
diff changeset
278 -- very small positive or negative value.
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 begin
kono
parents:
diff changeset
281 New_Float_Result := GEF.Cosh (New_Float(FXA5A00.Small));
kono
parents:
diff changeset
282 Dont_Optimize_New_Float(New_Float_Result, 11);
kono
parents:
diff changeset
283 exception
kono
parents:
diff changeset
284 when others =>
kono
parents:
diff changeset
285 Report.Failed("Unexpected exception on GEF.Cosh with a very" &
kono
parents:
diff changeset
286 "small positive value");
kono
parents:
diff changeset
287 end;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 begin
kono
parents:
diff changeset
290 The_Result := EF.Cosh (-FXA5A00.Small);
kono
parents:
diff changeset
291 Dont_Optimize_Float(The_Result, 12);
kono
parents:
diff changeset
292 exception
kono
parents:
diff changeset
293 when others =>
kono
parents:
diff changeset
294 Report.Failed("Unexpected exception on EF.Cosh with a very" &
kono
parents:
diff changeset
295 "small negative value");
kono
parents:
diff changeset
296 end;
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 -- Test for prescribed 1.0 result of Function Cosh with 0.0 parameter.
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 if GEF.Cosh (0.0) /= 1.0 or
kono
parents:
diff changeset
302 EF.Cosh (0.0) /= 1.0
kono
parents:
diff changeset
303 then
kono
parents:
diff changeset
304 Report.Failed("Incorrect value returned from Cosh(0.0)");
kono
parents:
diff changeset
305 end if;
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 -- Test of Cosh function with various input parameters.
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 if not FXA5A00.Result_Within_Range(GEF.Cosh(0.24), 1.029, 0.001) or
kono
parents:
diff changeset
311 not FXA5A00.Result_Within_Range( EF.Cosh(0.59), 1.179, 0.001) or
kono
parents:
diff changeset
312 not FXA5A00.Result_Within_Range(GEF.Cosh(1.06), 1.616, 0.001) or
kono
parents:
diff changeset
313 not FXA5A00.Result_Within_Range( EF.Cosh(1.50), 2.352, 0.001) or
kono
parents:
diff changeset
314 not FXA5A00.Result_Within_Range(GEF.Cosh(1.84), 3.228, 0.001) or
kono
parents:
diff changeset
315 not FXA5A00.Result_Within_Range( EF.Cosh(3.40), 14.99, 0.01)
kono
parents:
diff changeset
316 then
kono
parents:
diff changeset
317 Report.Failed("Incorrect result from Cosh function with " &
kono
parents:
diff changeset
318 "various input parameters");
kono
parents:
diff changeset
319 end if;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 exception
kono
parents:
diff changeset
323 when others => Report.Failed ("Exception raised in Test_Block");
kono
parents:
diff changeset
324 end Test_Block;
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 Report.Result;
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 end CXA5A02;