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 Sin and Sinh provide correct results.
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
41 -- The following files comprise this test:
43 -- FXA5A00.A (foundation code)
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
56 with Ada
.Numerics
.Elementary_Functions
;
57 with Ada
.Numerics
.Generic_Elementary_Functions
;
64 Report
.Test
("CXA5A01", "Check that the functions Sin and Sinh provide " &
73 package GEF
is new Ada
.Numerics
.Generic_Elementary_Functions
(New_Float
);
74 package EF
renames Ada
.Numerics
.Elementary_Functions
;
77 New_Float_Result
: New_Float
;
79 procedure Dont_Optimize_Float
is new Dont_Optimize
(Float);
80 procedure Dont_Optimize_New_Float
is new Dont_Optimize
(New_Float
);
84 -- Testing of Sin Function, both instantiated and pre-instantiated
87 -- Check that no exception occurs on computing the Sin with very
88 -- large (positive and negative) input values.
91 New_Float_Result
:= GEF
.Sin
(New_Float
(FXA5A00
.Large
));
92 Dont_Optimize_New_Float
(New_Float_Result
, 1);
95 Report
.Failed
("Unexpected exception on GEF.Sin with large " &
100 The_Result
:= EF
.Sin
(FXA5A00
.Minus_Large
);
101 Dont_Optimize_Float
(The_Result
, 2);
104 Report
.Failed
("Unexpected exception on GEF.Sin with large " &
109 -- Test of Sin for prescribed result at zero.
111 if GEF
.Sin
(0.0) /= 0.0 or
114 Report
.Failed
("Incorrect value returned from Sin(0.0)");
118 -- Test of Sin with expected result value between 0.0 and 1.0.
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)
125 Report
.Failed
("Incorrect value returned from Sin function when " &
126 "the expected result is between 0.0 and 1.0");
130 -- Test of Sin with expected result value between -1.0 and 0.0.
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)
137 Report
.Failed
("Incorrect value returned from Sin function when " &
138 "the expected result is between -1.0 and 0.0");
142 -- Testing of the Sin function with Cycle parameter.
144 -- Check that Argument_Error is raised when the value of the Cycle
145 -- parameter is zero.
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);
153 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
155 Report
.Failed
("Unexpected exception raised by GEF.Sin function " &
156 "when the Cycle parameter is zero");
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);
165 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
167 Report
.Failed
("Unexpected exception raised by EF.Sin function " &
168 "when the Cycle parameter is zero");
171 -- Check that Argument_Error is raised when the value of the Cycle
172 -- parameter is negative.
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);
180 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
182 Report
.Failed
("Unexpected exception raised by GEF.Sin function " &
183 "when the Cycle parameter is negative");
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);
192 when Ada
.Numerics
.Argument_Error
=> null; -- OK, expected exception.
194 Report
.Failed
("Unexpected exception raised by EF.Sin function " &
195 "when the Cycle parameter is negative");
199 -- Check that no exception occurs on computing the Sin with very
200 -- large (positive and negative) input values and Cycle parameter.
203 New_Float_Result
:= GEF
.Sin
(New_Float
(FXA5A00
.Large
), 360.0);
204 Dont_Optimize_New_Float
(New_Float_Result
, 7);
207 Report
.Failed
("Unexpected exception on GEF.Sin with large " &
208 "positive value and Cycle parameter");
212 The_Result
:= EF
.Sin
(FXA5A00
.Minus_Large
, 720.0);
213 Dont_Optimize_Float
(The_Result
, 8);
216 Report
.Failed
("Unexpected exception on EF.Sin with large " &
217 "negative value and Cycle parameter");
221 -- Test of Sin with Cycle parameter for prescribed result at zero.
223 if GEF
.Sin
(0.0, 360.0) /= 0.0 or
224 EF
.Sin
(0.0, 180.0) /= 0.0
226 Report
.Failed
("Incorrect value returned from Sin function with " &
227 "cycle parameter for a zero input parameter value");
231 -- Tests of Sin function with Cycle parameter for prescribed results.
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
240 Report
.Failed
("Incorrect result from the Sin function with " &
241 "various cycle values for prescribed results");
245 -- Testing of Sinh Function, both instantiated and pre-instantiated
248 -- Test for Constraint_Error on parameter with large positive magnitude.
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 " &
257 Dont_Optimize_New_Float
(New_Float_Result
, 9);
261 when Constraint_Error
=> null; -- OK, expected exception.
263 Report
.Failed
("Constraint_Error not raised when the GEF.Sinh " &
264 "function is provided a parameter with a large " &
268 -- Test for Constraint_Error on parameter with large negative magnitude.
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);
281 when Constraint_Error
=> null; -- OK, expected exception.
283 Report
.Failed
("Constraint_Error not raised when the EF.Sinh " &
284 "function is provided a parameter with a " &
285 "large negative value");
289 -- Test that no exception occurs when the Sinh function is provided a
290 -- very small positive or negative value.
293 New_Float_Result
:= GEF
.Sinh
(New_Float
(FXA5A00
.Small
));
294 Dont_Optimize_New_Float
(New_Float_Result
, 11);
297 Report
.Failed
("Unexpected exception on GEF.Sinh with a very" &
298 "small positive value");
302 The_Result
:= EF
.Sinh
(-FXA5A00
.Small
);
303 Dont_Optimize_Float
(The_Result
, 12);
306 Report
.Failed
("Unexpected exception on EF.Sinh with a very" &
307 "small negative value");
311 -- Test for prescribed 0.0 result of Function Sinh with 0.0 parameter.
313 if GEF
.Sinh
(0.0) /= 0.0 or
316 Report
.Failed
("Incorrect value returned from Sinh(0.0)");
320 -- Test of Sinh function with various input parameters.
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)
327 Report
.Failed
("Incorrect result returned from Sinh function " &
328 "with various input parameters");
333 when others => Report
.Failed
("Exception raised in Test_Block");