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 floating point addition and multiplication
28 -- have the required accuracy.
31 -- The check for the required precision is essentially a
32 -- check that a guard digit is used for the operations.
33 -- This test uses a generic package to check the addition
34 -- and multiplication results. The
35 -- generic package is instantiated with the standard FLOAT
36 -- type and a floating point type for the maximum number
37 -- of digits of precision.
39 -- APPLICABILITY CRITERIA:
40 -- This test applies only to implementations supporting the
45 -- 14 FEB 96 SAIC Initial Release for 2.1
46 -- 16 SEP 99 RLB Repaired to avoid printing thousands of (almost)
47 -- identical failure messages.
52 -- Basic Concepts for Computational Software
54 -- Problems and Methodologies in Mathematical Software Production
55 -- editors P. C. Messina and A. Murli
56 -- Lecture Notes in Computer Science Vol 142
57 -- Springer Verlag, 1982
59 -- Software Manual for the Elementary Functions
60 -- William J. Cody and William Waite
61 -- Prentice-Hall, 1980
67 Verbose
: constant Boolean := False;
70 type Real
is digits <>;
71 package Guard_Digit_Check
is
73 end Guard_Digit_Check
;
75 package body Guard_Digit_Check
is
76 -- made global so that the compiler will be more likely
77 -- to keep the values in memory instead of in higher
78 -- precision registers.
83 -- special constants - not declared as constants so that
84 -- the "stored" precision will be used instead of a "register"
90 Failure_Count
: Natural := 0;
92 procedure Thwart_Optimization
is
93 -- the purpose of this procedure is to reference the
94 -- global variables used by the test so
95 -- that the compiler is not likely to keep them in
96 -- a higher precision register for their entire lifetime.
98 if Report
.Ident_Bool
(False) then
106 One
:= 12.34; Two
:= 56.78; Zero
:= 90.12;
108 end Thwart_Optimization
;
111 procedure Addition_Test
is
114 Eps
:= Real
(K
) * Real
'Model_Epsilon;
115 for N
in 1.. Real
'Machine_EMax - 1 loop
116 BN
:= Real
(Real
'Machine_Radix) ** N
;
117 X
:= (One
+ Eps
) * BN
;
118 Y
:= (One
- Eps
) * BN
;
119 Z
:= X
- Y
; -- true value for Z is 2*Eps*BN
121 if Z
/= Eps
*BN
+ Eps
*BN
then
122 Report
.Failed
("addition check failed. K=" &
124 " N=" & Integer'Image (N
) &
125 " difference=" & Real
'Image (Z
- 2.0*Eps
*BN
) &
126 " Eps*BN=" & Real
'Image (Eps
*BN
) );
127 Failure_Count
:= Failure_Count
+ 1;
128 exit when Failure_Count
> K
*4; -- Avoid displaying dozens of messages.
135 Report
.Failed
("unexpected exception in addition test");
139 procedure Multiplication_Test
is
141 X
:= Real
(Real
'Machine_Radix) ** (Real
'Machine_EMax - 1);
145 Report
.Failed
("multiplication for large values");
148 X
:= Real
(Real
'Machine_Radix) ** (Real
'Model_EMin + 1);
152 Report
.Failed
("multiplication for small values");
155 -- selection of "random" values between 1/radix and radix
156 Y
:= One
/ Real
(Real
'Machine_Radix);
157 Z
:= Real
(Real
'Machine_Radix) - One
/Real
(Real
'Machine_Radix);
159 X
:= Y
+ Real
(I
) / 100.0 * Z
;
163 Report
.Failed
("multiplication for case" & Integer'Image (I
));
164 exit when Failure_Count
> 40+8; -- Avoid displaying dozens of messages.
170 Report
.Failed
("unexpected exception in multiplication test");
171 end Multiplication_Test
;
179 end Guard_Digit_Check
;
181 package Chk_Float
is new Guard_Digit_Check
(Float);
183 -- check the floating point type with the most digits
184 type A_Long_Float
is digits System
.Max_Digits
;
185 package Chk_A_Long_Float
is new Guard_Digit_Check
(A_Long_Float
);
187 Report
.Test
("CXG2005",
188 "Check the accuracy of floating point" &
189 " addition and multiplication");
192 Report
.Comment
("checking Standard.Float");
197 Report
.Comment
("checking a digits" &
198 Integer'Image (System
.Max_Digits
) &
199 " floating point type");
201 Chk_A_Long_Float
.Do_Test
;