cxa5a10.a

来自「linux下编程用 编译软件」· A 代码 · 共 552 行 · 第 1/2 页

A
552
字号
-- CXA5A10.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 functions Exp and Sqrt, and the exponentiation--      operator "**" provide correct results.---- TEST DESCRIPTION:--      This test examines both the versions of Exp, Sqrt, and "**"--      resulting from the instantiation of the--      Ada.Numerics.Generic_Elementary_Functions with a type derived from--      type Float, as well as the preinstantiated version of this package--      for type Float.--      Prescribed results (stated as such in the reference manual),--      including instances prescribed to raise exceptions, are examined--      in the test cases.  In addition, certain evaluations are performed--      for the preinstantiated package where the actual function result is--      compared with the expected result (within an epsilon range of--      accuracy).---- TEST FILES:--      The following files comprise this test:----         FXA5A00.A   (foundation code)--         CXA5A10.A------ CHANGE HISTORY:--      17 Apr 95   SAIC    Initial prerelease version.--      13 Jun 95   SAIC    Incorporated use of Dont_Optimize procedure, and--                          use of Result_Within_Range function overloaded for--                          FXA5A00.New_Float_Type.--      18 Apr 96   SAIC    Incorporated reviewer comments for ACVC 2.1.--      01 Oct 01   RLB     Protected Constraint_Error exception tests by--                          first testing for 'Machine_Overflows.----!with Ada.Exceptions;with Ada.Numerics.Elementary_Functions;with Ada.Numerics.Generic_Elementary_Functions;with FXA5A00;with Report;procedure CXA5A10 isbegin   Report.Test ("CXA5A10", "Check that Exp, Sqrt, and the ""**"" operator " &                           "provide correct results");   Test_Block:   declare      use FXA5A00, Ada.Numerics;      use Ada.Exceptions;      package GEF is new Ada.Numerics.Generic_Elementary_Functions(New_Float);      package  EF renames Ada.Numerics.Elementary_Functions;      use GEF, EF;      Arg,      Float_Result     : Float;      New_Float_Result : New_Float;      Flag_1, Flag_2, Flag_3, Flag_4,      Incorrect_Inverse_Base_e,      Incorrect_Inverse_Base_2,      Incorrect_Inverse_Base_8,      Incorrect_Inverse_Base_10,      Incorrect_Inverse_Base_16        : Boolean := False;      procedure Dont_Optimize_Float     is new Dont_Optimize(Float);      procedure Dont_Optimize_New_Float is new Dont_Optimize(New_Float);   begin      -- Testing of the "**" operator, both instantiated and pre-instantiated      -- version.      -- Check that Argument_Error is raised by the exponentiation operator      -- when the value of the Left parameter (operand) is negative.      begin         New_Float_Result := GEF."**"(Left  => -10.0,                                      Right =>   2.0);         Report.Failed("Argument_Error not raised by the instantiated "   &                       "version of the exponentiation operator when the " &                       "value of the Left parameter is negative");         Dont_Optimize_New_Float(New_Float_Result, 1);      exception         when Argument_Error => null;  -- OK, expected exception.         when others         =>            Report.Failed("Unexpected exception raised by the "            &                          "instantiated version of the exponentiation "    &                          "operator when the value of the Left parameter " &                          "is negative");      end;      begin         Float_Result := (-FXA5A00.Small) ** 4.0;         Report.Failed("Argument_Error not raised by the preinstantiated " &                       "version of the exponentiation operator when the "  &                       "value of the Left parameter is negative");         Dont_Optimize_Float(Float_Result, 2);      exception         when Argument_Error => null;  -- OK, expected exception.         when others         =>            Report.Failed("Unexpected exception raised by the "            &                          "preinstantiated version of the exponentiation " &                          "operator when the value of the Left parameter " &                          "is negative");      end;      -- Check that Argument_Error is raised by the exponentiation operator      -- when both parameters (operands) have the value 0.0.      begin         New_Float_Result := GEF."**"(0.0, Right => 0.0);         Report.Failed("Argument_Error not raised by the instantiated " &                       "version of the exponentiation operator when "   &                       "both operands are zero");         Dont_Optimize_New_Float(New_Float_Result, 3);      exception         when Argument_Error => null;  -- OK, expected exception.         when others         =>            Report.Failed("Unexpected exception raised by the "         &                          "instantiated version of the exponentiation " &                          "operator when both operands are zero");      end;      begin         Float_Result := 0.0**0.0;         Report.Failed("Argument_Error not raised by the preinstantiated " &                       "version of the exponentiation operator when both " &                       "operands are zero");         Dont_Optimize_Float(Float_Result, 4);      exception         when Argument_Error => null;  -- OK, expected exception.         when others         =>            Report.Failed("Unexpected exception raised by the "            &                          "preinstantiated version of the exponentiation " &                          "operator when both operands are zero");      end;      -- Check that Constraint_Error is raised by the exponentiation      -- operator when the value of the left parameter (operand) is zero,      -- and the value of the right parameter (exponent) is negative.      -- This check applies only if Machine_Overflows is true [A.5.1(28, 30)].      if New_Float'Machine_Overflows = True then         begin            New_Float_Result := GEF."**"(0.0, Right => -2.0);            Report.Failed("Constraint_Error not raised by the instantiated " &                          "version of the exponentiation operator when "     &                          "the left parameter is 0.0, and the right "        &                          "parameter is negative");            Dont_Optimize_New_Float(New_Float_Result, 5);         exception            when Constraint_Error => null;  -- OK, expected exception.            when others           =>               Report.Failed("Unexpected exception raised by the "         &                             "instantiated version of the exponentiation " &                             "operator when the left parameter is 0.0, "   &                             "and the right parameter is negative");         end;      end if;      if Float'Machine_Overflows = True then         begin            Float_Result := 0.0 ** (-FXA5A00.Small);            Report.Failed("Constraint_Error not raised by the " &                          "preinstantiated version of the exponentiation " &                          "operator when the left parameter is 0.0, and the " &                          "right parameter is negative");            Dont_Optimize_Float(Float_Result, 6);         exception            when Constraint_Error => null;  -- OK, expected exception.            when others           =>               Report.Failed("Unexpected exception raised by the "            &                             "preinstantiated version of the exponentiation " &                             "operator when the left parameter is 0.0, and "  &                             "the right parameter is negative");         end;      end if;      -- Prescribed results.      -- Check that exponentiation by a 0.0 exponent yields the value one.      if GEF."**"(Left => 10.0,  Right => 0.0) /= 1.0 or          EF."**"(FXA5A00.Large, Right => 0.0) /= 1.0 or         GEF."**"(3.0, 0.0)                    /= 1.0 or          FXA5A00.Small ** 0.0                 /= 1.0      then         Report.Failed("Incorrect results returned from the ""**"" " &                       "operator when the value of the exponent is 0.0");      end if;      -- Check that exponentiation by a unit exponent yields the value      -- of the left operand.      if GEF."**"(Left => 50.0,  Right => 1.0) /= 50.0          or          EF."**"(FXA5A00.Large, Right => 1.0) /= FXA5A00.Large or         GEF."**"(6.0, 1.0)                    /= 6.0           or          FXA5A00.Small ** 1.0                 /= FXA5A00.Small      then         Report.Failed("Incorrect results returned from the ""**"" " &                       "operator when the value of the exponent is 1.0");      end if;      -- Check that exponentiation of the value 1.0 yields the value 1.0.      if GEF."**"(Left => 1.0, Right => 16.0)   /=  1.0 or          EF."**"(1.0, Right => FXA5A00.Large)  /=  1.0 or         GEF."**"(1.0, 3.0)                     /=  1.0 or          1.0 ** FXA5A00.Small                  /=  1.0      then         Report.Failed("Incorrect results returned from the ""**"" " &                       "operator when the value of the operand is 1.0");      end if;      -- Check that exponentiation of the value 0.0 yields the value 0.0.      if GEF."**"(Left => 0.0, Right => 10.0)   /=  0.0 or          EF."**"(0.0, Right => FXA5A00.Large)  /=  0.0 or         GEF."**"(0.0, 4.0)                     /=  0.0 or          0.0 ** FXA5A00.Small                  /=  0.0      then         Report.Failed("Incorrect results returned from the ""**"" " &                       "operator when the value of the operand is 0.0");      end if;      -- Check that exponentiation of various operands with a variety of      -- of exponent values yield correct results.      if not Result_Within_Range(GEF."**"(5.0,   2.0),  25.0,   0.01)  or         not Result_Within_Range(GEF."**"(1.225, 1.5),   1.36,  0.01)  or         not Result_Within_Range(GEF."**"(0.26,  2.0),   0.068, 0.001) or         not Result_Within_Range( EF."**"(e,     5.0), 148.4,   0.1)   or         not Result_Within_Range( EF."**"(10.0,  e),   522.7,   0.1)   or         not Result_Within_Range( EF."**"(e,   (-3.0)),  0.050, 0.001) or         not Result_Within_Range(GEF."**"(10.0,(-2.0)),  0.010, 0.001)      then         Report.Failed("Incorrect results returned from the ""**"" "       &                       "operator with a variety of  operand and exponent " &                       "values");      end if;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?