| 1 |
-- CXG1005.A |
| 2 |
-- |
| 3 |
-- Grant of Unlimited Rights |
| 4 |
-- |
| 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 |
| 14 |
-- to do so. |
| 15 |
-- |
| 16 |
-- DISCLAIMER |
| 17 |
-- |
| 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. |
| 24 |
--* |
| 25 |
-- |
| 26 |
-- OBJECTIVE: |
| 27 |
-- Check that the subprograms defined in the package |
| 28 |
-- Ada.Numerics.Generic_Complex_Elementary_Functions provide correct |
| 29 |
-- results. |
| 30 |
-- |
| 31 |
-- TEST DESCRIPTION: |
| 32 |
-- This test checks that specific subprograms defined in the generic |
| 33 |
-- package Generic_Complex_Elementary_Functions are available, and that |
| 34 |
-- they provide prescribed results given specific input values. |
| 35 |
-- The generic package Ada.Numerics.Generic_Complex_Types is instantiated |
| 36 |
-- with a real type (new Float). The resulting new package is used as |
| 37 |
-- the generic actual to package Complex_IO. |
| 38 |
-- |
| 39 |
-- SPECIAL REQUIREMENTS: |
| 40 |
-- Implementations for which Float'Signed_Zeros is True must provide |
| 41 |
-- a body for ImpDef.Annex_G.Negative_Zero which returns a negative |
| 42 |
-- zero. |
| 43 |
-- |
| 44 |
-- APPLICABILITY CRITERIA |
| 45 |
-- This test only applies to implementations that support the |
| 46 |
-- numerics annex. |
| 47 |
-- |
| 48 |
-- |
| 49 |
-- |
| 50 |
-- CHANGE HISTORY: |
| 51 |
-- 06 Dec 94 SAIC ACVC 2.0 |
| 52 |
-- 16 Nov 95 SAIC Corrected visibility problems for ACVC 2.0.1. |
| 53 |
-- 21 Feb 96 SAIC Incorporated new structure for package Impdef. |
| 54 |
-- 29 Sep 96 SAIC Incorporated reviewer comments. |
| 55 |
-- |
| 56 |
--! |
| 57 |
|
| 58 |
with Ada.Numerics.Generic_Complex_Types; |
| 59 |
with Ada.Numerics.Generic_Complex_Elementary_Functions; |
| 60 |
with ImpDef.Annex_G; |
| 61 |
with Report; |
| 62 |
|
| 63 |
procedure CXG1005 is |
| 64 |
begin |
| 65 |
|
| 66 |
Report.Test ("CXG1005", "Check that the subprograms defined in " & |
| 67 |
"the package Generic_Complex_Elementary_" & |
| 68 |
"Functions provide correct results"); |
| 69 |
|
| 70 |
Test_Block: |
| 71 |
declare |
| 72 |
|
| 73 |
type Real_Type is new Float; |
| 74 |
|
| 75 |
TC_Signed_Zeros : Boolean := Real_Type'Signed_Zeros; |
| 76 |
|
| 77 |
package Complex_Pack is new |
| 78 |
Ada.Numerics.Generic_Complex_Types(Real_Type); |
| 79 |
|
| 80 |
package CEF is |
| 81 |
new Ada.Numerics.Generic_Complex_Elementary_Functions(Complex_Pack); |
| 82 |
|
| 83 |
use Ada.Numerics, Complex_Pack, CEF; |
| 84 |
|
| 85 |
Complex_Zero : constant Complex := Compose_From_Cartesian( 0.0, 0.0); |
| 86 |
Plus_One : constant Complex := Compose_From_Cartesian( 1.0, 0.0); |
| 87 |
Minus_One : constant Complex := Compose_From_Cartesian(-1.0, 0.0); |
| 88 |
Plus_i : constant Complex := Compose_From_Cartesian(i); |
| 89 |
Minus_i : constant Complex := Compose_From_Cartesian(-i); |
| 90 |
|
| 91 |
Complex_Positive_Real : constant Complex := |
| 92 |
Compose_From_Cartesian(4.0, 2.0); |
| 93 |
Complex_Positive_Imaginary : constant Complex := |
| 94 |
Compose_From_Cartesian(3.0, 5.0); |
| 95 |
Complex_Negative_Real : constant Complex := |
| 96 |
Compose_From_Cartesian(-4.0, 2.0); |
| 97 |
Complex_Negative_Imaginary : constant Complex := |
| 98 |
Compose_From_Cartesian(3.0, -5.0); |
| 99 |
|
| 100 |
|
| 101 |
function A_Zero_Result (Z : Complex) return Boolean is |
| 102 |
begin |
| 103 |
return (Re(Z) = 0.0 and Im(Z) = 0.0); |
| 104 |
end A_Zero_Result; |
| 105 |
|
| 106 |
|
| 107 |
-- In order to evaluate complex elementary functions that are |
| 108 |
-- prescribed to return a "real" result (meaning that the imaginary |
| 109 |
-- component is zero), the Function A_Real_Result is defined. |
| 110 |
|
| 111 |
function A_Real_Result (Z : Complex) return Boolean is |
| 112 |
begin |
| 113 |
return Im(Z) = 0.0; |
| 114 |
end A_Real_Result; |
| 115 |
|
| 116 |
|
| 117 |
-- In order to evaluate complex elementary functions that are |
| 118 |
-- prescribed to return an "imaginary" result (meaning that the real |
| 119 |
-- component of the complex number is zero, and the imaginary |
| 120 |
-- component is non-zero), the Function An_Imaginary_Result is defined. |
| 121 |
|
| 122 |
function An_Imaginary_Result (Z : Complex) return Boolean is |
| 123 |
begin |
| 124 |
return (Re(Z) = 0.0 and Im(Z) /= 0.0); |
| 125 |
end An_Imaginary_Result; |
| 126 |
|
| 127 |
|
| 128 |
begin |
| 129 |
|
| 130 |
-- Check that when the input parameter value is zero, the following |
| 131 |
-- functions yield a zero result. |
| 132 |
|
| 133 |
if not A_Zero_Result( Sqrt(Complex_Zero) ) then |
| 134 |
Report.Failed("Non-zero result from Function Sqrt with zero input"); |
| 135 |
end if; |
| 136 |
|
| 137 |
if not A_Zero_Result( Sin(Complex_Zero) ) then |
| 138 |
Report.Failed("Non-zero result from Function Sin with zero input"); |
| 139 |
end if; |
| 140 |
|
| 141 |
if not A_Zero_Result( Arcsin(Complex_Zero) ) then |
| 142 |
Report.Failed("Non-zero result from Function Arcsin with zero " & |
| 143 |
"input"); |
| 144 |
end if; |
| 145 |
|
| 146 |
if not A_Zero_Result( Tan(Complex_Zero) ) then |
| 147 |
Report.Failed("Non-zero result from Function Tan with zero input"); |
| 148 |
end if; |
| 149 |
|
| 150 |
if not A_Zero_Result( Arctan(Complex_Zero) ) then |
| 151 |
Report.Failed("Non-zero result from Function Arctan with zero " & |
| 152 |
"input"); |
| 153 |
end if; |
| 154 |
|
| 155 |
if not A_Zero_Result( Sinh(Complex_Zero) ) then |
| 156 |
Report.Failed("Non-zero result from Function Sinh with zero input"); |
| 157 |
end if; |
| 158 |
|
| 159 |
if not A_Zero_Result( Arcsinh(Complex_Zero) ) then |
| 160 |
Report.Failed("Non-zero result from Function Arcsinh with zero " & |
| 161 |
"input"); |
| 162 |
end if; |
| 163 |
|
| 164 |
if not A_Zero_Result( Tanh(Complex_Zero) ) then |
| 165 |
Report.Failed("Non-zero result from Function Tanh with zero input"); |
| 166 |
end if; |
| 167 |
|
| 168 |
if not A_Zero_Result( Arctanh(Complex_Zero) ) then |
| 169 |
Report.Failed("Non-zero result from Function Arctanh with zero " & |
| 170 |
"input"); |
| 171 |
end if; |
| 172 |
|
| 173 |
|
| 174 |
-- Check that when the input parameter value is zero, the following |
| 175 |
-- functions yield a result of one. |
| 176 |
|
| 177 |
if Exp(Complex_Zero) /= Plus_One |
| 178 |
then |
| 179 |
Report.Failed("Non-zero result from Function Exp with zero input"); |
| 180 |
end if; |
| 181 |
|
| 182 |
if Cos(Complex_Zero) /= Plus_One |
| 183 |
then |
| 184 |
Report.Failed("Non-zero result from Function Cos with zero input"); |
| 185 |
end if; |
| 186 |
|
| 187 |
if Cosh(Complex_Zero) /= Plus_One |
| 188 |
then |
| 189 |
Report.Failed("Non-zero result from Function Cosh with zero input"); |
| 190 |
end if; |
| 191 |
|
| 192 |
|
| 193 |
-- Check that when the input parameter value is zero, the following |
| 194 |
-- functions yield a real result. |
| 195 |
|
| 196 |
if not A_Real_Result( Arccos(Complex_Zero) ) then |
| 197 |
Report.Failed("Non-real result from Function Arccos with zero input"); |
| 198 |
end if; |
| 199 |
|
| 200 |
if not A_Real_Result( Arccot(Complex_Zero) ) then |
| 201 |
Report.Failed("Non-real result from Function Arccot with zero input"); |
| 202 |
end if; |
| 203 |
|
| 204 |
|
| 205 |
-- Check that when the input parameter value is zero, the following |
| 206 |
-- functions yield an imaginary result. |
| 207 |
|
| 208 |
if not An_Imaginary_Result( Arccoth(Complex_Zero) ) then |
| 209 |
Report.Failed("Non-imaginary result from Function Arccoth with " & |
| 210 |
"zero input"); |
| 211 |
end if; |
| 212 |
|
| 213 |
|
| 214 |
-- Check that when the input parameter value is one, the Sqrt function |
| 215 |
-- yields a result of one. |
| 216 |
|
| 217 |
if Sqrt(Plus_One) /= Plus_One then |
| 218 |
Report.Failed("Incorrect result from Function Sqrt with input " & |
| 219 |
"value of one"); |
| 220 |
end if; |
| 221 |
|
| 222 |
|
| 223 |
-- Check that when the input parameter value is one, the following |
| 224 |
-- functions yield a result of zero. |
| 225 |
|
| 226 |
if not A_Zero_Result( Log(Plus_One) ) then |
| 227 |
Report.Failed("Non-zero result from Function Log with input " & |
| 228 |
"value of one"); |
| 229 |
end if; |
| 230 |
|
| 231 |
if not A_Zero_Result( Arccos(Plus_One) ) then |
| 232 |
Report.Failed("Non-zero result from Function Arccos with input " & |
| 233 |
"value of one"); |
| 234 |
end if; |
| 235 |
|
| 236 |
if not A_Zero_Result( Arccosh(Plus_One) ) then |
| 237 |
Report.Failed("Non-zero result from Function Arccosh with input " & |
| 238 |
"value of one"); |
| 239 |
end if; |
| 240 |
|
| 241 |
|
| 242 |
-- Check that when the input parameter value is one, the Arcsin |
| 243 |
-- function yields a real result. |
| 244 |
|
| 245 |
if not A_Real_Result( Arcsin(Plus_One) ) then |
| 246 |
Report.Failed("Non-real result from Function Arcsin with input " & |
| 247 |
"value of one"); |
| 248 |
end if; |
| 249 |
|
| 250 |
|
| 251 |
-- Check that when the input parameter value is minus one, the Sqrt |
| 252 |
-- function yields a result of "i", when the sign of the imaginary |
| 253 |
-- component of the input parameter is positive (and yields "-i", if |
| 254 |
-- the sign on the imaginary component is negative), and the |
| 255 |
-- Complex_Types.Real'Signed_Zeros attribute is True. |
| 256 |
|
| 257 |
if TC_Signed_Zeros then |
| 258 |
|
| 259 |
declare |
| 260 |
Minus_One_With_Pos_Zero_Im_Component : Complex := |
| 261 |
Compose_From_Cartesian(-1.0, +0.0); |
| 262 |
Minus_One_With_Neg_Zero_Im_Component : Complex := |
| 263 |
Compose_From_Cartesian |
| 264 |
(-1.0, Real_Type(ImpDef.Annex_G.Negative_Zero)); |
| 265 |
begin |
| 266 |
|
| 267 |
if Sqrt(Minus_One_With_Pos_Zero_Im_Component) /= Plus_i then |
| 268 |
Report.Failed("Incorrect result from Function Sqrt, when " & |
| 269 |
"input value is minus one with a positive " & |
| 270 |
"imaginary component, Signed_Zeros being True"); |
| 271 |
end if; |
| 272 |
|
| 273 |
if Sqrt(Minus_One_With_Neg_Zero_Im_Component) /= Minus_i then |
| 274 |
Report.Failed("Incorrect result from Function Sqrt, when " & |
| 275 |
"input value is minus one with a negative " & |
| 276 |
"imaginary component, Signed_Zeros being True"); |
| 277 |
end if; |
| 278 |
end; |
| 279 |
|
| 280 |
else -- Signed_Zeros is False. |
| 281 |
|
| 282 |
-- Check that when the input parameter value is minus one, the Sqrt |
| 283 |
-- function yields a result of "i", when the |
| 284 |
-- Complex_Types.Real'Signed_Zeros attribute is False. |
| 285 |
|
| 286 |
if Sqrt(Minus_One) /= Plus_i then |
| 287 |
Report.Failed("Incorrect result from Function Sqrt, when " & |
| 288 |
"input value is minus one, Signed_Zeros being " & |
| 289 |
"False"); |
| 290 |
end if; |
| 291 |
|
| 292 |
end if; |
| 293 |
|
| 294 |
|
| 295 |
-- Check that when the input parameter value is minus one, the Log |
| 296 |
-- function yields an imaginary result. |
| 297 |
|
| 298 |
if not An_Imaginary_Result( Log(Minus_One) ) then |
| 299 |
Report.Failed("Non-imaginary result from Function Log with a " & |
| 300 |
"minus one input value"); |
| 301 |
end if; |
| 302 |
|
| 303 |
-- Check that when the input parameter is minus one, the following |
| 304 |
-- functions yield a real result. |
| 305 |
|
| 306 |
if not A_Real_Result( Arcsin(Minus_One) ) then |
| 307 |
Report.Failed("Non-real result from Function Arcsin with a " & |
| 308 |
"minus one input value"); |
| 309 |
end if; |
| 310 |
|
| 311 |
if not A_Real_Result( Arccos(Minus_One) ) then |
| 312 |
Report.Failed("Non-real result from Function Arccos with a " & |
| 313 |
"minus one input value"); |
| 314 |
end if; |
| 315 |
|
| 316 |
|
| 317 |
-- Check that when the input parameter has a value of +i or -i, the |
| 318 |
-- Log function yields an imaginary result. |
| 319 |
|
| 320 |
if not An_Imaginary_Result( Log(Plus_i) ) then |
| 321 |
Report.Failed("Non-imaginary result from Function Log with an " & |
| 322 |
"input value of ""+i"""); |
| 323 |
end if; |
| 324 |
|
| 325 |
if not An_Imaginary_Result( Log(Minus_i) ) then |
| 326 |
Report.Failed("Non-imaginary result from Function Log with an " & |
| 327 |
"input value of ""-i"""); |
| 328 |
end if; |
| 329 |
|
| 330 |
|
| 331 |
-- Check that exponentiation by a zero exponent yields the value one. |
| 332 |
|
| 333 |
if "**"(Left => Compose_From_Cartesian(5.0, 3.0), |
| 334 |
Right => Complex_Zero) /= Plus_One or |
| 335 |
Complex_Negative_Real**0.0 /= Plus_One or |
| 336 |
15.0**Complex_Zero /= Plus_One |
| 337 |
then |
| 338 |
Report.Failed("Incorrect result from exponentiation with a zero " & |
| 339 |
"exponent"); |
| 340 |
end if; |
| 341 |
|
| 342 |
|
| 343 |
-- Check that exponentiation by a unit exponent yields the value of |
| 344 |
-- the left operand (as a complex value). |
| 345 |
-- Note: a "unit exponent" is considered the complex number (1.0, 0.0) |
| 346 |
|
| 347 |
if "**"(Complex_Negative_Real, Plus_One) /= |
| 348 |
Complex_Negative_Real or |
| 349 |
Complex_Negative_Imaginary**Plus_One /= |
| 350 |
Complex_Negative_Imaginary or |
| 351 |
4.0**Plus_One /= |
| 352 |
Compose_From_Cartesian(4.0, 0.0) |
| 353 |
then |
| 354 |
Report.Failed("Incorrect result from exponentiation with a unit " & |
| 355 |
"exponent"); |
| 356 |
end if; |
| 357 |
|
| 358 |
|
| 359 |
-- Check that exponentiation of the value one yields the value one. |
| 360 |
|
| 361 |
if "**"(Plus_One, Complex_Negative_Imaginary) /= Plus_One or |
| 362 |
Plus_One**9.0 /= Plus_One or |
| 363 |
1.0**Complex_Negative_Real /= Plus_One |
| 364 |
then |
| 365 |
Report.Failed("Incorrect result from exponentiation of the value " & |
| 366 |
"One"); |
| 367 |
end if; |
| 368 |
|
| 369 |
|
| 370 |
-- Check that exponentiation of the value zero yields the value zero. |
| 371 |
begin |
| 372 |
if not A_Zero_Result("**"(Complex_Zero, |
| 373 |
Complex_Positive_Imaginary)) or |
| 374 |
not A_Zero_Result(Complex_Zero**4.0) or |
| 375 |
not A_Zero_Result(0.0**Complex_Positive_Real) |
| 376 |
then |
| 377 |
Report.Failed("Incorrect result from exponentiation of the " & |
| 378 |
"value zero"); |
| 379 |
end if; |
| 380 |
exception |
| 381 |
when others => |
| 382 |
Report.Failed("Exception raised during the exponentiation of " & |
| 383 |
"the complex value zero"); |
| 384 |
end; |
| 385 |
|
| 386 |
|
| 387 |
exception |
| 388 |
when others => Report.Failed ("Exception raised in Test_Block"); |
| 389 |
end Test_Block; |
| 390 |
|
| 391 |
Report.Result; |
| 392 |
|
| 393 |
end CXG1005; |