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 Exp and Sqrt, and the exponentiation
28 -- operator "**" provide correct results.
31 -- This test examines both the versions of Exp, Sqrt, and "**"
32 -- resulting from the instantiation of the
33 -- Ada.Numerics.Generic_Elementary_Functions with a type derived from
34 -- type Float, as well as the preinstantiated version of this package
36 -- Prescribed results (stated as such in the reference manual),
37 -- including instances prescribed to raise exceptions, are examined
38 -- in the test cases. In addition, certain evaluations are performed
39 -- for the preinstantiated package where the actual function result is
40 -- compared with the expected result (within an epsilon range of
44 -- The following files comprise this test:
46 -- FXA5A00.A (foundation code)
51 -- 17 Apr 95 SAIC Initial prerelease version.
52 -- 13 Jun 95 SAIC Incorporated use of Dont_Optimize procedure, and
53 -- use of Result_Within_Range function overloaded for
54 -- FXA5A00.New_Float_Type.
55 -- 18 Apr 96 SAIC Incorporated reviewer comments for ACVC 2.1.
56 -- 01 Oct 01 RLB Protected Constraint_Error exception tests by
57 -- first testing for 'Machine_Overflows.
62 with Ada
.Numerics
.Elementary_Functions
;
63 with Ada
.Numerics
.Generic_Elementary_Functions
;
70 Report
.Test
("CXA5A10", "Check that Exp, Sqrt, and the ""**"" operator " &
71 "provide correct results");
76 use FXA5A00
, Ada
.Numerics
;
79 package GEF
is new Ada
.Numerics
.Generic_Elementary_Functions
(New_Float
);
80 package EF
renames Ada
.Numerics
.Elementary_Functions
;
86 New_Float_Result
: New_Float
;
88 Flag_1
, Flag_2
, Flag_3
, Flag_4
,
89 Incorrect_Inverse_Base_e
,
90 Incorrect_Inverse_Base_2
,
91 Incorrect_Inverse_Base_8
,
92 Incorrect_Inverse_Base_10
,
93 Incorrect_Inverse_Base_16
: Boolean := False;
95 procedure Dont_Optimize_Float
is new Dont_Optimize
(Float);
96 procedure Dont_Optimize_New_Float
is new Dont_Optimize
(New_Float
);
100 -- Testing of the "**" operator, both instantiated and pre-instantiated
103 -- Check that Argument_Error is raised by the exponentiation operator
104 -- when the value of the Left parameter (operand) is negative.
107 New_Float_Result
:= GEF
."**"(Left
=> -10.0,
109 Report
.Failed
("Argument_Error not raised by the instantiated " &
110 "version of the exponentiation operator when the " &
111 "value of the Left parameter is negative");
112 Dont_Optimize_New_Float
(New_Float_Result
, 1);
114 when Argument_Error
=> null; -- OK, expected exception.
116 Report
.Failed
("Unexpected exception raised by the " &
117 "instantiated version of the exponentiation " &
118 "operator when the value of the Left parameter " &
123 Float_Result
:= (-FXA5A00
.Small
) ** 4.0;
124 Report
.Failed
("Argument_Error not raised by the preinstantiated " &
125 "version of the exponentiation operator when the " &
126 "value of the Left parameter is negative");
127 Dont_Optimize_Float
(Float_Result
, 2);
129 when Argument_Error
=> null; -- OK, expected exception.
131 Report
.Failed
("Unexpected exception raised by the " &
132 "preinstantiated version of the exponentiation " &
133 "operator when the value of the Left parameter " &
138 -- Check that Argument_Error is raised by the exponentiation operator
139 -- when both parameters (operands) have the value 0.0.
142 New_Float_Result
:= GEF
."**"(0.0, Right
=> 0.0);
143 Report
.Failed
("Argument_Error not raised by the instantiated " &
144 "version of the exponentiation operator when " &
145 "both operands are zero");
146 Dont_Optimize_New_Float
(New_Float_Result
, 3);
148 when Argument_Error
=> null; -- OK, expected exception.
150 Report
.Failed
("Unexpected exception raised by the " &
151 "instantiated version of the exponentiation " &
152 "operator when both operands are zero");
156 Float_Result
:= 0.0**0.0;
157 Report
.Failed
("Argument_Error not raised by the preinstantiated " &
158 "version of the exponentiation operator when both " &
159 "operands are zero");
160 Dont_Optimize_Float
(Float_Result
, 4);
162 when Argument_Error
=> null; -- OK, expected exception.
164 Report
.Failed
("Unexpected exception raised by the " &
165 "preinstantiated version of the exponentiation " &
166 "operator when both operands are zero");
170 -- Check that Constraint_Error is raised by the exponentiation
171 -- operator when the value of the left parameter (operand) is zero,
172 -- and the value of the right parameter (exponent) is negative.
173 -- This check applies only if Machine_Overflows is true [A.5.1(28, 30)].
175 if New_Float
'Machine_Overflows = True then
177 New_Float_Result
:= GEF
."**"(0.0, Right
=> -2.0);
178 Report
.Failed
("Constraint_Error not raised by the instantiated " &
179 "version of the exponentiation operator when " &
180 "the left parameter is 0.0, and the right " &
181 "parameter is negative");
182 Dont_Optimize_New_Float
(New_Float_Result
, 5);
184 when Constraint_Error
=> null; -- OK, expected exception.
186 Report
.Failed
("Unexpected exception raised by the " &
187 "instantiated version of the exponentiation " &
188 "operator when the left parameter is 0.0, " &
189 "and the right parameter is negative");
193 if Float'Machine_Overflows = True then
195 Float_Result
:= 0.0 ** (-FXA5A00
.Small
);
196 Report
.Failed
("Constraint_Error not raised by the " &
197 "preinstantiated version of the exponentiation " &
198 "operator when the left parameter is 0.0, and the " &
199 "right parameter is negative");
200 Dont_Optimize_Float
(Float_Result
, 6);
202 when Constraint_Error
=> null; -- OK, expected exception.
204 Report
.Failed
("Unexpected exception raised by the " &
205 "preinstantiated version of the exponentiation " &
206 "operator when the left parameter is 0.0, and " &
207 "the right parameter is negative");
211 -- Prescribed results.
212 -- Check that exponentiation by a 0.0 exponent yields the value one.
214 if GEF
."**"(Left
=> 10.0, Right
=> 0.0) /= 1.0 or
215 EF
."**"(FXA5A00
.Large
, Right
=> 0.0) /= 1.0 or
216 GEF
."**"(3.0, 0.0) /= 1.0 or
217 FXA5A00
.Small
** 0.0 /= 1.0
219 Report
.Failed
("Incorrect results returned from the ""**"" " &
220 "operator when the value of the exponent is 0.0");
224 -- Check that exponentiation by a unit exponent yields the value
225 -- of the left operand.
227 if GEF
."**"(Left
=> 50.0, Right
=> 1.0) /= 50.0 or
228 EF
."**"(FXA5A00
.Large
, Right
=> 1.0) /= FXA5A00
.Large
or
229 GEF
."**"(6.0, 1.0) /= 6.0 or
230 FXA5A00
.Small
** 1.0 /= FXA5A00
.Small
232 Report
.Failed
("Incorrect results returned from the ""**"" " &
233 "operator when the value of the exponent is 1.0");
237 -- Check that exponentiation of the value 1.0 yields the value 1.0.
239 if GEF
."**"(Left
=> 1.0, Right
=> 16.0) /= 1.0 or
240 EF
."**"(1.0, Right
=> FXA5A00
.Large
) /= 1.0 or
241 GEF
."**"(1.0, 3.0) /= 1.0 or
242 1.0 ** FXA5A00
.Small
/= 1.0
244 Report
.Failed
("Incorrect results returned from the ""**"" " &
245 "operator when the value of the operand is 1.0");
249 -- Check that exponentiation of the value 0.0 yields the value 0.0.
251 if GEF
."**"(Left
=> 0.0, Right
=> 10.0) /= 0.0 or
252 EF
."**"(0.0, Right
=> FXA5A00
.Large
) /= 0.0 or
253 GEF
."**"(0.0, 4.0) /= 0.0 or
254 0.0 ** FXA5A00
.Small
/= 0.0
256 Report
.Failed
("Incorrect results returned from the ""**"" " &
257 "operator when the value of the operand is 0.0");
261 -- Check that exponentiation of various operands with a variety of
262 -- of exponent values yield correct results.
264 if not Result_Within_Range
(GEF
."**"(5.0, 2.0), 25.0, 0.01) or
265 not Result_Within_Range
(GEF
."**"(1.225, 1.5), 1.36, 0.01) or
266 not Result_Within_Range
(GEF
."**"(0.26, 2.0), 0.068, 0.001) or
267 not Result_Within_Range
( EF
."**"(e
, 5.0), 148.4, 0.1) or
268 not Result_Within_Range
( EF
."**"(10.0, e
), 522.7, 0.1) or
269 not Result_Within_Range
( EF
."**"(e
, (-3.0)), 0.050, 0.001) or
270 not Result_Within_Range
(GEF
."**"(10.0,(-2.0)), 0.010, 0.001)
272 Report
.Failed
("Incorrect results returned from the ""**"" " &
273 "operator with a variety of operand and exponent " &
278 -- Use the following loops to check for internal consistency between
279 -- inverse functions.
282 -- Use the relative error value to account for non-exact
284 TC_Relative_Error
: Float := 0.005;
288 if not Incorrect_Inverse_Base_e
and
289 not FXA5A00
.Result_Within_Range
291 e
**(Float(j
)*EF
.Log
(Float(i
))),
294 Incorrect_Inverse_Base_e
:= True;
295 Report
.Failed
("Incorrect Log-** Inverse calc for Base e " &
296 "with i= " & Integer'Image(i
) & " and j= " &
299 if not Incorrect_Inverse_Base_2
and
300 not FXA5A00
.Result_Within_Range
302 2.0**(Float(j
)*EF
.Log
(Float(i
),2.0)),
305 Incorrect_Inverse_Base_2
:= True;
306 Report
.Failed
("Incorrect Log-** Inverse calc for Base 2 " &
307 "with i= " & Integer'Image(i
) & " and j= " &
310 if not Incorrect_Inverse_Base_8
and
311 not FXA5A00
.Result_Within_Range
313 8.0**(Float(j
)*EF
.Log
(Float(i
),8.0)),
316 Incorrect_Inverse_Base_8
:= True;
317 Report
.Failed
("Incorrect Log-** Inverse calc for Base 8 " &
318 "with i= " & Integer'Image(i
) & " and j= " &
321 if not Incorrect_Inverse_Base_10
and
322 not FXA5A00
.Result_Within_Range
324 10.0**(Float(j
)*EF
.Log
(Float(i
),10.0)),
327 Incorrect_Inverse_Base_10
:= True;
328 Report
.Failed
("Incorrect Log-** Inverse calc for Base 10 " &
329 "with i= " & Integer'Image(i
) & " and j= " &
332 if not Incorrect_Inverse_Base_16
and
333 not FXA5A00
.Result_Within_Range
335 16.0**(Float(j
)*EF
.Log
(Float(i
),16.0)),
338 Incorrect_Inverse_Base_16
:= True;
339 Report
.Failed
("Incorrect Log-** Inverse calc for Base 16 " &
340 "with i= " & Integer'Image(i
) & " and j= " &
348 Incorrect_Inverse_Base_e
:= False;
349 Incorrect_Inverse_Base_2
:= False;
350 Incorrect_Inverse_Base_8
:= False;
351 Incorrect_Inverse_Base_10
:= False;
352 Incorrect_Inverse_Base_16
:= False;
355 -- Testing of Exp Function, both instantiated and pre-instantiated
358 -- Check that the result of the Exp Function, when provided an X
359 -- parameter value of 0.0, is 1.0.
361 if GEF
.Exp
(X
=> 0.0) /= 1.0 or
364 Report
.Failed
("Incorrect result returned by Function Exp when " &
365 "given a parameter value of 0.0");
369 -- Check that the Exp Function provides correct results when provided
370 -- a variety of input parameter values.
372 if not Result_Within_Range
(GEF
.Exp
(0.001), 1.01, 0.01) or
373 not Result_Within_Range
( EF
.Exp
(0.1), 1.11, 0.01) or
374 not Result_Within_Range
(GEF
.Exp
(1.2697), 3.56, 0.01) or
375 not Result_Within_Range
( EF
.Exp
(3.2525), 25.9, 0.1) or
376 not Result_Within_Range
(GEF
.Exp
(-0.2198), 0.803, 0.001) or
377 not Result_Within_Range
( EF
.Exp
(-1.6621), 0.190, 0.001) or
378 not Result_Within_Range
(GEF
.Exp
(-2.3888), 0.092, 0.001) or
379 not Result_Within_Range
( EF
.Exp
(-5.4415), 0.004, 0.001)
381 Report
.Failed
("Incorrect result from Function Exp when provided " &
382 "a variety of input parameter values");
385 -- Use the following loops to check for internal consistency between
386 -- inverse functions.
389 while Arg
< 10.0 loop
390 if not Incorrect_Inverse_Base_e
and
391 FXA5A00
.Result_Within_Range
(EF
.Exp
(Arg
),
392 e
**(Arg
*EF
.Log
(Arg
)),
395 Incorrect_Inverse_Base_e
:= True;
396 Report
.Failed
("Incorrect Exp-** Inverse calc for Base e");
398 if not Incorrect_Inverse_Base_2
and
399 FXA5A00
.Result_Within_Range
(EF
.Exp
(Arg
),
400 2.0**(Arg
*EF
.Log
(Arg
,2.0)),
403 Incorrect_Inverse_Base_2
:= True;
404 Report
.Failed
("Incorrect Exp-** Inverse calc for Base 2");
406 if not Incorrect_Inverse_Base_8
and
407 FXA5A00
.Result_Within_Range
(EF
.Exp
(Arg
),
408 8.0**(Arg
*EF
.Log
(Arg
,8.0)),
411 Incorrect_Inverse_Base_8
:= True;
412 Report
.Failed
("Incorrect Exp-** Inverse calc for Base 8");
414 if not Incorrect_Inverse_Base_10
and
415 FXA5A00
.Result_Within_Range
(EF
.Exp
(Arg
),
416 10.0**(Arg
*EF
.Log
(Arg
,10.0)),
419 Incorrect_Inverse_Base_10
:= True;
420 Report
.Failed
("Incorrect Exp-** Inverse calc for Base 10");
422 if not Incorrect_Inverse_Base_16
and
423 FXA5A00
.Result_Within_Range
(EF
.Exp
(Arg
),
424 16.0**(Arg
*EF
.Log
(Arg
,16.0)),
427 Incorrect_Inverse_Base_16
:= True;
428 Report
.Failed
("Incorrect Exp-** Inverse calc for Base 16");
434 -- Testing of Sqrt Function, both instantiated and pre-instantiated
437 -- Check that Argument_Error is raised by the Sqrt Function when
438 -- the value of the input parameter X is negative.
441 Float_Result
:= EF
.Sqrt
(X
=> -FXA5A00
.Small
);
442 Report
.Failed
("Argument_Error not raised by Function Sqrt " &
443 "when provided a small negative input parameter " &
445 Dont_Optimize_Float
(Float_Result
, 7);
447 when Argument_Error
=> null; -- OK, expected exception.
449 Report
.Failed
("Unexpected exception raised by Function Sqrt " &
450 "when provided a small negative input parameter " &
455 New_Float_Result
:= GEF
.Sqrt
(X
=> -64.0);
456 Report
.Failed
("Argument_Error not raised by Function Sqrt " &
457 "when provided a large negative input parameter " &
459 Dont_Optimize_New_Float
(New_Float_Result
, 8);
461 when Argument_Error
=> null; -- OK, expected exception.
463 Report
.Failed
("Unexpected exception raised by Function Sqrt " &
464 "when provided a large negative input parameter " &
469 -- Check that the Sqrt Function, when given an X parameter value of 0.0,
470 -- returns a result of 0.0.
472 if GEF
.Sqrt
(X
=> 0.0) /= 0.0 or
475 Report
.Failed
("Incorrect result from Function Sqrt when provided " &
476 "an input parameter value of 0.0");
480 -- Check that the Sqrt Function, when given an X parameter input value
481 -- of 1.0, returns a result of 1.0.
483 if GEF
.Sqrt
(X
=> 1.0) /= 1.0 or
486 Report
.Failed
("Incorrect result from Function Sqrt when provided " &
487 "an input parameter value of 1.0");
491 -- Check that the Sqrt Function provides correct results when provided
492 -- a variety of input parameter values.
494 if not FXA5A00
.Result_Within_Range
(GEF
.Sqrt
(0.0327), 0.181, 0.001) or
495 not FXA5A00
.Result_Within_Range
( EF
.Sqrt
(0.1808), 0.425, 0.001) or
496 not FXA5A00
.Result_Within_Range
(GEF
.Sqrt
(1.0556), 1.03, 0.01) or
497 not FXA5A00
.Result_Within_Range
( EF
.Sqrt
(32.8208), 5.73, 0.01) or
498 not FXA5A00
.Result_Within_Range
( EF
.Sqrt
(27851.0), 166.9, 0.1) or
499 not FXA5A00
.Result_Within_Range
( EF
.Sqrt
(61203.4), 247.4, 0.1) or
500 not FXA5A00
.Result_Within_Range
( EF
.Sqrt
(655891.0), 809.9, 0.1)
502 Report
.Failed
("Incorrect result from Function Sqrt when provided " &
503 "a variety of input parameter values");
506 -- Check internal consistency between functions.
509 while Arg
< 10.0 loop
511 not FXA5A00
.Result_Within_Range
(Arg
,
512 EF
.Sqrt
(Arg
)*EF
.Sqrt
(Arg
),
515 Report
.Failed
("Inconsistency found in Case 1");
519 not FXA5A00
.Result_Within_Range
(Arg
, EF
.Sqrt
(Arg
)**2.0, 0.01)
521 Report
.Failed
("Inconsistency found in Case 2");
525 not FXA5A00
.Result_Within_Range
(EF
.Log
(Arg
),
526 EF
.Log
(Sqrt
(Arg
)**2.0), 0.01)
528 Report
.Failed
("Inconsistency found in Case 3");
532 not FXA5A00
.Result_Within_Range
(EF
.Log
(Arg
),
533 2.00*EF
.Log
(EF
.Sqrt
(Arg
)),
536 Report
.Failed
("Inconsistency found in Case 4");
544 when The_Error
: others =>
545 Report
.Failed
("The following exception was raised in the " &
546 "Test_Block: " & Exception_Name
(The_Error
));