3 -- Grant of Unlimited Rights
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
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.
27 -- Check that the functions Cos and Cosh provide correct results.
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
41 -- The following files comprise this test:
43 -- FXA5A00.A (foundation code)
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
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.
66 with Ada
.Numerics
.Elementary_Functions
;
67 with Ada
.Numerics
.Generic_Elementary_Functions
;
74 Report
.Test
("CXA5A02", "Check that the functions Cos and Cosh provide " &
83 package GEF
is new Ada
.Numerics
.Generic_Elementary_Functions
(New_Float
);
84 package EF
renames Ada
.Numerics
.Elementary_Functions
;
87 New_Float_Result
: New_Float
;
89 procedure Dont_Optimize_Float
is new Dont_Optimize
(Float);
90 procedure Dont_Optimize_New_Float
is new Dont_Optimize
(New_Float
);
94 -- Testing of Cos Function, both instantiated and pre-instantiated
97 -- Check that no exception occurs on computing the Cos with very
98 -- large (positive and negative) input values.
101 New_Float_Result
:= GEF
.Cos
(New_Float
(FXA5A00
.Large
));
102 Dont_Optimize_New_Float
(New_Float_Result
, 1);
105 Report
.Failed
("Unexpected exception on GEF.Cos with large " &
110 The_Result
:= EF
.Cos
(FXA5A00
.Minus_Large
);
111 Dont_Optimize_Float
(The_Result
, 2);
114 Report
.Failed
("Unexpected exception on GEF.Cos with large " &
119 -- Test of Cos for prescribed result at zero.
121 if GEF
.Cos
(0.0) /= 1.0 or
124 Report
.Failed
("Incorrect value returned from Cos(0.0)");
128 -- Test of Cos with expected result value between 1.0 and -1.0.
130 if not (Result_Within_Range
( EF
.Cos
(Ada
.Numerics
.Pi
/3.0),
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),
138 Result_Within_Range
( EF
.Cos
(2.0*Ada
.Numerics
.Pi
/3.0),
141 Result_Within_Range
(GEF
.Cos
(New_Float
(Ada
.Numerics
.Pi
)),
145 Report
.Failed
("Incorrect value returned from Cos function when " &
146 "the expected result is between 1.0 and -1.0");
150 -- Testing of the Cos function with Cycle parameter.
152 -- Check that Argument_Error is raised when the value of the Cycle
153 -- parameter is zero.
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);
161 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
163 Report
.Failed
("Unexpected exception raised by GEF.cos function " &
164 "when the Cycle parameter is zero");
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);
173 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
175 Report
.Failed
("Unexpected exception raised by EF.Cos function " &
176 "when the Cycle parameter is zero");
179 -- Check that Argument_Error is raised when the value of the Cycle
180 -- parameter is negative.
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);
188 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
190 Report
.Failed
("Unexpected exception raised by GEF.Cos function " &
191 "when the Cycle parameter is negative");
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);
200 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
202 Report
.Failed
("Unexpected exception raised by EF.Cos function " &
203 "when the Cycle parameter is negative");
206 -- Test of Cos with Cycle parameter for prescribed result at zero.
208 if GEF
.Cos
(0.0, 360.0) /= 1.0 or
209 EF
.Cos
(0.0, 360.0) /= 1.0
211 Report
.Failed
("Incorrect value returned from Cos function with " &
212 "cycle parameter for a zero input parameter value");
216 -- Tests of Cos function with specified Cycle, using various input
217 -- parameter values for prescribed results.
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
226 Report
.Failed
("Incorrect result from the Cos function with " &
227 "specified cycle for prescribed results");
232 -- Testing of Cosh Function, both instantiated and pre-instantiated
235 -- Test for Constraint_Error on parameter with large positive magnitude.
239 if New_Float
'Machine_Overflows then
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 " &
245 Dont_Optimize_New_Float
(New_Float_Result
, 9);
249 when Constraint_Error
=> null; -- OK, expected exception.
251 Report
.Failed
("Constraint_Error not raised when the GEF.Cosh " &
252 "function is provided a parameter with a large " &
256 -- Test for Constraint_Error on parameter with large negative magnitude.
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);
269 when Constraint_Error
=> null; -- OK, expected exception.
271 Report
.Failed
("Constraint_Error not raised when the EF.Cosh " &
272 "function is provided a parameter with a " &
273 "large negative value");
277 -- Test that no exception occurs when the Cosh function is provided a
278 -- very small positive or negative value.
281 New_Float_Result
:= GEF
.Cosh
(New_Float
(FXA5A00
.Small
));
282 Dont_Optimize_New_Float
(New_Float_Result
, 11);
285 Report
.Failed
("Unexpected exception on GEF.Cosh with a very" &
286 "small positive value");
290 The_Result
:= EF
.Cosh
(-FXA5A00
.Small
);
291 Dont_Optimize_Float
(The_Result
, 12);
294 Report
.Failed
("Unexpected exception on EF.Cosh with a very" &
295 "small negative value");
299 -- Test for prescribed 1.0 result of Function Cosh with 0.0 parameter.
301 if GEF
.Cosh
(0.0) /= 1.0 or
304 Report
.Failed
("Incorrect value returned from Cosh(0.0)");
308 -- Test of Cosh function with various input parameters.
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)
317 Report
.Failed
("Incorrect result from Cosh function with " &
318 "various input parameters");
323 when others => Report
.Failed
("Exception raised in Test_Block");