cxg2016.a
来自「用于进行gcc测试」· A 代码 · 共 483 行 · 第 1/2 页
A
483 行
-- CXG2016.A---- Grant of Unlimited Rights---- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained-- unlimited rights in the software and documentation contained herein.-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making-- this public release, the Government intends to confer upon all-- recipients unlimited rights equal to those held by the Government.-- These rights include rights to use, duplicate, release or disclose the-- released technical data and computer software in whole or in part, in-- any manner and for any purpose whatsoever, and to have or permit others-- to do so.---- DISCLAIMER---- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A-- PARTICULAR PURPOSE OF SAID MATERIAL.--*---- OBJECTIVE:-- Check that the ARCTAN function returns a-- result that is within the error bound allowed.---- TEST DESCRIPTION:-- This test consists of a generic package that is-- instantiated to check both Float and a long float type.-- The test for each floating point type is divided into-- several parts:-- Special value checks where the result is a known constant.-- Exception checks.---- SPECIAL REQUIREMENTS-- The Strict Mode for the numerical accuracy must be-- selected. The method by which this mode is selected-- is implementation dependent.---- APPLICABILITY CRITERIA:-- This test applies only to implementations supporting the-- Numerics Annex.-- This test only applies to the Strict Mode for numerical-- accuracy.------ CHANGE HISTORY:-- 19 Mar 96 SAIC Initial release for 2.1-- 30 APR 96 SAIC Fixed optimization issue-- 17 AUG 96 SAIC Incorporated Reviewer's suggestions.-- 12 OCT 96 SAIC Incorporated Reviewer's suggestions.-- 02 DEC 97 EDS Remove procedure Identity_1_Test and calls to-- procedure.-- 29 JUN 98 EDS Replace -0.0 with call to ImpDef.Annex_G.Negative_Zero-- 28 APR 99 RLB Replaced comma accidentally deleted in above change.-- 15 DEC 99 RLB Added model range checking to "exact" results,-- in order to avoid too strictly requiring a specific-- result.--!---- References:---- Software Manual for the Elementary Functions-- William J. Cody, Jr. and William Waite-- Prentice-Hall, 1980---- CRC Standard Mathematical Tables-- 23rd Edition---- Implementation and Testing of Function Software-- W. J. Cody-- Problems and Methodologies in Mathematical Software Production-- editors P. C. Messina and A. Murli-- Lecture Notes in Computer Science Volume 142-- Springer Verlag, 1982--with System;with Report;with Ada.Numerics.Generic_Elementary_Functions;with Impdef.Annex_G;procedure CXG2016 is Verbose : constant Boolean := False; Max_Samples : constant := 1000; -- CRC Standard Mathematical Tables; 23rd Edition; pg 738 Sqrt2 : constant := 1.41421_35623_73095_04880_16887_24209_69807_85696_71875_37695; Sqrt3 : constant := 1.73205_08075_68877_29352_74463_41505_87236_69428_05253_81039; Pi : constant := Ada.Numerics.Pi; generic type Real is digits <>; Half_PI_Low : in Real; -- The machine number closest to, but not greater -- than PI/2.0. Half_PI_High : in Real;-- The machine number closest to, but not less -- than PI/2.0. PI_Low : in Real; -- The machine number closest to, but not greater -- than PI. PI_High : in Real; -- The machine number closest to, but not less -- than PI. package Generic_Check is procedure Do_Test; end Generic_Check; package body Generic_Check is package Elementary_Functions is new Ada.Numerics.Generic_Elementary_Functions (Real); function Arctan (Y : Real; X : Real := 1.0) return Real renames Elementary_Functions.Arctan; function Arctan (Y : Real; X : Real := 1.0; Cycle : Real) return Real renames Elementary_Functions.Arctan; -- flag used to terminate some tests early Accuracy_Error_Reported : Boolean := False; -- The following value is a lower bound on the accuracy -- required. It is normally 0.0 so that the lower bound -- is computed from Model_Epsilon. However, for tests -- where the expected result is only known to a certain -- amount of precision this bound takes on a non-zero -- value to account for that level of precision. Error_Low_Bound : Real := 0.0; procedure Check (Actual, Expected : Real; Test_Name : String; MRE : Real) is Max_Error : Real; Rel_Error : Real; Abs_Error : Real; begin -- In the case where the expected result is very small or 0 -- we compute the maximum error as a multiple of Model_Epsilon -- instead of Model_Epsilon and Expected. Rel_Error := MRE * abs Expected * Real'Model_Epsilon; Abs_Error := MRE * Real'Model_Epsilon; if Rel_Error > Abs_Error then Max_Error := Rel_Error; else Max_Error := Abs_Error; end if; -- take into account the low bound on the error if Max_Error < Error_Low_Bound then Max_Error := Error_Low_Bound; end if; if abs (Actual - Expected) > Max_Error then Accuracy_Error_Reported := True; Report.Failed (Test_Name & " actual: " & Real'Image (Actual) & " expected: " & Real'Image (Expected) & " difference: " & Real'Image (Actual - Expected) & " max err:" & Real'Image (Max_Error) ); elsif Verbose then if Actual = Expected then Report.Comment (Test_Name & " exact result"); else Report.Comment (Test_Name & " passed"); end if; end if; end Check; procedure Special_Value_Test is -- If eta is very small, arctan(x + eta) ~= arctan(x) + eta/(1+x*x). -- -- For tests 4 and 5, there is an error of 4.0ME for arctan + an -- additional error of 1.0ME because pi is not exact for a total of 5.0ME. -- -- In test 3 there is the error for pi plus an additional error -- of (1.0ME)/4 since sqrt3 is not exact, for a total of 5.25ME. -- -- In test 2 there is the error for pi plus an additional error -- of (3/4)(1.0ME) since sqrt3 is not exact, for a total of 5.75ME. type Data_Point is record Degrees, Radians, Tangent, Allowed_Error : Real; end record; type Test_Data_Type is array (Positive range <>) of Data_Point; -- the values in the following table only involve static -- expressions so no additional loss of precision occurs. Test_Data : constant Test_Data_Type := ( -- degrees radians tangent error test # ( 0.0, 0.0, 0.0, 4.0 ), -- 1 ( 30.0, Pi/6.0, Sqrt3/3.0, 5.75), -- 2 ( 60.0, Pi/3.0, Sqrt3, 5.25), -- 3 ( 45.0, Pi/4.0, 1.0, 5.0 ), -- 4 (-45.0, -Pi/4.0, -1.0, 5.0 ) ); -- 5 begin for I in Test_Data'Range loop Check (Arctan (Test_Data (I).Tangent), Test_Data (I).Radians, "special value test" & Integer'Image (I) & " arctan(" & Real'Image (Test_Data (I).Tangent) & ")", Test_Data (I).Allowed_Error); Check (Arctan (Test_Data (I).Tangent, Cycle => 360.0), Test_Data (I).Degrees, "special value test" & Integer'Image (I) & " arctan(" & Real'Image (Test_Data (I).Tangent) & ", cycle=>360)", Test_Data (I).Allowed_Error); end loop; exception when Constraint_Error => Report.Failed ("Constraint_Error raised in special value test"); when others => Report.Failed ("exception in special value test"); end Special_Value_Test; procedure Check_Exact (Actual, Expected_Low, Expected_High : Real; Test_Name : String) is -- If the expected result is not a model number, then Expected_Low is -- the first machine number less than the (exact) expected -- result, and Expected_High is the first machine number greater than -- the (exact) expected result. If the expected result is a model -- number, Expected_Low = Expected_High = the result. Model_Expected_Low : Real := Expected_Low;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?