cxg2011.a
来自「linux下编程用 编译软件」· A 代码 · 共 491 行 · 第 1/2 页
A
491 行
-- only report the first error in this test in order to keep -- lots of failures from producing a huge error log return; end if; end loop; exception when Constraint_Error => Report.Failed ("Constraint_Error raised in Taylor Series Test"); when others => Report.Failed ("exception in Taylor Series Test"); end Taylor_Series_Test; procedure Log_Difference_Identity is -- Check using the identity ln(x) = ln(17x/16) - ln(17/16) -- over the range A to B. -- The selected range assures that both X and 17x/16 will -- have the same exponents and neither argument gets too close -- to 1. Cody pg 50. A : constant Real := 1.0 / Sqrt (2.0); B : constant Real := 15.0 / 16.0; X : Real; Expected : Real; Actual : Real; begin Accuracy_Error_Reported := False; -- reset for I in 1..Max_Samples loop X := (B - A) * Real (I) / Real (Max_Samples) + A; -- magic argument purification X := Real'Machine (Real'Machine (X+8.0) - 8.0); Expected := Log (X + X / 16.0) - Log (17.0/16.0); Actual := Log (X); Check (Actual, Expected, "Log Difference Identity -" & Integer'Image (I) & " log (" & Real'Image (X) & ")", 4.0); if Accuracy_Error_Reported then -- only report the first error in this test in order to keep -- lots of failures from producing a huge error log return; end if; end loop; exception when Constraint_Error => Report.Failed ("Constraint_Error raised in Log Difference Identity Test"); when others => Report.Failed ("exception in Log Difference Identity Test"); end Log_Difference_Identity; procedure Log_Product_Identity is -- Check using the identity ln(x**2) = 2ln(x) -- over the range A to B. -- This large range is chosen to minimize the possibility of -- undetected systematic errors. Cody pg 53. A : constant Real := 16.0; B : constant Real := 240.0; X : Real; Expected : Real; Actual : Real; begin Accuracy_Error_Reported := False; -- reset for I in 1..Max_Samples loop X := (B - A) * Real (I) / Real (Max_Samples) + A; -- magic argument purification X := Real'Machine (Real'Machine (X+8.0) - 8.0); Expected := 2.0 * Log (X); Actual := Log (X*X); Check (Actual, Expected, "Log Product Identity -" & Integer'Image (I) & " log (" & Real'Image (X) & ")", 4.0); if Accuracy_Error_Reported then -- only report the first error in this test in order to keep -- lots of failures from producing a huge error log return; end if; end loop; exception when Constraint_Error => Report.Failed ("Constraint_Error raised in Log Product Identity Test"); when others => Report.Failed ("exception in Log Product Identity Test"); end Log_Product_Identity; procedure Log10_Test is -- Check using the identity log(x) = log(11x/10) - log(1.1) -- over the range A to B. See Cody pg 52. A : constant Real := 1.0 / Sqrt (10.0); B : constant Real := 0.9; X : Real; Expected : Real; Actual : Real; begin if Real'Digits > 17 then -- constant used below is accuract to 17 digits Error_Low_Bound := 0.00000_00000_00000_01; Report.Comment ("log accuracy checked to 19 digits"); end if; Accuracy_Error_Reported := False; -- reset for I in 1..Max_Samples loop X := (B - A) * Real (I) / Real (Max_Samples) + A; Expected := Log (X + X/10.0, 10.0) - 3.77060_15822_50407_5E-4 - 21.0 / 512.0; Actual := Log (X, 10.0); Check (Actual, Expected, "Log 10 Test -" & Integer'Image (I) & " log (" & Real'Image (X) & ")", 4.0); -- only report the first error in this test in order to keep -- lots of failures from producing a huge error log exit when Accuracy_Error_Reported; end loop; Error_Low_Bound := 0.0; -- reset exception when Constraint_Error => Report.Failed ("Constraint_Error raised in Log 10 Test"); when others => Report.Failed ("exception in Log 10 Test"); end Log10_Test; procedure Exception_Test is X1, X2, X3, X4 : Real; begin begin X1 := Log (0.0); Report.Failed ("exception not raised for LOG(0)"); exception -- Log (0.0) must raise Constraint_Error, not Argument_Error, -- as per A.5.1(28,29). Was incorrect in ACVC 2.1 release. when Ada.Numerics.Argument_Error => Report.Failed ("Argument_Error raised instead of" & " Constraint_Error for LOG(0)--A.5.1(28,29)"); when Constraint_Error => null; -- ok when others => Report.Failed ("wrong exception raised for LOG(0)"); end; begin X2 := Log ( 1.0, 0.0); Report.Failed ("exception not raised for LOG(1,0)"); exception when Ada.Numerics.Argument_Error => null; -- ok when Constraint_Error => Report.Failed ("constraint_error raised instead of" & " argument_error for LOG(1,0)"); when others => Report.Failed ("wrong exception raised for LOG(1,0)"); end; begin X3 := Log (1.0, 1.0); Report.Failed ("exception not raised for LOG(1,1)"); exception when Ada.Numerics.Argument_Error => null; -- ok when Constraint_Error => Report.Failed ("constraint_error raised instead of" & " argument_error for LOG(1,1)"); when others => Report.Failed ("wrong exception raised for LOG(1,1)"); end; begin X4 := Log (1.0, -10.0); Report.Failed ("exception not raised for LOG(1,-10)"); exception when Ada.Numerics.Argument_Error => null; -- ok when Constraint_Error => Report.Failed ("constraint_error raised instead of" & " argument_error for LOG(1,-10)"); when others => Report.Failed ("wrong exception raised for LOG(1,-10)"); end; -- optimizer thwarting if Report.Ident_Bool (False) then Report.Comment (Real'Image (X1+X2+X3+X4)); end if; end Exception_Test; procedure Do_Test is begin Special_Value_Test; Taylor_Series_Test; Log_Difference_Identity; Log_Product_Identity; Log10_Test; Exception_Test; end Do_Test; end Generic_Check; ----------------------------------------------------------------------- ----------------------------------------------------------------------- package Float_Check is new Generic_Check (Float); -- check the floating point type with the most digits type A_Long_Float is digits System.Max_Digits; package A_Long_Float_Check is new Generic_Check (A_Long_Float); ----------------------------------------------------------------------- -----------------------------------------------------------------------begin Report.Test ("CXG2011", "Check the accuracy of the log function"); if Verbose then Report.Comment ("checking Standard.Float"); end if; Float_Check.Do_Test; if Verbose then Report.Comment ("checking a digits" & Integer'Image (System.Max_Digits) & " floating point type"); end if; A_Long_Float_Check.Do_Test; Report.Result;end CXG2011;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?