Mercurial > hg > CbC > CbC_gcc
comparison 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 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 -- CXA5A02.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 functions Cos and Cosh provide correct results. | |
28 -- | |
29 -- TEST DESCRIPTION: | |
30 -- This test examines both the version of Cos and Cosh resulting from | |
31 -- the instantiation of the Ada.Numerics.Generic_Elementary_Functions | |
32 -- with type derived from type Float, as well as the pre-instantiated | |
33 -- version of this package for type Float. | |
34 -- Prescribed results, including instances prescribed to raise | |
35 -- exceptions, are examined in the test cases. In addition, | |
36 -- certain evaluations are performed where the actual function result | |
37 -- is compared with the expected result (within an epsilon range of | |
38 -- accuracy). | |
39 -- | |
40 -- TEST FILES: | |
41 -- The following files comprise this test: | |
42 -- | |
43 -- FXA5A00.A (foundation code) | |
44 -- CXA5A02.A | |
45 -- | |
46 -- | |
47 -- CHANGE HISTORY: | |
48 -- 09 Mar 95 SAIC Initial prerelease version. | |
49 -- 03 Apr 95 SAIC Removed reference to derived type. | |
50 -- 13 Jun 95 SAIC Incorporated use of Dont_Optimize procedure, and | |
51 -- use of Result_Within_Range function overloaded for | |
52 -- FXA5A00.New_Float_Type. | |
53 -- 28 Feb 97 PWB.CTA Removed checks specifying Cycle => 2.0 * Pi | |
54 -- 26 Jun 98 EDS Protected exception checks by first testing | |
55 -- for 'Machine_Overflows. Removed code deleted | |
56 -- by comment. | |
57 -- CHANGE NOTE: | |
58 -- According to Ken Dritz, author of the Numerics Annex of the RM, | |
59 -- one should never specify the cycle 2.0*Pi for the trigonometric | |
60 -- functions. In particular, if the machine number for the first | |
61 -- argument is not an exact multiple of the machine number for the | |
62 -- explicit cycle, then the specified exact results cannot be | |
63 -- reasonably expected. The affected checks have been deleted. | |
64 --! | |
65 | |
66 with Ada.Numerics.Elementary_Functions; | |
67 with Ada.Numerics.Generic_Elementary_Functions; | |
68 with FXA5A00; | |
69 with Report; | |
70 | |
71 procedure CXA5A02 is | |
72 begin | |
73 | |
74 Report.Test ("CXA5A02", "Check that the functions Cos and Cosh provide " & | |
75 "correct results"); | |
76 | |
77 Test_Block: | |
78 declare | |
79 | |
80 use Ada.Numerics; | |
81 use FXA5A00; | |
82 | |
83 package GEF is new Ada.Numerics.Generic_Elementary_Functions(New_Float); | |
84 package EF renames Ada.Numerics.Elementary_Functions; | |
85 | |
86 The_Result : Float; | |
87 New_Float_Result : New_Float; | |
88 | |
89 procedure Dont_Optimize_Float is new Dont_Optimize(Float); | |
90 procedure Dont_Optimize_New_Float is new Dont_Optimize(New_Float); | |
91 | |
92 begin | |
93 | |
94 -- Testing of Cos Function, both instantiated and pre-instantiated | |
95 -- version. | |
96 | |
97 -- Check that no exception occurs on computing the Cos with very | |
98 -- large (positive and negative) input values. | |
99 | |
100 begin | |
101 New_Float_Result := GEF.Cos (New_Float(FXA5A00.Large)); | |
102 Dont_Optimize_New_Float(New_Float_Result, 1); | |
103 exception | |
104 when others => | |
105 Report.Failed("Unexpected exception on GEF.Cos with large " & | |
106 "positive value"); | |
107 end; | |
108 | |
109 begin | |
110 The_Result := EF.Cos (FXA5A00.Minus_Large); | |
111 Dont_Optimize_Float(The_Result, 2); | |
112 exception | |
113 when others => | |
114 Report.Failed("Unexpected exception on GEF.Cos with large " & | |
115 "negative value"); | |
116 end; | |
117 | |
118 | |
119 -- Test of Cos for prescribed result at zero. | |
120 | |
121 if GEF.Cos (0.0) /= 1.0 or | |
122 EF.Cos (0.0) /= 1.0 | |
123 then | |
124 Report.Failed("Incorrect value returned from Cos(0.0)"); | |
125 end if; | |
126 | |
127 | |
128 -- Test of Cos with expected result value between 1.0 and -1.0. | |
129 | |
130 if not (Result_Within_Range( EF.Cos(Ada.Numerics.Pi/3.0), | |
131 0.500, | |
132 0.001) and | |
133 Result_Within_Range(GEF.Cos(0.6166), 0.816, 0.001) and | |
134 Result_Within_Range(GEF.Cos(0.1949), 0.981, 0.001) and | |
135 Result_Within_Range( EF.Cos(Ada.Numerics.Pi/2.0), | |
136 0.00, | |
137 0.001) and | |
138 Result_Within_Range( EF.Cos(2.0*Ada.Numerics.Pi/3.0), | |
139 -0.500, | |
140 0.001) and | |
141 Result_Within_Range(GEF.Cos(New_Float(Ada.Numerics.Pi)), | |
142 -1.00, | |
143 0.001)) | |
144 then | |
145 Report.Failed("Incorrect value returned from Cos function when " & | |
146 "the expected result is between 1.0 and -1.0"); | |
147 end if; | |
148 | |
149 | |
150 -- Testing of the Cos function with Cycle parameter. | |
151 | |
152 -- Check that Argument_Error is raised when the value of the Cycle | |
153 -- parameter is zero. | |
154 | |
155 begin | |
156 New_Float_Result := GEF.Cos (X => 1.0, Cycle => 0.0); | |
157 Report.Failed("Argument_Error not raised by GEF.Cos function " & | |
158 "when the Cycle parameter is zero"); | |
159 Dont_Optimize_New_Float(New_Float_Result, 3); | |
160 exception | |
161 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
162 when others => | |
163 Report.Failed("Unexpected exception raised by GEF.cos function " & | |
164 "when the Cycle parameter is zero"); | |
165 end; | |
166 | |
167 begin | |
168 The_Result := EF.Cos (X => 0.55, Cycle => 0.0); | |
169 Report.Failed("Argument_Error not raised by EF.Cos function when " & | |
170 "the Cycle parameter is zero"); | |
171 Dont_Optimize_Float(The_Result, 4); | |
172 exception | |
173 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
174 when others => | |
175 Report.Failed("Unexpected exception raised by EF.Cos function " & | |
176 "when the Cycle parameter is zero"); | |
177 end; | |
178 | |
179 -- Check that Argument_Error is raised when the value of the Cycle | |
180 -- parameter is negative. | |
181 | |
182 begin | |
183 New_Float_Result := GEF.Cos (X => 0.45, Cycle => -2.0*Pi); | |
184 Report.Failed("Argument_Error not raised by GEF.Cos function " & | |
185 "when the Cycle parameter is negative"); | |
186 Dont_Optimize_New_Float(New_Float_Result, 5); | |
187 exception | |
188 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
189 when others => | |
190 Report.Failed("Unexpected exception raised by GEF.Cos function " & | |
191 "when the Cycle parameter is negative"); | |
192 end; | |
193 | |
194 begin | |
195 The_Result := EF.Cos (X => 0.10, Cycle => -Pi/2.0); | |
196 Report.Failed("Argument_Error not raised by EF.Cos function when " & | |
197 "the Cycle parameter is negative"); | |
198 Dont_Optimize_Float(The_Result, 6); | |
199 exception | |
200 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
201 when others => | |
202 Report.Failed("Unexpected exception raised by EF.Cos function " & | |
203 "when the Cycle parameter is negative"); | |
204 end; | |
205 | |
206 -- Test of Cos with Cycle parameter for prescribed result at zero. | |
207 | |
208 if GEF.Cos (0.0, 360.0) /= 1.0 or | |
209 EF.Cos (0.0, 360.0) /= 1.0 | |
210 then | |
211 Report.Failed("Incorrect value returned from Cos function with " & | |
212 "cycle parameter for a zero input parameter value"); | |
213 end if; | |
214 | |
215 | |
216 -- Tests of Cos function with specified Cycle, using various input | |
217 -- parameter values for prescribed results. | |
218 | |
219 if GEF.Cos(0.0, 360.0) /= 1.0 or | |
220 EF.Cos(360.0, 360.0) /= 1.0 or | |
221 GEF.Cos(90.0, 360.0) /= 0.0 or | |
222 EF.Cos(270.0, 360.0) /= 0.0 or | |
223 GEF.Cos(180.0, 360.0) /= -1.0 or | |
224 EF.Cos(540.0, 360.0) /= -1.0 | |
225 then | |
226 Report.Failed("Incorrect result from the Cos function with " & | |
227 "specified cycle for prescribed results"); | |
228 end if; | |
229 | |
230 | |
231 | |
232 -- Testing of Cosh Function, both instantiated and pre-instantiated | |
233 -- version. | |
234 | |
235 -- Test for Constraint_Error on parameter with large positive magnitude. | |
236 | |
237 begin | |
238 | |
239 if New_Float'Machine_Overflows then | |
240 | |
241 New_Float_Result := GEF.Cosh (New_Float(FXA5A00.Large)); | |
242 Report.Failed("Constraint_Error not raised when the GEF.Cosh " & | |
243 "function is provided a parameter with a large " & | |
244 "positive value"); | |
245 Dont_Optimize_New_Float(New_Float_Result, 9); | |
246 end if; | |
247 | |
248 exception | |
249 when Constraint_Error => null; -- OK, expected exception. | |
250 when others => | |
251 Report.Failed("Constraint_Error not raised when the GEF.Cosh " & | |
252 "function is provided a parameter with a large " & | |
253 "positive value"); | |
254 end; | |
255 | |
256 -- Test for Constraint_Error on parameter with large negative magnitude. | |
257 | |
258 begin | |
259 | |
260 if Float'Machine_Overflows then | |
261 The_Result := EF.Cosh (FXA5A00.Minus_Large); | |
262 Report.Failed("Constraint_Error not raised when the EF.Cosh " & | |
263 "function is provided a parameter with a " & | |
264 "large negative value"); | |
265 Dont_Optimize_Float(The_Result, 10); | |
266 end if; | |
267 | |
268 exception | |
269 when Constraint_Error => null; -- OK, expected exception. | |
270 when others => | |
271 Report.Failed("Constraint_Error not raised when the EF.Cosh " & | |
272 "function is provided a parameter with a " & | |
273 "large negative value"); | |
274 end; | |
275 | |
276 | |
277 -- Test that no exception occurs when the Cosh function is provided a | |
278 -- very small positive or negative value. | |
279 | |
280 begin | |
281 New_Float_Result := GEF.Cosh (New_Float(FXA5A00.Small)); | |
282 Dont_Optimize_New_Float(New_Float_Result, 11); | |
283 exception | |
284 when others => | |
285 Report.Failed("Unexpected exception on GEF.Cosh with a very" & | |
286 "small positive value"); | |
287 end; | |
288 | |
289 begin | |
290 The_Result := EF.Cosh (-FXA5A00.Small); | |
291 Dont_Optimize_Float(The_Result, 12); | |
292 exception | |
293 when others => | |
294 Report.Failed("Unexpected exception on EF.Cosh with a very" & | |
295 "small negative value"); | |
296 end; | |
297 | |
298 | |
299 -- Test for prescribed 1.0 result of Function Cosh with 0.0 parameter. | |
300 | |
301 if GEF.Cosh (0.0) /= 1.0 or | |
302 EF.Cosh (0.0) /= 1.0 | |
303 then | |
304 Report.Failed("Incorrect value returned from Cosh(0.0)"); | |
305 end if; | |
306 | |
307 | |
308 -- Test of Cosh function with various input parameters. | |
309 | |
310 if not FXA5A00.Result_Within_Range(GEF.Cosh(0.24), 1.029, 0.001) or | |
311 not FXA5A00.Result_Within_Range( EF.Cosh(0.59), 1.179, 0.001) or | |
312 not FXA5A00.Result_Within_Range(GEF.Cosh(1.06), 1.616, 0.001) or | |
313 not FXA5A00.Result_Within_Range( EF.Cosh(1.50), 2.352, 0.001) or | |
314 not FXA5A00.Result_Within_Range(GEF.Cosh(1.84), 3.228, 0.001) or | |
315 not FXA5A00.Result_Within_Range( EF.Cosh(3.40), 14.99, 0.01) | |
316 then | |
317 Report.Failed("Incorrect result from Cosh function with " & | |
318 "various input parameters"); | |
319 end if; | |
320 | |
321 | |
322 exception | |
323 when others => Report.Failed ("Exception raised in Test_Block"); | |
324 end Test_Block; | |
325 | |
326 Report.Result; | |
327 | |
328 end CXA5A02; |