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 Argument 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 Argument function.
35 -- Of special interest is the case where either the real or
36 -- the imaginary part of the parameter is very large while the
37 -- other part is very small or 0.
39 -- SPECIAL REQUIREMENTS
40 -- The Strict Mode for the numerical accuracy must be
41 -- selected. The method by which this mode is selected
42 -- is implementation dependent.
44 -- APPLICABILITY CRITERIA:
45 -- This test applies only to implementations supporting the
47 -- This test only applies to the Strict Mode for numerical
52 -- 15 FEB 96 SAIC Initial release for 2.1
53 -- 03 MAR 97 PWB.CTA Removed checks involving explicit cycle => 2.0*Pi
56 -- According to Ken Dritz, author of the Numerics Annex of the RM,
57 -- one should never specify the cycle 2.0*Pi for the trigonometric
58 -- functions. In particular, if the machine number for the first
59 -- argument is not an exact multiple of the machine number for the
60 -- explicit cycle, then the specified exact results cannot be
61 -- reasonably expected. The affected checks in this test have been
62 -- marked as comments, with the additional notation "pwb-math".
68 -- Problems and Methodologies in Mathematical Software Production;
69 -- editors: P. C. Messina and A Murli;
70 -- Lecture Notes in Computer Science
72 -- Springer Verlag 1982
79 with Ada
.Numerics
.Generic_Complex_Types
;
80 with Ada
.Numerics
.Complex_Types
;
82 Verbose
: constant Boolean := False;
85 -- CRC Standard Mathematical Tables; 23rd Edition; pg 738
87 1.41421_35623_73095_04880_16887_24209_69807_85696_71875_37695
;
89 1.73205_08075_68877_29352_74463_41505_87236_69428_05253_81039
;
91 Pi
: constant := Ada
.Numerics
.Pi
;
94 type Real
is digits <>;
95 package Generic_Check
is
99 package body Generic_Check
is
100 package Complex_Types
is new
101 Ada
.Numerics
.Generic_Complex_Types
(Real
);
105 procedure Check
(Actual
, Expected
: Real
;
112 -- In the case where the expected result is very small or 0
113 -- we compute the maximum error as a multiple of Model_Epsilon instead
114 -- of Model_Epsilon and Expected.
115 Rel_Error
:= MRE
* abs Expected
* Real
'Model_Epsilon;
116 Abs_Error
:= MRE
* Real
'Model_Epsilon;
117 if Rel_Error
> Abs_Error
then
118 Max_Error
:= Rel_Error
;
120 Max_Error
:= Abs_Error
;
123 if abs (Actual
- Expected
) > Max_Error
then
124 Report
.Failed
(Test_Name
&
125 " actual: " & Real
'Image (Actual
) &
126 " expected: " & Real
'Image (Expected
) &
128 Real
'Image (Actual
- Expected
) &
129 " mre:" & Real
'Image (Max_Error
) );
131 if Actual
= Expected
then
132 Report
.Comment
(Test_Name
& " exact result");
134 Report
.Comment
(Test_Name
& " passed");
140 procedure Special_Cases
is
150 type Test_Data_Type
is array (Positive range <>) of Data_Point
;
152 -- the values in the following table only involve static
153 -- expressions to minimize errors in precision introduced by the
154 -- test. For cases where Pi is used in the argument we must
155 -- allow an extra 1.0*MRE to account for roundoff error in the
156 -- argument. Where the result involves a square root we allow
157 -- an extra 0.5*MRE to allow for roundoff error.
158 Test_Data
: constant Test_Data_Type
:= (
159 -- Re Im Radians Degrees Err Test #
160 (0.0, 0.0, 0.0, 0.0, 4.0 ), -- 1
161 (1.0, 0.0, 0.0, 0.0, 4.0 ), -- 2
162 (Real
'Safe_Last, 0.0, 0.0, 0.0, 4.0 ), -- 3
163 (Real
'Model_Small, 0.0, 0.0, 0.0, 4.0 ), -- 4
164 (1.0, 1.0, Pi
/4.0, 45.0, 5.0 ), -- 5
165 (1.0, -1.0, -Pi
/4.0, -45.0, 5.0 ), -- 6
166 (-1.0, -1.0, -3.0*Pi
/4.0,-135.0, 5.0 ), -- 7
167 (-1.0, 1.0, 3.0*Pi
/4.0, 135.0, 5.0 ), -- 8
168 (Sqrt3
, 1.0, Pi
/6.0, 30.0, 5.5 ), -- 9
169 (-Sqrt3
, 1.0, 5.0*Pi
/6.0, 150.0, 5.5 ), -- 10
170 (Sqrt3
, -1.0, -Pi
/6.0, -30.0, 5.5 ), -- 11
171 (-Sqrt3
, -1.0, -5.0*Pi
/6.0,-150.0, 5.5 ), -- 12
172 (Real
'Model_Small, Real
'Model_Small, Pi
/4.0, 45.0, 5.0 ), -- 13
173 (-Real
'Safe_Last, 0.0, Pi
, 180.0, 5.0 ), -- 14
174 (-Real
'Safe_Last, -Real
'Model_Small, -Pi
,-180.0, 5.0 ), -- 15
175 (100000.0, 100000.0, Pi
/4.0, 45.0, 5.0 )); -- 16
180 for I
in Test_Data
'Range loop
182 Z
:= (Test_Data
(I
).Re
, Test_Data
(I
).Im
);
184 Check
(X
, Test_Data
(I
).Radians
,
185 "test" & Integer'Image (I
) & " argument(z)",
186 Test_Data
(I
).Error_Bound
);
187 --pwb-math X := Argument (Z, 2.0*Pi);
188 --pwb-math Check (X, Test_Data(I).Radians,
189 --pwb-math "test" & Integer'Image (I) & " argument(z, 2pi)",
190 --pwb-math Test_Data (I).Error_Bound);
191 X
:= Argument
(Z
, 360.0);
192 Check
(X
, Test_Data
(I
).Degrees
,
193 "test" & Integer'Image (I
) & " argument(z, 360)",
194 Test_Data
(I
).Error_Bound
);
197 when Constraint_Error
=>
198 Report
.Failed
("Constraint_Error raised in test" &
201 Report
.Failed
("exception in test" &
206 if Real
'Signed_Zeros then
208 X
:= Argument
((-1.0, Real
(ImpDef
.Annex_G
.Negative_Zero
)));
209 Check
(X
, -Pi
, "test of arg((-1,-0)", 4.0);
212 Report
.Failed
("exception in signed zero test");
218 procedure Exception_Cases
is
219 -- check that Argument_Error is raised if Cycle is <= 0
220 Z
: Complex
:= (1.0, 1.0);
225 X
:= Argument
(Z
, Cycle
=> 0.0);
226 Report
.Failed
("no exception for cycle = 0.0");
228 when Ada
.Numerics
.Argument_Error
=> null;
230 Report
.Failed
("wrong exception for cycle = 0.0");
234 Y
:= Argument
(Z
, Cycle
=> -3.0);
235 Report
.Failed
("no exception for cycle < 0.0");
237 when Ada
.Numerics
.Argument_Error
=> null;
239 Report
.Failed
("wrong exception for cycle < 0.0");
242 if Report
.Ident_Int
(2) = 1 then
243 -- optimization thwarting code - never executed
244 Report
.Failed
("2=1" & Real
'Image (X
+Y
));
256 package Chk_Float
is new Generic_Check
(Float);
258 -- check the floating point type with the most digits
259 type A_Long_Float
is digits System
.Max_Digits
;
260 package Chk_A_Long_Float
is new Generic_Check
(A_Long_Float
);
262 Report
.Test
("CXG2006",
263 "Check the accuracy of the complex argument" &
267 Report
.Comment
("checking Standard.Float");
273 Report
.Comment
("checking a digits" &
274 Integer'Image (System
.Max_Digits
) &
275 " floating point type");
278 Chk_A_Long_Float
.Do_Test
;