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 the subprograms defined in the package
28 -- Ada.Numerics.Generic_Complex_Types provide the prescribed results.
29 -- Specifically, check the various versions of functions "+" and "-".
32 -- This test checks that the subprograms "+" and "-" defined in the
33 -- Generic_Complex_Types package provide the results prescribed for the
34 -- evaluation of these complex arithmetic operations. The functions
35 -- Re and Im are used to extract the appropriate component of the
36 -- complex result, in order that the prescribed result component can be
38 -- The generic package is instantiated with a real type (new Float),
39 -- and the results produced by the specified subprograms are verified.
41 -- SPECIAL REQUIREMENTS:
42 -- This test can be run in either "relaxed" or "strict" mode.
46 -- 06 Dec 94 SAIC ACVC 2.0
50 with Ada
.Numerics
.Generic_Complex_Types
;
57 Report
.Test
("CXG1002", "Check that the subprograms defined in " &
58 "the package Ada.Numerics.Generic_Complex_Types " &
59 "provide the prescribed results");
64 type Real_Type
is new Float;
66 package Complex_Pack
is new
67 Ada
.Numerics
.Generic_Complex_Types
(Real_Type
);
70 -- Declare a zero valued complex number using the record
71 -- aggregate approach.
73 Complex_Zero
: constant Complex_Pack
.Complex
:= (0.0, 0.0);
77 TC_Complex_Left
: Complex_Pack
.Complex
:= Complex_Zero
;
79 TC_Real
: Real_Type
:= 0.0;
81 TC_Imaginary
: Complex_Pack
.Imaginary
;
86 -- Check that the imaginary component of the result of a binary addition
87 -- operator that yields a result of complex type is exact when either
88 -- of its operands is of pure-real type.
90 TC_Complex
:= Compose_From_Cartesian
(2.0, 3.0);
93 if Im
("+"(Left
=> TC_Complex
, Right
=> TC_Real
)) /= 3.0 or
94 Im
("+"(TC_Complex
, 6.0)) /= 3.0 or
95 Im
(TC_Complex
+ TC_Real
) /= 3.0 or
96 Im
(TC_Complex
+ 5.0) /= 3.0 or
97 Im
((7.0, 2.0) + 1.0) /= 2.0 or
98 Im
((7.0, 5.0) + (-2.0)) /= 5.0 or
99 Im
((-7.0, -2.0) + 1.0) /= -2.0 or
100 Im
((-7.0, -3.0) + (-3.0)) /= -3.0
102 Report
.Failed
("Incorrect results from Function ""+"" with " &
103 "one Complex and one Real argument - 1");
106 if Im
("+"(Left
=> TC_Real
, Right
=> TC_Complex
)) /= 3.0 or
107 Im
("+"(4.0, TC_Complex
)) /= 3.0 or
108 Im
(TC_Real
+ TC_Complex
) /= 3.0 or
109 Im
(9.0 + TC_Complex
) /= 3.0 or
110 Im
(1.0 + (7.0, -9.0)) /= -9.0 or
111 Im
((-2.0) + (7.0, 2.0)) /= 2.0 or
112 Im
(1.0 + (-7.0, -5.0)) /= -5.0 or
113 Im
((-3.0) + (-7.0, 16.0)) /= 16.0
115 Report
.Failed
("Incorrect results from Function ""+"" with " &
116 "one Complex and one Real argument - 2");
120 -- Check that the imaginary component of the result of a binary
121 -- subtraction operator that yields a result of complex type is exact
122 -- when its right operand is of pure-real type.
124 TC_Complex
:= (8.0, -4.0);
127 if Im
("-"(Left
=> TC_Complex
, Right
=> TC_Real
)) /= -4.0 or
128 Im
("-"(TC_Complex
, 5.0)) /= -4.0 or
129 Im
(TC_Complex
- TC_Real
) /= -4.0 or
130 Im
(TC_Complex
- 4.0) /= -4.0 or
131 Im
((6.0, 5.0) - 1.0) /= 5.0 or
132 Im
((6.0, 13.0) - 7.0) /= 13.0 or
133 Im
((-5.0, 3.0) - (2.0)) /= 3.0 or
134 Im
((-5.0, -6.0) - (-3.0)) /= -6.0
136 Report
.Failed
("Incorrect results from Function ""-"" with " &
137 "one Complex and one Real argument");
141 -- Check that the real component of the result of a binary addition
142 -- operator that yields a result of complex type is exact when either
143 -- of its operands is of pure-imaginary type.
145 TC_Complex
:= (5.0, 0.0);
147 if Re
("+"(Left
=> TC_Complex
, Right
=> i
)) /= 5.0 or
148 Re
("+"(Complex_Pack
.j
, TC_Complex
)) /= 5.0 or
149 Re
((-8.0, 5.0) + ( 2.0*i
)) /= -8.0 or
150 Re
((2.0, 5.0) + (-2.0*i
)) /= 2.0 or
151 Re
((-20.0, -5.0) + ( 3.0*i
)) /= -20.0 or
152 Re
((6.0, -5.0) + (-3.0*i
)) /= 6.0
154 Report
.Failed
("Incorrect results from Function ""+"" with " &
155 "one Complex and one Imaginary argument");
159 -- Check that the real component of the result of a binary
160 -- subtraction operator that yields a result of complex type is exact
161 -- when its right operand is of pure-imaginary type.
163 TC_Complex
:= TC_Complex
+ i
; -- Should produce (5.0, 1.0)
165 if Re
("-"(TC_Complex
, i
)) /= 5.0 or
166 Re
((-4.0, 4.0) - ( 2.0*i
)) /= -4.0 or
167 Re
((9.0, 4.0) - ( 5.0*i
)) /= 9.0 or
168 Re
((16.0, -5.0) - ( 3.0*i
)) /= 16.0 or
169 Re
((-3.0, -5.0) - (-4.0*i
)) /= -3.0
171 Report
.Failed
("Incorrect results from Function ""-"" with " &
172 "one Complex and one Imaginary argument");
176 -- Check that the result of a binary addition operation is exact when
177 -- one of its operands is of real type and the other is of
178 -- pure-imaginary type; the operator is analogous to the
179 -- Compose_From_Cartesian function; it performs no arithmetic.
181 TC_Complex
:= Complex_Pack
."+"(5.0, Complex_Pack
.i
);
183 if TC_Complex
/= (5.0, 1.0) or
184 (4.0 + i
) /= (4.0, 1.0) or
185 "+"(Left
=> j
, Right
=> 3.0) /= (3.0, 1.0)
187 Report
.Failed
("Incorrect results from Function ""+"" with " &
188 "one Real and one Imaginary argument");
193 when others => Report
.Failed
("Exception raised in Test_Block");