1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
-- CXA5A03.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 Tan, Tanh, and Arctanh provide correct
-- results.
--
-- TEST DESCRIPTION:
-- This test examines both the version of Tan, Tanh, and Arctanh
-- 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, including instances prescribed to raise
-- exceptions, are examined in the test cases. In addition,
-- certain evaluations are performed 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)
-- CXA5A03.A
--
--
-- CHANGE HISTORY:
-- 14 Mar 95 SAIC Initial prerelease version.
-- 06 Apr 95 SAIC Corrected errors in context clause references
-- and usage of Cycle parameter.
-- 13 Jun 95 SAIC Incorporated use of Dont_Optimize procedure, and
-- use of Result_Within_Range function overloaded for
-- FXA5A00.New_Float_Type.
-- 29 Jun 98 EDS Protected exception tests by first testing
-- for 'Machine_Overflows
--
--!
with Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Generic_Elementary_Functions;
with FXA5A00;
with Report;
procedure CXA5A03 is
begin
Report.Test ("CXA5A03", "Check that the functions Tan, Tanh, and " &
"Arctanh provide correct results");
Test_Block:
declare
use Ada.Numerics;
use FXA5A00;
package GEF is new Ada.Numerics.Generic_Elementary_Functions(New_Float);
package EF renames Ada.Numerics.Elementary_Functions;
The_Result : Float;
New_Float_Result : New_Float;
procedure Dont_Optimize_Float is new Dont_Optimize(Float);
procedure Dont_Optimize_New_Float is new Dont_Optimize(New_Float);
begin
-- Testing of Tan Function, both instantiated and pre-instantiated
-- version.
-- Check that no exception occurs on computing the Tan with very
-- large (positive and negative) input values.
begin
New_Float_Result := GEF.Tan (New_Float(FXA5A00.Large));
Dont_Optimize_New_Float(New_Float_Result, 1);
exception
when others =>
Report.Failed("Unexpected exception on GEF.Tan with large " &
"positive value");
end;
begin
The_Result := EF.Tan (FXA5A00.Minus_Large);
Dont_Optimize_Float(The_Result, 2);
exception
when others =>
Report.Failed("Unexpected exception on EF.Tan with large " &
"negative value");
end;
-- Check that no exception occurs on computing the Tan with very
-- small (positive and negative) input values.
begin
New_Float_Result := GEF.Tan (New_Float(FXA5A00.Small));
Dont_Optimize_New_Float(New_Float_Result, 3);
exception
when others =>
Report.Failed("Unexpected exception on GEF.Tan with small " &
"positive value");
end;
begin
The_Result := EF.Tan (-FXA5A00.Small);
Dont_Optimize_Float(The_Result, 4);
exception
when others =>
Report.Failed("Unexpected exception on EF.Tan with small " &
"negative value");
end;
-- Check prescribed result from Tan function. When the parameter X
-- has the value zero, the Tan function yields a result of zero.
if GEF.Tan(0.0) /= 0.0 or
EF.Tan(0.0) /= 0.0
then
Report.Failed("Incorrect result from Tan function with zero " &
"value input parameter");
end if;
-- Check the results of the Tan function with various input parameters.
if not (Result_Within_Range(GEF.Tan(0.7854), 1.0, 0.001) and
Result_Within_Range(GEF.Tan(0.8436), 1.124, 0.001) and
Result_Within_Range( EF.Tan(Pi), 0.0, 0.001) and
Result_Within_Range( EF.Tan(-Pi), 0.0, 0.001) and
Result_Within_Range(GEF.Tan(0.5381), 0.597, 0.001) and
Result_Within_Range( EF.Tan(0.1978), 0.200, 0.001))
then
Report.Failed("Incorrect result from Tan function with various " &
"input parameters");
end if;
-- Testing of Tan function with cycle parameter.
-- Check that Constraint_Error is raised by the Tan function with
-- specified cycle, when the value of the parameter X is an odd
-- multiple of the quarter cycle.
if New_Float'Machine_Overflows = True then
begin
New_Float_Result := GEF.Tan(270.0, 360.0);
Report.Failed("Constraint_Error not raised by GEF.Tan on odd " &
"multiple of the quarter cycle");
Dont_Optimize_New_Float(New_Float_Result, 5);
exception
when Constraint_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by GEF.Tan on odd " &
"multiple of the quarter cycle");
end;
end if;
-- Check that the exception Numerics.Argument_Error is raised, when
-- the value of the parameter Cycle is zero or negative.
begin
New_Float_Result := GEF.Tan(X => 1.0, Cycle => -360.0);
Report.Failed("Argument_Error not raised by GEF.Tan when Cycle " &
"parameter has negative value");
Dont_Optimize_New_Float(New_Float_Result, 6);
exception
when Argument_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by GEF.Tan when Cycle " &
"parameter has negative value");
end;
begin
The_Result := EF.Tan(1.0, Cycle => 0.0);
Report.Failed("Argument_Error not raised by GEF.Tan when Cycle " &
"parameter has a zero value");
Dont_Optimize_Float(The_Result, 7);
exception
when Argument_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by EF.Tan when Cycle " &
"parameter has a zero value");
end;
-- Check that no exception occurs on computing the Tan with very
-- large (positive and negative) input values.
begin
New_Float_Result := GEF.Tan (New_Float(FXA5A00.Large), 360.0);
Dont_Optimize_New_Float(New_Float_Result, 8);
exception
when others =>
Report.Failed("Unexpected exception on GEF.Tan with large " &
"positive value");
end;
begin
The_Result := EF.Tan (FXA5A00.Minus_Large, Cycle => 360.0);
Dont_Optimize_Float(The_Result, 9);
exception
when others =>
Report.Failed("Unexpected exception on EF.Tan with large " &
"negative value");
end;
-- Check prescribed result from Tan function with Cycle parameter.
if GEF.Tan(0.0, 360.0) /= 0.0 or
EF.Tan(0.0, Cycle => 360.0) /= 0.0
then
Report.Failed("Incorrect result from Tan function with cycle " &
"parameter, using a zero value input parameter");
end if;
-- Check the Tan function, with specified Cycle parameter, with a
-- variety of input parameters.
if not Result_Within_Range(GEF.Tan(30.0, 360.0), 0.577, 0.001) or
not Result_Within_Range( EF.Tan(57.0, 360.0), 1.540, 0.001) or
not Result_Within_Range(GEF.Tan(115.0, 360.0), -2.145, 0.001) or
not Result_Within_Range( EF.Tan(299.0, 360.0), -1.804, 0.001) or
not Result_Within_Range(GEF.Tan(390.0, 360.0), 0.577, 0.001) or
not Result_Within_Range( EF.Tan(520.0, 360.0), -0.364, 0.001)
then
Report.Failed("Incorrect result from the Tan function with " &
"cycle parameter, with various input parameter " &
"values");
end if;
-- Testing of Tanh Function, both instantiated and pre-instantiated
-- version.
-- Check that no exception occurs on computing the Tan with very
-- large (positive and negative) input values.
begin
New_Float_Result := GEF.Tanh (New_Float(FXA5A00.Large));
Dont_Optimize_New_Float(New_Float_Result, 10);
exception
when others =>
Report.Failed("Unexpected exception on GEF.Tanh with large " &
"positive value");
end;
begin
The_Result := EF.Tanh (FXA5A00.Minus_Large);
Dont_Optimize_Float(The_Result, 11);
exception
when others =>
Report.Failed("Unexpected exception on EF.Tanh with large " &
"negative value");
end;
-- Check for prescribed result of Tanh with zero value input parameter.
if GEF.Tanh (0.0) /= 0.0 or
EF.Tanh (0.0) /= 0.0
then
Report.Failed("Incorrect result from Tanh with zero parameter");
end if;
-- Check the results of the Tanh function with various input
-- parameters.
if not (FXA5A00.Result_Within_Range(GEF.Tanh(2.99), 0.995, 0.001) and
FXA5A00.Result_Within_Range(GEF.Tanh(0.130), 0.129, 0.001) and
FXA5A00.Result_Within_Range( EF.Tanh(Pi), 0.996, 0.001) and
FXA5A00.Result_Within_Range( EF.Tanh(-Pi), -0.996, 0.001) and
FXA5A00.Result_Within_Range(GEF.Tanh(0.60), 0.537, 0.001) and
FXA5A00.Result_Within_Range( EF.Tanh(1.04), 0.778, 0.001) and
FXA5A00.Result_Within_Range(GEF.Tanh(1.55), 0.914, 0.001) and
FXA5A00.Result_Within_Range( EF.Tanh(-2.14), -0.973, 0.001))
then
Report.Failed("Incorrect result from Tanh function with various " &
"input parameters");
end if;
-- Testing of Arctanh Function, both instantiated and pre-instantiated
-- version.
-- Check that Constraint_Error is raised by the Arctanh function
-- when the absolute value of the parameter X is one.
if New_Float'Machine_Overflows = True then
begin
New_Float_Result := GEF.Arctanh(X => 1.0);
Report.Failed("Constraint_Error not raised by Function Arctanh " &
"when provided a parameter value of 1.0");
Dont_Optimize_New_Float(New_Float_Result, 12);
exception
when Constraint_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by Function Arctanh "
& "when provided a parameter value of 1.0");
end;
end if;
if Float'Machine_Overflows = True then
begin
The_Result := EF.Arctanh(-1.0);
Report.Failed("Constraint_Error not raised by Function Arctanh " &
"when provided a parameter value of -1.0");
Dont_Optimize_Float(The_Result, 13);
exception
when Constraint_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by Function Arctanh "
& "when provided a parameter value of -1.0");
end;
end if;
-- Check that Function Arctanh raises Argument_Error when the absolute
-- value of the parameter X exceeds one.
begin
New_Float_Result := GEF.Arctanh(New_Float(FXA5A00.One_Plus_Delta));
Report.Failed("Argument_Error not raised by Function Arctanh " &
"when provided a parameter value greater than 1.0");
Dont_Optimize_New_Float(New_Float_Result, 14);
exception
when Argument_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by Function Arctanh " &
"when provided a parameter value greater than 1.0");
end;
begin
The_Result := EF.Arctanh(FXA5A00.Minus_One_Minus_Delta);
Report.Failed("Argument_Error not raised by Function Arctanh " &
"when provided a parameter value less than -1.0");
Dont_Optimize_Float(The_Result, 15);
exception
when Argument_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by Function Arctanh " &
"when provided a parameter value less than -1.0");
end;
begin
New_Float_Result := GEF.Arctanh(New_Float(FXA5A00.Large));
Report.Failed("Argument_Error not raised by Function Arctanh " &
"when provided a large positive parameter value");
Dont_Optimize_New_Float(New_Float_Result, 16);
exception
when Argument_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by Function Arctanh " &
"when provided a large positive parameter value");
end;
begin
The_Result := EF.Arctanh(FXA5A00.Minus_Large);
Report.Failed("Argument_Error not raised by Function Arctanh " &
"when provided a large negative parameter value");
Dont_Optimize_Float(The_Result, 17);
exception
when Argument_Error => null; -- OK, expected exception.
when others =>
Report.Failed("Unexpected exception raised by Function Arctanh " &
"when provided a large negative parameter value");
end;
-- Prescribed results for Function Arctanh with zero input value.
if GEF.Arctanh(0.0) /= 0.0 or
EF.Arctanh(0.0) /= 0.0
then
Report.Failed("Incorrect result from Function Arctanh with a " &
"parameter value of zero");
end if;
-- Check the results of the Arctanh function with various input
-- parameters.
if not (Result_Within_Range(GEF.Arctanh(0.15), 0.151, 0.001) and
Result_Within_Range( EF.Arctanh(0.44), 0.472, 0.001) and
Result_Within_Range(GEF.Arctanh(0.81), 1.127, 0.001) and
Result_Within_Range( EF.Arctanh(0.99), 2.647, 0.001))
then
Report.Failed("Incorrect result from Arctanh function with " &
"various input parameters");
end if;
exception
when others => Report.Failed ("Exception raised in Test_Block");
end Test_Block;
Report.Result;
end CXA5A03;
|