Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/ada/acats/tests/cxa/cxa5a01.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 -- CXA5A01.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 Sin and Sinh provide correct results. | |
28 -- | |
29 -- TEST DESCRIPTION: | |
30 -- This test examines both the version of Sin and Sinh resulting from | |
31 -- the instantiation of the Ada.Numerics.Generic_Elementary_Functions | |
32 -- with a type derived from type Float, as well as the preinstantiated | |
33 -- version of this package for type Float. | |
34 -- Prescribed results, as well as 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 -- CXA5A01.A | |
45 -- | |
46 -- | |
47 -- CHANGE HISTORY: | |
48 -- 06 Mar 95 SAIC Initial prerelease version. | |
49 -- 13 Jun 95 SAIC Incorporated use of Dont_Optimize procedure, and | |
50 -- use of Result_Within_Range function overloaded for | |
51 -- FXA5A00.New_Float_Type. | |
52 -- 26 Jun 98 EDS Protected exception tests by first testing | |
53 -- for 'Machine_Overflows | |
54 --! | |
55 | |
56 with Ada.Numerics.Elementary_Functions; | |
57 with Ada.Numerics.Generic_Elementary_Functions; | |
58 with FXA5A00; | |
59 with Report; | |
60 | |
61 procedure CXA5A01 is | |
62 begin | |
63 | |
64 Report.Test ("CXA5A01", "Check that the functions Sin and Sinh provide " & | |
65 "correct results"); | |
66 | |
67 Test_Block: | |
68 declare | |
69 | |
70 use Ada.Numerics; | |
71 use FXA5A00; | |
72 | |
73 package GEF is new Ada.Numerics.Generic_Elementary_Functions(New_Float); | |
74 package EF renames Ada.Numerics.Elementary_Functions; | |
75 | |
76 The_Result : Float; | |
77 New_Float_Result : New_Float; | |
78 | |
79 procedure Dont_Optimize_Float is new Dont_Optimize(Float); | |
80 procedure Dont_Optimize_New_Float is new Dont_Optimize(New_Float); | |
81 | |
82 begin | |
83 | |
84 -- Testing of Sin Function, both instantiated and pre-instantiated | |
85 -- version. | |
86 | |
87 -- Check that no exception occurs on computing the Sin with very | |
88 -- large (positive and negative) input values. | |
89 | |
90 begin | |
91 New_Float_Result := GEF.Sin (New_Float(FXA5A00.Large)); | |
92 Dont_Optimize_New_Float(New_Float_Result, 1); | |
93 exception | |
94 when others => | |
95 Report.Failed("Unexpected exception on GEF.Sin with large " & | |
96 "positive value"); | |
97 end; | |
98 | |
99 begin | |
100 The_Result := EF.Sin (FXA5A00.Minus_Large); | |
101 Dont_Optimize_Float(The_Result, 2); | |
102 exception | |
103 when others => | |
104 Report.Failed("Unexpected exception on GEF.Sin with large " & | |
105 "negative value"); | |
106 end; | |
107 | |
108 | |
109 -- Test of Sin for prescribed result at zero. | |
110 | |
111 if GEF.Sin (0.0) /= 0.0 or | |
112 EF.Sin (0.0) /= 0.0 | |
113 then | |
114 Report.Failed("Incorrect value returned from Sin(0.0)"); | |
115 end if; | |
116 | |
117 | |
118 -- Test of Sin with expected result value between 0.0 and 1.0. | |
119 | |
120 if not (GEF.Sin (Ada.Numerics.Pi/4.0) < 1.0) or | |
121 not ( EF.Sin (Ada.Numerics.Pi/4.0) < 1.0) or | |
122 not FXA5A00.Result_Within_Range(GEF.Sin(0.35), 0.343, 0.001) or | |
123 not FXA5A00.Result_Within_Range( EF.Sin(1.18), 0.924, 0.001) | |
124 then | |
125 Report.Failed("Incorrect value returned from Sin function when " & | |
126 "the expected result is between 0.0 and 1.0"); | |
127 end if; | |
128 | |
129 | |
130 -- Test of Sin with expected result value between -1.0 and 0.0. | |
131 | |
132 if not (GEF.Sin (-Ada.Numerics.Pi/4.0) > -1.0) or | |
133 not ( EF.Sin (-Ada.Numerics.Pi/4.0) > -1.0) or | |
134 not FXA5A00.Result_Within_Range(GEF.Sin(-0.24), -0.238, 0.001) or | |
135 not FXA5A00.Result_Within_Range( EF.Sin(-1.00), -0.841, 0.001) | |
136 then | |
137 Report.Failed("Incorrect value returned from Sin function when " & | |
138 "the expected result is between -1.0 and 0.0"); | |
139 end if; | |
140 | |
141 | |
142 -- Testing of the Sin function with Cycle parameter. | |
143 | |
144 -- Check that Argument_Error is raised when the value of the Cycle | |
145 -- parameter is zero. | |
146 | |
147 begin | |
148 New_Float_Result := GEF.Sin (X => 1.0, Cycle => 0.0); | |
149 Report.Failed("Argument_Error not raised by GEF.Sin function " & | |
150 "when the Cycle parameter is zero"); | |
151 Dont_Optimize_New_Float(New_Float_Result, 3); | |
152 exception | |
153 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
154 when others => | |
155 Report.Failed("Unexpected exception raised by GEF.Sin function " & | |
156 "when the Cycle parameter is zero"); | |
157 end; | |
158 | |
159 begin | |
160 The_Result := EF.Sin (X => 0.34, Cycle => 0.0); | |
161 Report.Failed("Argument_Error not raised by EF.Sin function when " & | |
162 "the Cycle parameter is zero"); | |
163 Dont_Optimize_Float(The_Result, 4); | |
164 exception | |
165 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
166 when others => | |
167 Report.Failed("Unexpected exception raised by EF.Sin function " & | |
168 "when the Cycle parameter is zero"); | |
169 end; | |
170 | |
171 -- Check that Argument_Error is raised when the value of the Cycle | |
172 -- parameter is negative. | |
173 | |
174 begin | |
175 New_Float_Result := GEF.Sin (X => 0.45, Cycle => -1.0); | |
176 Report.Failed("Argument_Error not raised by GEF.Sin function " & | |
177 "when the Cycle parameter is negative"); | |
178 Dont_Optimize_New_Float(New_Float_Result, 5); | |
179 exception | |
180 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
181 when others => | |
182 Report.Failed("Unexpected exception raised by GEF.Sin function " & | |
183 "when the Cycle parameter is negative"); | |
184 end; | |
185 | |
186 begin | |
187 The_Result := EF.Sin (X => 0.10, Cycle => -4.0); | |
188 Report.Failed("Argument_Error not raised by EF.Sin function when " & | |
189 "the Cycle parameter is negative"); | |
190 Dont_Optimize_Float(The_Result, 6); | |
191 exception | |
192 when Ada.Numerics.Argument_Error => null; -- OK, expected exception. | |
193 when others => | |
194 Report.Failed("Unexpected exception raised by EF.Sin function " & | |
195 "when the Cycle parameter is negative"); | |
196 end; | |
197 | |
198 | |
199 -- Check that no exception occurs on computing the Sin with very | |
200 -- large (positive and negative) input values and Cycle parameter. | |
201 | |
202 begin | |
203 New_Float_Result := GEF.Sin (New_Float(FXA5A00.Large), 360.0); | |
204 Dont_Optimize_New_Float(New_Float_Result, 7); | |
205 exception | |
206 when others => | |
207 Report.Failed("Unexpected exception on GEF.Sin with large " & | |
208 "positive value and Cycle parameter"); | |
209 end; | |
210 | |
211 begin | |
212 The_Result := EF.Sin (FXA5A00.Minus_Large, 720.0); | |
213 Dont_Optimize_Float(The_Result, 8); | |
214 exception | |
215 when others => | |
216 Report.Failed("Unexpected exception on EF.Sin with large " & | |
217 "negative value and Cycle parameter"); | |
218 end; | |
219 | |
220 | |
221 -- Test of Sin with Cycle parameter for prescribed result at zero. | |
222 | |
223 if GEF.Sin (0.0, 360.0) /= 0.0 or | |
224 EF.Sin (0.0, 180.0) /= 0.0 | |
225 then | |
226 Report.Failed("Incorrect value returned from Sin function with " & | |
227 "cycle parameter for a zero input parameter value"); | |
228 end if; | |
229 | |
230 | |
231 -- Tests of Sin function with Cycle parameter for prescribed results. | |
232 | |
233 if GEF.Sin(0.0, 360.0) /= 0.0 or | |
234 EF.Sin(180.0, 360.0) /= 0.0 or | |
235 GEF.Sin(90.0, 360.0) /= 1.0 or | |
236 EF.Sin(450.0, 360.0) /= 1.0 or | |
237 GEF.Sin(270.0, 360.0) /= -1.0 or | |
238 EF.Sin(630.0, 360.0) /= -1.0 | |
239 then | |
240 Report.Failed("Incorrect result from the Sin function with " & | |
241 "various cycle values for prescribed results"); | |
242 end if; | |
243 | |
244 | |
245 -- Testing of Sinh Function, both instantiated and pre-instantiated | |
246 -- version. | |
247 | |
248 -- Test for Constraint_Error on parameter with large positive magnitude. | |
249 | |
250 begin | |
251 | |
252 if New_Float'Machine_Overflows then | |
253 New_Float_Result := GEF.Sinh (New_Float(FXA5A00.Large)); | |
254 Report.Failed("Constraint_Error not raised when the GEF.Sinh " & | |
255 "function is provided a parameter with a large " & | |
256 "positive value"); | |
257 Dont_Optimize_New_Float(New_Float_Result, 9); | |
258 end if; | |
259 | |
260 exception | |
261 when Constraint_Error => null; -- OK, expected exception. | |
262 when others => | |
263 Report.Failed("Constraint_Error not raised when the GEF.Sinh " & | |
264 "function is provided a parameter with a large " & | |
265 "positive value"); | |
266 end; | |
267 | |
268 -- Test for Constraint_Error on parameter with large negative magnitude. | |
269 | |
270 begin | |
271 | |
272 if Float'Machine_Overflows then | |
273 The_Result := EF.Sinh (FXA5A00.Minus_Large); | |
274 Report.Failed("Constraint_Error not raised when the EF.Sinh " & | |
275 "function is provided a parameter with a " & | |
276 "large negative value"); | |
277 Dont_Optimize_Float(The_Result, 10); | |
278 end if; | |
279 | |
280 exception | |
281 when Constraint_Error => null; -- OK, expected exception. | |
282 when others => | |
283 Report.Failed("Constraint_Error not raised when the EF.Sinh " & | |
284 "function is provided a parameter with a " & | |
285 "large negative value"); | |
286 end; | |
287 | |
288 | |
289 -- Test that no exception occurs when the Sinh function is provided a | |
290 -- very small positive or negative value. | |
291 | |
292 begin | |
293 New_Float_Result := GEF.Sinh (New_Float(FXA5A00.Small)); | |
294 Dont_Optimize_New_Float(New_Float_Result, 11); | |
295 exception | |
296 when others => | |
297 Report.Failed("Unexpected exception on GEF.Sinh with a very" & | |
298 "small positive value"); | |
299 end; | |
300 | |
301 begin | |
302 The_Result := EF.Sinh (-FXA5A00.Small); | |
303 Dont_Optimize_Float(The_Result, 12); | |
304 exception | |
305 when others => | |
306 Report.Failed("Unexpected exception on EF.Sinh with a very" & | |
307 "small negative value"); | |
308 end; | |
309 | |
310 | |
311 -- Test for prescribed 0.0 result of Function Sinh with 0.0 parameter. | |
312 | |
313 if GEF.Sinh (0.0) /= 0.0 or | |
314 EF.Sinh (0.0) /= 0.0 | |
315 then | |
316 Report.Failed("Incorrect value returned from Sinh(0.0)"); | |
317 end if; | |
318 | |
319 | |
320 -- Test of Sinh function with various input parameters. | |
321 | |
322 if not FXA5A00.Result_Within_Range(GEF.Sinh(0.01), 0.010, 0.001) or | |
323 not FXA5A00.Result_Within_Range( EF.Sinh(0.61), 0.649, 0.001) or | |
324 not FXA5A00.Result_Within_Range(GEF.Sinh(1.70), 2.65, 0.01) or | |
325 not FXA5A00.Result_Within_Range( EF.Sinh(3.15), 11.65, 0.01) | |
326 then | |
327 Report.Failed("Incorrect result returned from Sinh function " & | |
328 "with various input parameters"); | |
329 end if; | |
330 | |
331 | |
332 exception | |
333 when others => Report.Failed ("Exception raised in Test_Block"); | |
334 end Test_Block; | |
335 | |
336 Report.Result; | |
337 | |
338 end CXA5A01; |