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 complex Compose_From_Polar function returns
28 -- results that are within the error bound allowed.
29 -- Check that Argument_Error is raised if the Cycle parameter
30 -- is less than or equal to zero.
33 -- This test uses a generic package to compute and check the
34 -- values of the Compose_From_Polar function.
36 -- SPECIAL REQUIREMENTS
37 -- The Strict Mode for the numerical accuracy must be
38 -- selected. The method by which this mode is selected
39 -- is implementation dependent.
41 -- APPLICABILITY CRITERIA:
42 -- This test applies only to implementations supporting the
44 -- This test only applies to the Strict Mode for numerical
49 -- 23 FEB 96 SAIC Initial release for 2.1
50 -- 23 APR 96 SAIC Fixed error checking
51 -- 03 MAR 97 PWB.CTA Deleted checks with explicit Cycle => 2.0*Pi
54 -- According to Ken Dritz, author of the Numerics Annex of the RM,
55 -- one should never specify the cycle 2.0*Pi for the trigonometric
56 -- functions. In particular, if the machine number for the first
57 -- argument is not an exact multiple of the machine number for the
58 -- explicit cycle, then the specified exact results cannot be
59 -- reasonably expected. The affected checks in this test have been
60 -- marked as comments, with the additional notation "pwb-math".
67 with Ada
.Numerics
.Generic_Complex_Types
;
69 Verbose
: constant Boolean := False;
72 -- CRC Standard Mathematical Tables; 23rd Edition; pg 738
74 1.41421_35623_73095_04880_16887_24209_69807_85696_71875_37695
;
76 1.73205_08075_68877_29352_74463_41505_87236_69428_05253_81039
;
78 Pi
: constant := Ada
.Numerics
.Pi
;
81 type Real
is digits <>;
82 package Generic_Check
is
86 package body Generic_Check
is
87 package Complex_Types
is new
88 Ada
.Numerics
.Generic_Complex_Types
(Real
);
91 Maximum_Relative_Error
: constant Real
:= 3.0;
93 procedure Check
(Actual
, Expected
: Real
;
97 -- Arg_Error is additional absolute error that is allowed beyond
98 -- the MRE to account for error in the result that can be
99 -- attributed to error in the arguments.
104 -- In the case where the expected result is very small or 0
105 -- we compute the maximum error as a multiple of Model_Small instead
106 -- of Model_Epsilon and Expected.
107 Rel_Error
:= MRE
* abs Expected
* Real
'Model_Epsilon;
108 Abs_Error
:= MRE
* Real
'Model_Epsilon;
109 if Rel_Error
> Abs_Error
then
110 Max_Error
:= Rel_Error
;
112 Max_Error
:= Abs_Error
;
114 Max_Error
:= Max_Error
+ Arg_Error
;
116 if abs (Actual
- Expected
) > Max_Error
then
117 Report
.Failed
(Test_Name
&
118 " actual: " & Real
'Image (Actual
) &
119 " expected: " & Real
'Image (Expected
) &
120 " difference: " & Real
'Image (Actual
- Expected
) &
121 " max err:" & Real
'Image (Max_Error
) );
123 if Actual
= Expected
then
124 Report
.Comment
(Test_Name
& " exact result");
126 Report
.Comment
(Test_Name
& " passed");
132 procedure Check
(Actual
, Expected
: Complex
;
136 -- Arg_Error is additional absolute error that is allowed beyond
137 -- the MRE to account for error in the result that can be
138 -- attributed to error in the arguments.
140 Check
(Actual
.Re
, Expected
.Re
,
141 Test_Name
& " real part",
143 Check
(Actual
.Im
, Expected
.Im
,
144 Test_Name
& " imaginary part",
149 procedure Special_Cases
is
160 -- shorthand names for various constants
161 P4
: constant := Pi
/4.0;
162 P6
: constant := Pi
/6.0;
164 MER2
: constant Real
:= Real
'Model_Epsilon * Sqrt2
;
166 type Test_Data_Type
is array (Positive range <>) of Data_Point
;
168 -- the values in the following table only involve static
169 -- expressions so no loss of precision occurs.
170 Test_Data
: constant Test_Data_Type
:= (
171 --Re Im Modulus Radians Degrees Arg_Err
172 ( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ), -- 1
173 ( 0.0, 0.0, 0.0, Pi
, 180.0, 0.0 ), -- 2
175 ( 1.0, 0.0, 1.0, 0.0, 0.0, 0.0 ), -- 3
176 (-1.0, 0.0, -1.0, 0.0, 0.0, 0.0 ), -- 4
178 ( 1.0, 1.0, Sqrt2
, P4
, 45.0, MER2
), -- 5
179 (-1.0, 1.0, -Sqrt2
, -P4
, -45.0, MER2
), -- 6
180 ( 1.0, -1.0, Sqrt2
, -P4
, -45.0, MER2
), -- 7
181 (-1.0, -1.0, -Sqrt2
, P4
, 45.0, MER2
), -- 8
182 (-1.0, -1.0, Sqrt2
, -3.0*P4
,-135.0, MER2
), -- 9
183 (-1.0, 1.0, Sqrt2
, 3.0*P4
, 135.0, MER2
), -- 10
184 ( 1.0, -1.0, -Sqrt2
, 3.0*P4
, 135.0, MER2
), -- 11
186 (-1.0, 0.0, 1.0, Pi
, 180.0, 0.0 ), -- 12
187 ( 1.0, 0.0, -1.0, Pi
, 180.0, 0.0 ) ); -- 13
193 for I
in Test_Data
'Range loop
195 Exp
:= (Test_Data
(I
).Re
, Test_Data
(I
).Im
);
197 Z
:= Compose_From_Polar
(Test_Data
(I
).Modulus
,
198 Test_Data
(I
).Radians
);
200 "test" & Integer'Image (I
) & " compose_from_polar(m,r)",
201 Maximum_Relative_Error
, Test_Data
(I
).Arg_Error
);
203 --pwb-math Z := Compose_From_Polar (Test_Data (I).Modulus,
204 --pwb-math Test_Data (I).Radians,
206 --pwb-math Check (Z, Exp,
207 --pwb-math "test" & Integer'Image (I) & " compose_from_polar(m,r,2pi)",
208 --pwb-math Maximum_Relative_Error, Test_Data (I).Arg_Error);
210 Z
:= Compose_From_Polar
(Test_Data
(I
).Modulus
,
211 Test_Data
(I
).Degrees
,
214 "test" & Integer'Image (I
) & " compose_from_polar(m,d,360)",
215 Maximum_Relative_Error
, Test_Data
(I
).Arg_Error
);
218 when Constraint_Error
=>
219 Report
.Failed
("Constraint_Error raised in test" &
222 Report
.Failed
("exception in test" &
229 procedure Exception_Cases
is
230 -- check that Argument_Error is raised if Cycle is <= 0
235 Z
:= Compose_From_Polar
(3.0, 0.0, Cycle
=> 0.0);
236 Report
.Failed
("no exception for cycle = 0.0");
238 when Ada
.Numerics
.Argument_Error
=> null;
240 Report
.Failed
("wrong exception for cycle = 0.0");
244 W
:= Compose_From_Polar
(6.0, 1.0, Cycle
=> -10.0);
245 Report
.Failed
("no exception for cycle < 0.0");
247 when Ada
.Numerics
.Argument_Error
=> null;
249 Report
.Failed
("wrong exception for cycle < 0.0");
252 if Report
.Ident_Int
(1) = 2 then
253 -- not executed - used to make it appear that we use the
254 -- results of the above computation
256 Report
.Failed
(Real
'Image (Z
.Re
+ Z
.Im
));
268 package Chk_Float
is new Generic_Check
(Float);
270 -- check the floating point type with the most digits
271 type A_Long_Float
is digits System
.Max_Digits
;
272 package Chk_A_Long_Float
is new Generic_Check
(A_Long_Float
);
274 Report
.Test
("CXG2007",
275 "Check the accuracy of the Compose_From_Polar" &
279 Report
.Comment
("checking Standard.Float");
284 Report
.Comment
("checking a digits" &
285 Integer'Image (System
.Max_Digits
) &
286 " floating point type");
288 Chk_A_Long_Float
.Do_Test
;