OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxa/] [cxa5a09.a] - Blame information for rev 316

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- CXA5A09.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 function Log provides correct results.
28
--
29
-- TEST DESCRIPTION:
30
--      This test examines both the version of Log resulting from the
31
--      instantiation of the Ada.Numerics.Generic_Elementary_Functions with
32
--      with a type derived from type Float,as well as the preinstantiated
33
--      version of this package for type Float.
34
--      Prescribed results, including instances prescribed to raise
35
--      exceptions, are examined in the test cases.  In addition,
36
--      certain evaluations are performed where the actual function result
37
--      is compared with the expected result (within an epsilon range of
38
--      accuracy).
39
--
40
-- TEST FILES:
41
--      The following files comprise this test:
42
--
43
--         FXA5A00.A   (foundation code)
44
--         CXA5A09.A
45
--
46
--
47
-- CHANGE HISTORY:
48
--      11 Apr 95   SAIC    Initial prerelease version.
49
--      13 Jun 95   SAIC    Incorporated use of Dont_Optimize procedure, and
50
--                          use of Result_Within_Range function overloaded for
51
--                          FXA5A00.New_Float_Type.
52
--      29 Jun 98   EDS     Protected exception tests by first testing
53
--                          for 'Machine_Overflows
54
--
55
--!
56
 
57
with Ada.Numerics.Elementary_Functions;
58
with Ada.Numerics.Generic_Elementary_Functions;
59
with FXA5A00;
60
with Report;
61
 
62
procedure CXA5A09 is
63
begin
64
 
65
   Report.Test ("CXA5A09", "Check that the Log function provides " &
66
                           "correct results");
67
 
68
   Test_Block:
69
   declare
70
 
71
      use Ada.Numerics;
72
      use FXA5A00;
73
 
74
      package GEF is new Ada.Numerics.Generic_Elementary_Functions(New_Float);
75
      package  EF renames Ada.Numerics.Elementary_Functions;
76
 
77
      Arg,
78
      Float_Result     : Float     := 0.0;
79
      New_Float_Result : New_Float := 0.0;
80
 
81
      Incorrect_Inverse,
82
      Incorrect_Inverse_Base_2,
83
      Incorrect_Inverse_Base_8,
84
      Incorrect_Inverse_Base_10,
85
      Incorrect_Inverse_Base_16  : Boolean   := False;
86
 
87
      procedure Dont_Optimize_Float     is new Dont_Optimize(Float);
88
      procedure Dont_Optimize_New_Float is new Dont_Optimize(New_Float);
89
 
90
   begin
91
 
92
      -- Testing of Log Function, both instantiated and pre-instantiated
93
      -- version.
94
 
95
      -- Check that Argument_Error is raised when the parameter X is negative.
96
 
97
      begin
98
         New_Float_Result := GEF.Log(X => -1.0);
99
         Report.Failed("Argument_Error not raised by the Log function " &
100
                       "when the input parameter is negative");
101
         Dont_Optimize_New_Float(New_Float_Result, 1);
102
      exception
103
         when Argument_Error => null; -- OK, expected exception.
104
         when others         =>
105
            Report.Failed("Unexpected exception raised by the Log function " &
106
                          "when the input parameter is negative");
107
      end;
108
 
109
      begin
110
         Float_Result := EF.Log(X => -FXA5A00.Large);
111
         Report.Failed("Argument_Error not raised by the Log function " &
112
                       "when the input parameter is negative");
113
         Dont_Optimize_Float(Float_Result, 2);
114
      exception
115
         when Argument_Error => null; -- OK, expected exception.
116
         when others         =>
117
            Report.Failed("Unexpected exception raised by the Log function " &
118
                          "when the input parameter is negative");
119
      end;
120
 
121
 
122
      -- Check that Constraint_Error is raised when the Log function is
123
      -- provided an input parameter of zero.
124
 
125
      if New_Float'Machine_Overflows = True then
126
         begin
127
            New_Float_Result := GEF.Log(X => 0.0);
