annotate gcc/testsuite/ada/acats/tests/cxg/cxg2016.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CXG2016.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that the ARCTAN function returns a
kono
parents:
diff changeset
28 -- result that is within the error bound allowed.
kono
parents:
diff changeset
29 --
kono
parents:
diff changeset
30 -- TEST DESCRIPTION:
kono
parents:
diff changeset
31 -- This test consists of a generic package that is
kono
parents:
diff changeset
32 -- instantiated to check both Float and a long float type.
kono
parents:
diff changeset
33 -- The test for each floating point type is divided into
kono
parents:
diff changeset
34 -- several parts:
kono
parents:
diff changeset
35 -- Special value checks where the result is a known constant.
kono
parents:
diff changeset
36 -- Exception checks.
kono
parents:
diff changeset
37 --
kono
parents:
diff changeset
38 -- SPECIAL REQUIREMENTS
kono
parents:
diff changeset
39 -- The Strict Mode for the numerical accuracy must be
kono
parents:
diff changeset
40 -- selected. The method by which this mode is selected
kono
parents:
diff changeset
41 -- is implementation dependent.
kono
parents:
diff changeset
42 --
kono
parents:
diff changeset
43 -- APPLICABILITY CRITERIA:
kono
parents:
diff changeset
44 -- This test applies only to implementations supporting the
kono
parents:
diff changeset
45 -- Numerics Annex.
kono
parents:
diff changeset
46 -- This test only applies to the Strict Mode for numerical
kono
parents:
diff changeset
47 -- accuracy.
kono
parents:
diff changeset
48 --
kono
parents:
diff changeset
49 --
kono
parents:
diff changeset
50 -- CHANGE HISTORY:
kono
parents:
diff changeset
51 -- 19 Mar 96 SAIC Initial release for 2.1
kono
parents:
diff changeset
52 -- 30 APR 96 SAIC Fixed optimization issue
kono
parents:
diff changeset
53 -- 17 AUG 96 SAIC Incorporated Reviewer's suggestions.
kono
parents:
diff changeset
54 -- 12 OCT 96 SAIC Incorporated Reviewer's suggestions.
kono
parents:
diff changeset
55 -- 02 DEC 97 EDS Remove procedure Identity_1_Test and calls to
kono
parents:
diff changeset
56 -- procedure.
kono
parents:
diff changeset
57 -- 29 JUN 98 EDS Replace -0.0 with call to ImpDef.Annex_G.Negative_Zero
kono
parents:
diff changeset
58 -- 28 APR 99 RLB Replaced comma accidentally deleted in above change.
kono
parents:
diff changeset
59 -- 15 DEC 99 RLB Added model range checking to "exact" results,
kono
parents:
diff changeset
60 -- in order to avoid too strictly requiring a specific
kono
parents:
diff changeset
61 -- result.
kono
parents:
diff changeset
62 --!
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 --
kono
parents:
diff changeset
65 -- References:
kono
parents:
diff changeset
66 --
kono
parents:
diff changeset
67 -- Software Manual for the Elementary Functions
kono
parents:
diff changeset
68 -- William J. Cody, Jr. and William Waite
kono
parents:
diff changeset
69 -- Prentice-Hall, 1980
kono
parents:
diff changeset
70 --
kono
parents:
diff changeset
71 -- CRC Standard Mathematical Tables
kono
parents:
diff changeset
72 -- 23rd Edition
kono
parents:
diff changeset
73 --
kono
parents:
diff changeset
74 -- Implementation and Testing of Function Software
kono
parents:
diff changeset
75 -- W. J. Cody
kono
parents:
diff changeset
76 -- Problems and Methodologies in Mathematical Software Production
kono
parents:
diff changeset
77 -- editors P. C. Messina and A. Murli
kono
parents:
diff changeset
78 -- Lecture Notes in Computer Science Volume 142
kono
parents:
diff changeset
79 -- Springer Verlag, 1982
kono
parents:
diff changeset
80 --
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 with System;
kono
parents:
diff changeset
83 with Report;
kono
parents:
diff changeset
84 with Ada.Numerics.Generic_Elementary_Functions;
kono
parents:
diff changeset
85 with Impdef.Annex_G;
kono
parents:
diff changeset
86 procedure CXG2016 is
kono
parents:
diff changeset
87 Verbose : constant Boolean := False;
kono
parents:
diff changeset
88 Max_Samples : constant := 1000;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 -- CRC Standard Mathematical Tables; 23rd Edition; pg 738
kono
parents:
diff changeset
91 Sqrt2 : constant :=
kono
parents:
diff changeset
92 1.41421_35623_73095_04880_16887_24209_69807_85696_71875_37695;
kono
parents:
diff changeset
93 Sqrt3 : constant :=
kono
parents:
diff changeset
94 1.73205_08075_68877_29352_74463_41505_87236_69428_05253_81039;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 Pi : constant := Ada.Numerics.Pi;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 generic
kono
parents:
diff changeset
99 type Real is digits <>;
kono
parents:
diff changeset
100 Half_PI_Low : in Real; -- The machine number closest to, but not greater
kono
parents:
diff changeset
101 -- than PI/2.0.
kono
parents:
diff changeset
102 Half_PI_High : in Real;-- The machine number closest to, but not less
kono
parents:
diff changeset
103 -- than PI/2.0.
kono
parents:
diff changeset
104 PI_Low : in Real; -- The machine number closest to, but not greater
kono
parents:
diff changeset
105 -- than PI.
kono
parents:
diff changeset
106 PI_High : in Real; -- The machine number closest to, but not less
kono
parents:
diff changeset
107 -- than PI.
kono
parents:
diff changeset
108 package Generic_Check is
kono
parents:
diff changeset
109 procedure Do_Test;
kono
parents:
diff changeset
110 end Generic_Check;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 package body Generic_Check is
kono
parents:
diff changeset
113 package Elementary_Functions is new
kono
parents:
diff changeset
114 Ada.Numerics.Generic_Elementary_Functions (Real);
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 function Arctan (Y : Real;
kono
parents:
diff changeset
117 X : Real := 1.0) return Real renames
kono
parents:
diff changeset
118 Elementary_Functions.Arctan;
kono
parents:
diff changeset
119 function Arctan (Y : Real;
kono
parents:
diff changeset
120 X : Real := 1.0;
kono
parents:
diff changeset
121 Cycle : Real) return Real renames
kono
parents:
diff changeset
122 Elementary_Functions.Arctan;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 -- flag used to terminate some tests early
kono
parents:
diff changeset
125 Accuracy_Error_Reported : Boolean := False;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 -- The following value is a lower bound on the accuracy
kono
parents:
diff changeset
128 -- required. It is normally 0.0 so that the lower bound
kono
parents:
diff changeset
129 -- is computed from Model_Epsilon. However, for tests
kono
parents:
diff changeset
130 -- where the expected result is only known to a certain
kono
parents:
diff changeset
131 -- amount of precision this bound takes on a non-zero
kono
parents:
diff changeset
132 -- value to account for that level of precision.
kono
parents:
diff changeset
133 Error_Low_Bound : Real := 0.0;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 procedure Check (Actual, Expected : Real;
kono
parents:
diff changeset
136 Test_Name : String;
kono
parents:
diff changeset
137 MRE : Real) is
kono
parents:
diff changeset
138 Max_Error : Real;
kono
parents:
diff changeset
139 Rel_Error : Real;
kono
parents:
diff changeset
140 Abs_Error : Real;
kono
parents:
diff changeset
141 begin
kono
parents:
diff changeset
142 -- In the case where the expected result is very small or 0
kono
parents:
diff changeset
143 -- we compute the maximum error as a multiple of Model_Epsilon
kono
parents:
diff changeset
144 -- instead of Model_Epsilon and Expected.
kono
parents:
diff changeset
145 Rel_Error := MRE * abs Expected * Real'Model_Epsilon;
kono
parents:
diff changeset
146 Abs_Error := MRE * Real'Model_Epsilon;
kono
parents:
diff changeset
147 if Rel_Error > Abs_Error then
kono
parents:
diff changeset
148 Max_Error := Rel_Error;
kono
parents:
diff changeset
149 else
kono
parents:
diff changeset
150 Max_Error := Abs_Error;
kono
parents:
diff changeset
151 end if;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 -- take into account the low bound on the error
kono
parents:
diff changeset
154 if Max_Error < Error_Low_Bound then
kono
parents:
diff changeset
155 Max_Error := Error_Low_Bound;
kono
parents:
diff changeset
156 end if;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 if abs (Actual - Expected) > Max_Error then
kono
parents:
diff changeset
159 Accuracy_Error_Reported := True;
kono
parents:
diff changeset
160 Report.Failed (Test_Name &
kono
parents:
diff changeset
161 " actual: " & Real'Image (Actual) &
kono
parents:
diff changeset
162 " expected: " & Real'Image (Expected) &
kono
parents:
diff changeset
163 " difference: " & Real'Image (Actual - Expected) &
kono
parents:
diff changeset
164 " max err:" & Real'Image (Max_Error) );
kono
parents:
diff changeset
165 elsif Verbose then
kono
parents:
diff changeset
166 if Actual = Expected then
kono
parents:
diff changeset
167 Report.Comment (Test_Name & " exact result");
kono
parents:
diff changeset
168 else
kono
parents:
diff changeset
169 Report.Comment (Test_Name & " passed");
kono
parents:
diff changeset
170 end if;
kono
parents:
diff changeset
171 end if;
kono
parents:
diff changeset
172 end Check;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 procedure Special_Value_Test is
kono
parents:
diff changeset
176 -- If eta is very small, arctan(x + eta) ~= arctan(x) + eta/(1+x*x).
kono
parents:
diff changeset
177 --
kono
parents:
diff changeset
178 -- For tests 4 and 5, there is an error of 4.0ME for arctan + an
kono
parents:
diff changeset
179 -- additional error of 1.0ME because pi is not exact for a total of 5.0ME.
kono
parents:
diff changeset
180 --
kono
parents:
diff changeset
181 -- In test 3 there is the error for pi plus an additional error
kono
parents:
diff changeset
182 -- of (1.0ME)/4 since sqrt3 is not exact, for a total of 5.25ME.
kono
parents:
diff changeset
183 --
kono
parents:
diff changeset
184 -- In test 2 there is the error for pi plus an additional error
kono
parents:
diff changeset
185 -- of (3/4)(1.0ME) since sqrt3 is not exact, for a total of 5.75ME.
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 type Data_Point is
kono
parents:
diff changeset
189 record
kono
parents:
diff changeset
190 Degrees,
kono
parents:
diff changeset
191 Radians,
kono
parents:
diff changeset
192 Tangent,
kono
parents:
diff changeset
193 Allowed_Error : Real;
kono
parents:
diff changeset
194 end record;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 type Test_Data_Type is array (Positive range <>) of Data_Point;
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 -- the values in the following table only involve static
kono
parents:
diff changeset
199 -- expressions so no additional loss of precision occurs.
kono
parents:
diff changeset
200 Test_Data : constant Test_Data_Type := (
kono
parents:
diff changeset
201 -- degrees radians tangent error test #
kono
parents:
diff changeset
202 ( 0.0, 0.0, 0.0, 4.0 ), -- 1
kono
parents:
diff changeset
203 ( 30.0, Pi/6.0, Sqrt3/3.0, 5.75), -- 2
kono
parents:
diff changeset
204 ( 60.0, Pi/3.0, Sqrt3, 5.25), -- 3
kono
parents:
diff changeset
205 ( 45.0, Pi/4.0, 1.0, 5.0 ), -- 4
kono
parents:
diff changeset
206 (-45.0, -Pi/4.0, -1.0, 5.0 ) ); -- 5
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 begin
kono
parents:
diff changeset
209 for I in Test_Data'Range loop
kono
parents:
diff changeset
210 Check (Arctan (Test_Data (I).Tangent),
kono
parents:
diff changeset
211 Test_Data (I).Radians,
kono
parents:
diff changeset
212 "special value test" & Integer'Image (I) &
kono
parents:
diff changeset
213 " arctan(" &
kono
parents:
diff changeset
214 Real'Image (Test_Data (I).Tangent) &
kono
parents:
diff changeset
215 ")",
kono
parents:
diff changeset
216 Test_Data (I).Allowed_Error);
kono
parents:
diff changeset
217 Check (Arctan (Test_Data (I).Tangent, Cycle => 360.0),
kono
parents:
diff changeset
218 Test_Data (I).Degrees,
kono
parents:
diff changeset
219 "special value test" & Integer'Image (I) &
kono
parents:
diff changeset
220 " arctan(" &
kono
parents:
diff changeset
221 Real'Image (Test_Data (I).Tangent) &
kono
parents:
diff changeset
222 ", cycle=>360)",
kono
parents:
diff changeset
223 Test_Data (I).Allowed_Error);
kono
parents:
diff changeset
224 end loop;
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 exception
kono
parents:
diff changeset
227 when Constraint_Error =>
kono
parents:
diff changeset
228 Report.Failed ("Constraint_Error raised in special value test");
kono
parents:
diff changeset
229 when others =>
kono
parents:
diff changeset
230 Report.Failed ("exception in special value test");
kono
parents:
diff changeset
231 end Special_Value_Test;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 procedure Check_Exact (Actual, Expected_Low, Expected_High : Real;
kono
parents:
diff changeset
236 Test_Name : String) is
kono
parents:
diff changeset
237 -- If the expected result is not a model number, then Expected_Low is
kono
parents:
diff changeset
238 -- the first machine number less than the (exact) expected
kono
parents:
diff changeset
239 -- result, and Expected_High is the first machine number greater than
kono
parents:
diff changeset
240 -- the (exact) expected result. If the expected result is a model
kono
parents:
diff changeset
241 -- number, Expected_Low = Expected_High = the result.
kono
parents:
diff changeset
242 Model_Expected_Low : Real := Expected_Low;
kono
parents:
diff changeset
243 Model_Expected_High : Real := Expected_High;
kono
parents:
diff changeset
244 begin
kono
parents:
diff changeset
245 -- Calculate the first model number nearest to, but below (or equal)
kono
parents:
diff changeset
246 -- to the expected result:
kono
parents:
diff changeset
247 while Real'Model (Model_Expected_Low) /= Model_Expected_Low loop
kono
parents:
diff changeset
248 -- Try the next machine number lower:
kono
parents:
diff changeset
249 Model_Expected_Low := Real'Adjacent(Model_Expected_Low, 0.0);
kono
parents:
diff changeset
250 end loop;
kono
parents:
diff changeset
251 -- Calculate the first model number nearest to, but above (or equal)
kono
parents:
diff changeset
252 -- to the expected result:
kono
parents:
diff changeset
253 while Real'Model (Model_Expected_High) /= Model_Expected_High loop
kono
parents:
diff changeset
254 -- Try the next machine number higher:
kono
parents:
diff changeset
255 Model_Expected_High := Real'Adjacent(Model_Expected_High, 100.0);
kono
parents:
diff changeset
256 end loop;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 if Actual < Model_Expected_Low or Actual > Model_Expected_High then
kono
parents:
diff changeset
259 Accuracy_Error_Reported := True;
kono
parents:
diff changeset
260 if Actual < Model_Expected_Low then
kono
parents:
diff changeset
261 Report.Failed (Test_Name &
kono
parents:
diff changeset
262 " actual: " & Real'Image (Actual) &
kono
parents:
diff changeset
263 " expected low: " & Real'Image (Model_Expected_Low) &
kono
parents:
diff changeset
264 " expected high: " & Real'Image (Model_Expected_High) &
kono
parents:
diff changeset
265 " difference: " & Real'Image (Actual - Expected_Low));
kono
parents:
diff changeset
266 else
kono
parents:
diff changeset
267 Report.Failed (Test_Name &
kono
parents:
diff changeset
268 " actual: " & Real'Image (Actual) &
kono
parents:
diff changeset
269 " expected low: " & Real'Image (Model_Expected_Low) &
kono
parents:
diff changeset
270 " expected high: " & Real'Image (Model_Expected_High) &
kono
parents:
diff changeset
271 " difference: " & Real'Image (Expected_High - Actual));
kono
parents:
diff changeset
272 end if;
kono
parents:
diff changeset
273 elsif Verbose then
kono
parents:
diff changeset
274 Report.Comment (Test_Name & " passed");
kono
parents:
diff changeset
275 end if;
kono
parents:
diff changeset
276 end Check_Exact;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 procedure Exact_Result_Test is
kono
parents:
diff changeset
280 begin
kono
parents:
diff changeset
281 -- A.5.1(40);6.0
kono
parents:
diff changeset
282 Check_Exact (Arctan (0.0, 1.0), 0.0, 0.0, "arctan(0,1)");
kono
parents:
diff changeset
283 Check_Exact (Arctan (0.0, 1.0, 27.0), 0.0, 0.0, "arctan(0,1,27)");
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 -- G.2.4(11-13);6.0
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 Check_Exact (Arctan (1.0, 0.0), Half_PI_Low, Half_PI_High,
kono
parents:
diff changeset
288 "arctan(1,0)");
kono
parents:
diff changeset
289 Check_Exact (Arctan (1.0, 0.0, 360.0), 90.0, 90.0, "arctan(1,0,360)");
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 Check_Exact (Arctan (-1.0, 0.0), -Half_PI_High, -Half_PI_Low,
kono
parents:
diff changeset
292 "arctan(-1,0)");
kono
parents:
diff changeset
293 Check_Exact (Arctan (-1.0, 0.0, 360.0), -90.0, -90.0,
kono
parents:
diff changeset
294 "arctan(-1,0,360)");
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 if Real'Signed_Zeros then
kono
parents:
diff changeset
297 Check_Exact (Arctan (0.0, -1.0), PI_Low, PI_High, "arctan(+0,-1)");
kono
parents:
diff changeset
298 Check_Exact (Arctan (0.0, -1.0, 360.0), 180.0, 180.0,
kono
parents:
diff changeset
299 "arctan(+0,-1,360)");
kono
parents:
diff changeset
300 Check_Exact (Arctan ( Real ( ImpDef.Annex_G.Negative_Zero ), -1.0),
kono
parents:
diff changeset
301 -PI_High, -PI_Low, "arctan(-0,-1)");
kono
parents:
diff changeset
302 Check_Exact (Arctan ( Real ( ImpDef.Annex_G.Negative_Zero ), -1.0,
kono
parents:
diff changeset
303 360.0), -180.0, -180.0, "arctan(-0,-1,360)");
kono
parents:
diff changeset
304 else
kono
parents:
diff changeset
305 Check_Exact (Arctan (0.0, -1.0), PI_Low, PI_High, "arctan(0,-1)");
kono
parents:
diff changeset
306 Check_Exact (Arctan (0.0, -1.0, 360.0), 180.0, 180.0,
kono
parents:
diff changeset
307 "arctan(0,-1,360)");
kono
parents:
diff changeset
308 end if;
kono
parents:
diff changeset
309 exception
kono
parents:
diff changeset
310 when Constraint_Error =>
kono
parents:
diff changeset
311 Report.Failed ("Constraint_Error raised in Exact_Result Test");
kono
parents:
diff changeset
312 when others =>
kono
parents:
diff changeset
313 Report.Failed ("Exception in Exact_Result Test");
kono
parents:
diff changeset
314 end Exact_Result_Test;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 procedure Taylor_Series_Test is
kono
parents:
diff changeset
318 -- This test checks the Arctan by using a taylor series expansion that
kono
parents:
diff changeset
319 -- will produce a result accurate to 19 decimal digits for
kono
parents:
diff changeset
320 -- the range under test.
kono
parents:
diff changeset
321 --
kono
parents:
diff changeset
322 -- The maximum relative error bound for this test is
kono
parents:
diff changeset
323 -- 4 for the arctan operation and 2 for the Taylor series
kono
parents:
diff changeset
324 -- for a total of 6 * Model_Epsilon
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 A : constant := -1.0/16.0;
kono
parents:
diff changeset
327 B : constant := 1.0/16.0;
kono
parents:
diff changeset
328 X : Real;
kono
parents:
diff changeset
329 Actual, Expected : Real;
kono
parents:
diff changeset
330 Sum, Em, X_Squared : Real;
kono
parents:
diff changeset
331 begin
kono
parents:
diff changeset
332 if Real'Digits > 19 then
kono
parents:
diff changeset
333 -- Taylor series calculation produces result accurate to 19
kono
parents:
diff changeset
334 -- digits. If type being tested has more digits then set
kono
parents:
diff changeset
335 -- the error low bound to account for this.
kono
parents:
diff changeset
336 -- The error low bound is conservatively set to 6*10**-19
kono
parents:
diff changeset
337 Error_Low_Bound := 0.00000_00000_00000_0006;
kono
parents:
diff changeset
338 Report.Comment ("arctan accuracy checked to 19 digits");
kono
parents:
diff changeset
339 end if;
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 Accuracy_Error_Reported := False; -- reset
kono
parents:
diff changeset
342 for I in 0..Max_Samples loop
kono
parents:
diff changeset
343 X := (B - A) * Real (I) / Real (Max_Samples) + A;
kono
parents:
diff changeset
344 X_Squared := X * X;
kono
parents:
diff changeset
345 Em := 17.0;
kono
parents:
diff changeset
346 Sum := X_Squared / Em;
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 for II in 1 .. 7 loop
kono
parents:
diff changeset
349 Em := Em - 2.0;
kono
parents:
diff changeset
350 Sum := (1.0 / Em - Sum) * X_Squared;
kono
parents:
diff changeset
351 end loop;
kono
parents:
diff changeset
352 Sum := -X * Sum;
kono
parents:
diff changeset
353 Expected := X + Sum;
kono
parents:
diff changeset
354 Sum := (X - Expected) + Sum;
kono
parents:
diff changeset
355 if not Real'Machine_Rounds then
kono
parents:
diff changeset
356 Expected := Expected + (Sum + Sum);
kono
parents:
diff changeset
357 end if;
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 Actual := Arctan (X);
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 Check (Actual, Expected,
kono
parents:
diff changeset
362 "Taylor_Series_Test " & Integer'Image (I) & ": arctan(" &
kono
parents:
diff changeset
363 Real'Image (X) & ") ",
kono
parents:
diff changeset
364 6.0);
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 if Accuracy_Error_Reported then
kono
parents:
diff changeset
367 -- only report the first error in this test in order to keep
kono
parents:
diff changeset
368 -- lots of failures from producing a huge error log
kono
parents:
diff changeset
369 return;
kono
parents:
diff changeset
370 end if;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 end loop;
kono
parents:
diff changeset
373 Error_Low_Bound := 0.0; -- reset
kono
parents:
diff changeset
374 exception
kono
parents:
diff changeset
375 when Constraint_Error =>
kono
parents:
diff changeset
376 Report.Failed
kono
parents:
diff changeset
377 ("Constraint_Error raised in Taylor_Series_Test");
kono
parents:
diff changeset
378 when others =>
kono
parents:
diff changeset
379 Report.Failed ("exception in Taylor_Series_Test");
kono
parents:
diff changeset
380 end Taylor_Series_Test;
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 procedure Exception_Test is
kono
parents:
diff changeset
384 X1, X2, X3 : Real := 0.0;
kono
parents:
diff changeset
385 begin
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 begin -- A.5.1(20);6.0
kono
parents:
diff changeset
388 X1 := Arctan(0.0, Cycle => 0.0);
kono
parents:
diff changeset
389 Report.Failed ("no exception for cycle = 0.0");
kono
parents:
diff changeset
390 exception
kono
parents:
diff changeset
391 when Ada.Numerics.Argument_Error => null;
kono
parents:
diff changeset
392 when others =>
kono
parents:
diff changeset
393 Report.Failed ("wrong exception for cycle = 0.0");
kono
parents:
diff changeset
394 end;
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 begin -- A.5.1(20);6.0
kono
parents:
diff changeset
397 X2 := Arctan (0.0, Cycle => -1.0);
kono
parents:
diff changeset
398 Report.Failed ("no exception for cycle < 0.0");
kono
parents:
diff changeset
399 exception
kono
parents:
diff changeset
400 when Ada.Numerics.Argument_Error => null;
kono
parents:
diff changeset
401 when others =>
kono
parents:
diff changeset
402 Report.Failed ("wrong exception for cycle < 0.0");
kono
parents:
diff changeset
403 end;
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 begin -- A.5.1(25);6.0
kono
parents:
diff changeset
406 X3 := Arctan (0.0, 0.0);
kono
parents:
diff changeset
407 Report.Failed ("no exception for arctan(0,0)");
kono
parents:
diff changeset
408 exception
kono
parents:
diff changeset
409 when Ada.Numerics.Argument_Error => null;
kono
parents:
diff changeset
410 when others =>
kono
parents:
diff changeset
411 Report.Failed ("wrong exception for arctan(0,0)");
kono
parents:
diff changeset
412 end;
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 -- optimizer thwarting
kono
parents:
diff changeset
415 if Report.Ident_Bool (False) then
kono
parents:
diff changeset
416 Report.Comment (Real'Image (X1 + X2 + X3));
kono
parents:
diff changeset
417 end if;
kono
parents:
diff changeset
418 end Exception_Test;
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 procedure Do_Test is
kono
parents:
diff changeset
422 begin
kono
parents:
diff changeset
423 Special_Value_Test;
kono
parents:
diff changeset
424 Exact_Result_Test;
kono
parents:
diff changeset
425 Taylor_Series_Test;
kono
parents:
diff changeset
426 Exception_Test;
kono
parents:
diff changeset
427 end Do_Test;
kono
parents:
diff changeset
428 end Generic_Check;
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 -----------------------------------------------------------------------
kono
parents:
diff changeset
431 -----------------------------------------------------------------------
kono
parents:
diff changeset
432 -- These expressions must be truly static, which is why we have to do them
kono
parents:
diff changeset
433 -- outside of the generic, and we use the named numbers. Note that we know
kono
parents:
diff changeset
434 -- that PI is not a machine number (it is irrational), and it should be
kono
parents:
diff changeset
435 -- represented to more digits than supported by the target machine.
kono
parents:
diff changeset
436 Float_Half_PI_Low : constant := Float'Adjacent(PI/2.0, 0.0);
kono
parents:
diff changeset
437 Float_Half_PI_High : constant := Float'Adjacent(PI/2.0, 10.0);
kono
parents:
diff changeset
438 Float_PI_Low : constant := Float'Adjacent(PI, 0.0);
kono
parents:
diff changeset
439 Float_PI_High : constant := Float'Adjacent(PI, 10.0);
kono
parents:
diff changeset
440 package Float_Check is new Generic_Check (Float,
kono
parents:
diff changeset
441 Half_PI_Low => Float_Half_PI_Low,
kono
parents:
diff changeset
442 Half_PI_High => Float_Half_PI_High,
kono
parents:
diff changeset
443 PI_Low => Float_PI_Low,
kono
parents:
diff changeset
444 PI_High => Float_PI_High);
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 -- check the Floating point type with the most digits
kono
parents:
diff changeset
447 type A_Long_Float is digits System.Max_Digits;
kono
parents:
diff changeset
448 A_Long_Float_Half_PI_Low : constant := A_Long_Float'Adjacent(PI/2.0, 0.0);
kono
parents:
diff changeset
449 A_Long_Float_Half_PI_High : constant := A_Long_Float'Adjacent(PI/2.0, 10.0);
kono
parents:
diff changeset
450 A_Long_Float_PI_Low : constant := A_Long_Float'Adjacent(PI, 0.0);
kono
parents:
diff changeset
451 A_Long_Float_PI_High : constant := A_Long_Float'Adjacent(PI, 10.0);
kono
parents:
diff changeset
452 package A_Long_Float_Check is new Generic_Check (A_Long_Float,
kono
parents:
diff changeset
453 Half_PI_Low => A_Long_Float_Half_PI_Low,
kono
parents:
diff changeset
454 Half_PI_High => A_Long_Float_Half_PI_High,
kono
parents:
diff changeset
455 PI_Low => A_Long_Float_PI_Low,
kono
parents:
diff changeset
456 PI_High => A_Long_Float_PI_High);
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 -----------------------------------------------------------------------
kono
parents:
diff changeset
459 -----------------------------------------------------------------------
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 begin
kono
parents:
diff changeset
463 Report.Test ("CXG2016",
kono
parents:
diff changeset
464 "Check the accuracy of the ARCTAN function");
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 if Verbose then
kono
parents:
diff changeset
467 Report.Comment ("checking Standard.Float");
kono
parents:
diff changeset
468 end if;
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 Float_Check.Do_Test;
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 if Verbose then
kono
parents:
diff changeset
473 Report.Comment ("checking a digits" &
kono
parents:
diff changeset
474 Integer'Image (System.Max_Digits) &
kono
parents:
diff changeset
475 " floating point type");
kono
parents:
diff changeset
476 end if;
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 A_Long_Float_Check.Do_Test;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 Report.Result;
kono
parents:
diff changeset
482 end CXG2016;