128
            Report.Failed("Constraint_Error not raised by the Log function " &
129
                          "when the input parameter is zero");
130
            Dont_Optimize_New_Float(New_Float_Result, 3);
131
         exception
132
            when Constraint_Error => null; -- OK, expected exception.
133
            when others         =>
134
               Report.Failed("Unexpected exception raised by the Log function "
135
                             & "when the input parameter is zero");
136
         end;
137
      end if;
138
 
139
 
140
      -- Check for the reference manual prescribed results of the Log function.
141
 
142
      if GEF.Log(X => 1.0) /= 0.0 or
143
          EF.Log(X => 1.0) /= 0.0
144
      then
145
         Report.Failed("Incorrect result from Function Log when provided " &
146
                       "an input parameter value of 1.0");
147
      end if;
148
 
149
 
150
      -- Check that the Log function provides correct results when provided
151
      -- a variety of input parameters.
152
 
153
      if not FXA5A00.Result_Within_Range(GEF.Log(0.015),   -4.20,  0.01)  or
154
         not FXA5A00.Result_Within_Range(GEF.Log(0.592),   -0.524, 0.001) or
155
         not FXA5A00.Result_Within_Range(GEF.Log(0.997),   -0.003, 0.001) or
156
         not FXA5A00.Result_Within_Range(GEF.Log(1.341),    0.293, 0.001) or
157
         not FXA5A00.Result_Within_Range( EF.Log(2.826),    1.04,  0.01)  or
158
         not FXA5A00.Result_Within_Range( EF.Log(10.052),   2.31,  0.01)  or
159
         not FXA5A00.Result_Within_Range( EF.Log(2569.143), 7.85,  0.01)
160
      then
161
         Report.Failed("Incorrect results from Function Log when provided " &
162
                       "a variety of input parameter values");
163
      end if;
164
 
165
      Arg := 0.001;
166
      while Arg < 1.0 and not Incorrect_Inverse loop
167
         if not Result_Within_Range(EF."**"(e,EF.Log(Arg)), Arg, 0.001) then
168
            Incorrect_Inverse := True;
169
         end if;
170
         Arg := Arg + 0.001;
171
      end loop;
172
 
173
      if Incorrect_Inverse then
174
         Report.Failed("Incorrect inverse result comparing ""**"" and " &
175
                       "Log function over argument range 0.001..1.0");
176
         Incorrect_Inverse := False;
177
      end if;
178
 
179
      Arg := 1.0;
180
      while Arg < 10.0 and not Incorrect_Inverse loop
181
         if not Result_Within_Range(EF."**"(e,EF.Log(Arg)), Arg, 0.01) then
182
            Incorrect_Inverse := True;
183
         end if;
184
         Arg := Arg + 0.01;
185
      end loop;
186
 
187
      if Incorrect_Inverse then
188
         Report.Failed("Incorrect inverse result comparing ""**"" and " &
189
                       "Log function over argument range 1.0..10.0");
190
         Incorrect_Inverse := False;
191
      end if;
192
 
193
      Arg := 1.0;
194
      while Arg < 1000.0 and not Incorrect_Inverse loop
195
         if not Result_Within_Range(EF."**"(e,EF.Log(Arg)), Arg, 0.1) then
196
            Incorrect_Inverse := True;
197
         end if;
198
         Arg := Arg + 1.0;
199
      end loop;
200
 
201
      if Incorrect_Inverse then
202
         Report.Failed("Incorrect inverse result comparing ""**"" and " &
203
                       "Log function over argument range 1.0..1000.0");
204
      end if;
205
 
206
 
207
      -- Testing of Log Function, with specified Base parameter, both
208
      -- instantiated and pre-instantiated versions.
209
 
210
      -- Check that Argument_Error is raised by the Log function with
211
      -- specified Base parameter, when the X parameter value is negative.
212
 
213
      begin
214
         New_Float_Result := GEF.Log(X => -1.0, Base => 16.0);
215
         Report.Failed("Argument_Error not raised by the Log function " &
216
                       "with Base parameter, when the input parameter " &
217
                       "value is -1.0");
218
         Dont_Optimize_New_Float(New_Float_Result, 4);
219
      exception
220
         when Argument_Error => null;  -- OK, expected exception.
221
         when others         =>
222
            Report.Failed("Unexpected exception raised by the Log function " &
223
                          "with Base parameter, when the X parameter value " &
224
                          "is -1.0");
225
      end;
226
 
227
      begin
228
         Float_Result := EF.Log(X => -FXA5A00.Large, Base => 8.0);
229
         Report.Failed("Argument_Error not raised by the Log function " &
230
                       "with Base parameter, when the X parameter "     &
231
                       "value is a large negative value");
232
         Dont_Optimize_Float(Float_Result, 5);
233
      exception
234
         when Argument_Error => null;  -- OK, expected exception.
235
         when others         =>
236
            Report.Failed("Unexpected exception raised by the Log function " &
237
                          "with Base parameter, when the X parameter "       &
238
                          "value is a large negative value");
239
      end;
240
 
241
 
242
      -- Check that Argument_Error is raised by the Log function when
243
      -- the specified Base parameter is zero.
244
 
245
      begin
246
         New_Float_Result := GEF.Log(X => 10.0, Base => 0.0);
247
         Report.Failed("Argument_Error not raised by the Log function " &
248
                       "with Base parameter of 0.0");
249
         Dont_Optimize_New_Float(New_Float_Result, 6);
250
      exception
251
         when Argument_Error => null;  -- OK, expected exception.
252
         when others         =>
253
            Report.Failed("Unexpected exception raised by the Log function " &
254
                          "with Base parameter of 0.0");
255
      end;
256
 
257
 
258
      -- Check that Argument_Error is raised by the Log function when
259
      -- the specified Base parameter is one.
260
 
261
      begin
262
         Float_Result := EF.Log(X => 12.3, Base => 1.0);
263
         Report.Failed("Argument_Error not raised by the Log function " &
264
                       "with Base parameter of 1.0");
265
         Dont_Optimize_Float(Float_Result, 7);
266
      exception
267
         when Argument_Error => null;  -- OK, expected exception.
268
         when others         =>
269
            Report.Failed("Unexpected exception raised by the Log function " &
270
                          "with Base parameter of 1.0");
271
      end;
272
 
273
 
274
      -- Check that Argument_Error is raised by the Log function when
275
      -- the specified Base parameter is negative.
276
 
277
      begin
278
         New_Float_Result := GEF.Log(X => 12.3, Base => -10.0);
279
         Report.Failed("Argument_Error not raised by the Log function " &
280
                       "with negative Base parameter");
281
         Dont_Optimize_New_Float(New_Float_Result, 8);
282
      exception
283
         when Argument_Error => null;  -- OK, expected exception.
284
         when others         =>
285
            Report.Failed("Unexpected exception raised by the Log function " &
286
                          "with negative Base parameter");
287
      end;
288
 
289
 
290
      -- Check that Constraint_Error is raised by the Log function when the
291
      -- input X parameter value is 0.0.
292
 
293
      if New_Float'Machine_Overflows = True then
294
         begin
295
            New_Float_Result := GEF.Log(X => 0.0, Base => 16.0);
296
            Report.Failed("Constraint_Error not raised by the Log function "  &
297
                          "with specified Base parameter, when the value of " &
298
                          "the parameter X is 0.0");
299
            Dont_Optimize_New_Float(New_Float_Result, 9);
300
         exception
301
            when Constraint_Error => null;  -- OK, expected exception.
302
            when others           =>
303
               Report.Failed("Unexpected exception raised by Function Log"    &
304
                             "with specified Base parameter, when the value " &
305
                             "of the parameter X is 0.0");
306
         end;
307
      end if;
308
 
309
      -- Check for the prescribed results of the Log function with specified
310
      -- Base parameter.
311
 
312
      if GEF.Log(X => 1.0, Base => 16.0) /= 0.0 or
313
          EF.Log(X => 1.0, Base => 10.0) /= 0.0 or
314
         GEF.Log(1.0, Base => 8.0)       /= 0.0 or
315
          EF.Log(1.0, 2.0)               /= 0.0
316
      then
317
         Report.Failed("Incorrect result from Function Log with specified " &
318
                       "Base parameter when provided an parameter X input " &
319
                       "value of 1.0");
320
      end if;
321
 
322
 
323
      -- Check that the Log function with specified Base parameter provides
324
      -- correct results when provided a variety of input parameters.
325
 
326
      if not Result_Within_Range(GEF.Log( 10.0,  e),     2.30,  0.01)  or
327
         not Result_Within_Range( EF.Log(  8.0,  2.0),   3.0,   0.01)  or
328
         not Result_Within_Range(GEF.Log(256.0,  2.0),   8.0,   0.01)  or
329
         not Result_Within_Range( EF.Log(512.0,  8.0),   3.0,   0.01)  or
330
         not Result_Within_Range(GEF.Log(0.5649, e),    -0.57,  0.01)  or
331
         not Result_Within_Range( EF.Log(1.7714, e),     0.57,  0.01)  or
332
         not Result_Within_Range(GEF.Log(0.5718, 10.0), -0.243, 0.001) or
333
         not Result_Within_Range( EF.Log(466.25, 10.0),  2.67,  0.01)
334
      then
335
         Report.Failed("Incorrect results from Function Log with specified " &
336
                       "Base parameter, when provided a variety of input "   &
337
                       "parameter values");
338
      end if;
339
 
340
 
341
      Arg := 1.0;
342
      while Arg < 1000.0 and
343
            not (Incorrect_Inverse_Base_2  and Incorrect_Inverse_Base_8 and
344
                 Incorrect_Inverse_Base_10 and Incorrect_Inverse_Base_16)
345
      loop
346
         if not FXA5A00.Result_Within_Range(EF."**"(2.0,EF.Log(Arg,2.0)),
347
                                            Arg,
348
                                            0.001)
349
         then
350
            Incorrect_Inverse_Base_2 := True;
351
         end if;
352
         if not FXA5A00.Result_Within_Range(EF."**"(8.0,EF.Log(Arg,8.0)),
353
                                            Arg,
354
                                            0.001)
355
         then
356
            Incorrect_Inverse_Base_8 := True;
357
         end if;
358
         if not FXA5A00.Result_Within_Range(EF."**"(10.0,EF.Log(Arg,10.0)),
359
                                            Arg,
360
                                            0.001)
361
         then
362
            Incorrect_Inverse_Base_10 := True;
363
         end if;
364
         if not FXA5A00.Result_Within_Range(EF."**"(16.0,EF.Log(Arg,16.0)),
365
                                            Arg,
366
                                            0.001)
367
         then
368
            Incorrect_Inverse_Base_16 := True;
369
         end if;
370
         Arg := Arg + 1.0;
371
      end loop;
372
 
373
      if Incorrect_Inverse_Base_2 then
374
         Report.Failed("Incorrect inverse result comparing ""**"" and " &
375
                       "Log function for Base 2");
376
      end if;
377
 
378
      if Incorrect_Inverse_Base_8 then
379
         Report.Failed("Incorrect inverse result comparing ""**"" and " &
380
                       "Log function for Base 8");
381
      end if;
382
 
383
      if Incorrect_Inverse_Base_10 then
384
         Report.Failed("Incorrect inverse result comparing ""**"" and " &
385
                       "Log function for Base 10");
386
      end if;
387
 
388
      if Incorrect_Inverse_Base_16 then
389
         Report.Failed("Incorrect inverse result comparing ""**"" and " &
390
                       "Log function for Base 16");
391
      end if;
392
 
393
 
394
   exception
395
      when others => Report.Failed ("Exception raised in Test_Block");
396
   end Test_Block;
397
 
398
   Report.Result;
399
 
400
end CXA5A09;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.