summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxa5015.a
blob: e1035db271be47cbdbbb0767d9f3e6547bdfa3b9 (plain)
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
-- CXA5015.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 following representation-oriented attributes are 
--      available and that the produce correct results: 
--      'Denorm, 'Signed_Zeros, 'Exponent 'Fraction, 'Compose, 'Scaling, 
--      'Floor, 'Ceiling, 'Rounding, 'Unbiased_Rounding, 'Truncation, 
--      'Remainder, 'Adjacent, 'Copy_Sign, 'Leading_Part, 'Machine, and 
--      'Model_Small.
--      
-- TEST DESCRIPTION:
--      This test checks whether certain attributes of floating point types
--      are available from an implementation.  Where attribute correctness 
--      can be verified in a straight forward manner, the appropriate checks 
--      are included here.  However, this test is not intended to ensure the 
--      correctness of the results returned from all of the attributes 
--      examined in this test; that process will occur in the tests of the 
--      Numerics_Annex. 
--      
--       
-- CHANGE HISTORY:
--      26 Jun 95   SAIC    Initial prerelease version.
--      29 Apr 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--      01 DEC 97   EDS     Fix value for checking the S'Adjacent attribute
--!

with Report;

procedure CXA5015 is

   subtype Float_Subtype   is Float range -10.0..10.0;
   type    Derived_Float_1 is digits  8;
   type    Derived_Float_2 is new Derived_Float_1 range -10.0..10.0E10;

   use type Float, Float_Subtype, Derived_Float_1, Derived_Float_2;

   TC_Boolean   : Boolean;
   TC_Float     : Float;
   TC_SFloat    : Float_Subtype;
   TC_DFloat_1  : Derived_Float_1;
   TC_DFloat_2  : Derived_Float_2;
   TC_Tolerance : Float := 0.001;

   function Not_Equal (Actual_Result, Expected_Result, Tolerance : Float)
     return Boolean is
   begin
      return abs(Actual_Result - Expected_Result) > Tolerance;
   end Not_Equal;


begin

   Report.Test ("CXA5015", "Check that certain representation-oriented " &
                           "attributes are available and that they "     &
                           "produce correct results");

   -- New Representation-Oriented Attributes.
   --
   -- Check the S'Denorm attribute.

   TC_Boolean := Float'Denorm;
   TC_Boolean := Float_Subtype'Denorm;
   TC_Boolean := Derived_Float_1'Denorm;
   TC_Boolean := Derived_Float_2'Denorm;


   -- Check the S'Signed_Zeroes attribute.

   TC_Boolean := Float'Signed_Zeros;
   TC_Boolean := Float_Subtype'Signed_Zeros;
   TC_Boolean := Derived_Float_1'Signed_Zeros;
   TC_Boolean := Derived_Float_2'Signed_Zeros;


   -- New Primitive Function Attributes.
   --
   -- Check the S'Exponent attribute.

   TC_Float    := 0.5;
   TC_SFloat   := 0.99;
   TC_DFloat_1 := 2.45;
   TC_DFloat_2 := 2.65;

   if Float'Exponent(TC_Float) > Float_Subtype'Exponent(TC_SFloat) or
      Float'Exponent(TC_Float) > 2
   then
      Report.Failed("Incorrect result from the 'Exponent attribute");
   end if;


   -- Check the S'Fraction attribute.

   if Not_Equal 
        (Float'Fraction(TC_Float), 
         TC_Float * Float(Float'Machine_Radix)**(-Float'Exponent(TC_Float)),
         TC_Tolerance)
   then
      Report.Failed("Incorrect result from the 'Fraction attribute - 1");
   end if;

   if Float'Fraction(TC_Float) < 
      (1.0/Float(Float'Machine_Radix)) - TC_Tolerance  or
      Float'Fraction(TC_Float) >= 1.0 - TC_Tolerance    
   then
      Report.Failed("Incorrect result from the 'Fraction attribute - 2");
   end if;


   -- Check the S'Compose attribute.

   if Not_Equal 
       (Float'Compose(TC_Float, 3),
        TC_Float * Float(Float'Machine_Radix)**(3-Float'Exponent(TC_Float)),
        TC_Tolerance)
   then
      Report.Failed("Incorrect result from the 'Compose attribute");
   end if;


   -- Check the S'Scaling attribute.

   if Not_Equal 
        (Float'Scaling(TC_Float, 2),
         TC_Float * Float(Float'Machine_Radix)**2,
         TC_Tolerance)
   then
      Report.Failed("Incorrect result from the 'Scaling attribute");
   end if;


   -- Check the S'Floor attribute.

   TC_Float    :=  0.99;
   TC_SFloat   :=  1.00;
   TC_DFloat_1 :=  2.50;
   TC_DFloat_2 := -2.50;

   if Float'Floor(TC_Float)               /=  0.0  or
      Float_Subtype'Floor(TC_SFloat)      /=  1.0  or
      Derived_Float_1'Floor(TC_DFloat_1)  /=  2.0  or
      Derived_Float_2'Floor(TC_DFloat_2)  /= -3.0
   then
      Report.Failed("Incorrect result from the 'Floor attribute");
   end if;


   -- Check the S'Ceiling attribute.

   TC_Float    :=  0.99;
   TC_SFloat   :=  1.00;
   TC_DFloat_1 :=  2.50;
   TC_DFloat_2 := -2.99;

   if Float'Ceiling(TC_Float)               /=  1.0  or
      Float_Subtype'Ceiling(TC_SFloat)      /=  1.0  or
      Derived_Float_1'Ceiling(TC_DFloat_1)  /=  3.0  or
      Derived_Float_2'Ceiling(TC_DFloat_2)  /= -2.0
   then
      Report.Failed("Incorrect result from the 'Ceiling attribute");
   end if;


   -- Check the S'Rounding attribute.

   TC_Float    :=  0.49;
   TC_SFloat   :=  1.00;
   TC_DFloat_1 :=  2.50;
   TC_DFloat_2 := -2.50;

   if Float'Rounding(TC_Float)               /=  0.0  or
      Float_Subtype'Rounding(TC_SFloat)      /=  1.0  or
      Derived_Float_1'Rounding(TC_DFloat_1)  /=  3.0  or
      Derived_Float_2'Rounding(TC_DFloat_2)  /= -3.0
   then
      Report.Failed("Incorrect result from the 'Rounding attribute");
   end if;


   -- Check the S'Unbiased_Rounding attribute.

   TC_Float    :=  0.50;
   TC_SFloat   :=  1.50;
   TC_DFloat_1 :=  2.50;
   TC_DFloat_2 := -2.50;

   if Float'Unbiased_Rounding(TC_Float)               /=  0.0  or
      Float_Subtype'Unbiased_Rounding(TC_SFloat)      /=  2.0  or
      Derived_Float_1'Unbiased_Rounding(TC_DFloat_1)  /=  2.0  or
      Derived_Float_2'Unbiased_Rounding(TC_DFloat_2)  /= -2.0
   then
      Report.Failed("Incorrect result from the 'Unbiased_Rounding " &
                    "attribute");
   end if;


   -- Check the S'Truncation attribute.

   TC_Float    := -0.99;
   TC_SFloat   :=  1.50;
   TC_DFloat_1 :=  2.99;
   TC_DFloat_2 := -2.50;

   if Float'Truncation(TC_Float)               /=  0.0  or
      Float_Subtype'Truncation(TC_SFloat)      /=  1.0  or
      Derived_Float_1'Truncation(TC_DFloat_1)  /=  2.0  or
      Derived_Float_2'Truncation(TC_DFloat_2)  /= -2.0
   then
      Report.Failed("Incorrect result from the 'Truncation attribute");
   end if;


   -- Check the S'Remainder attribute.

   TC_Float    :=  9.0;
   TC_SFloat   :=  7.5;
   TC_DFloat_1 :=  5.0;
   TC_DFloat_2 :=  8.0;

   if Float'Remainder(TC_Float, 2.0)                /=  1.0  or
      Float_Subtype'Remainder(TC_SFloat, 3.0)       /=  1.5  or
      Derived_Float_1'Remainder(TC_DFloat_1, 2.0)   /=  1.0  or
      Derived_Float_2'Remainder(TC_DFloat_2, 4.0)   /=  0.0
   then
      Report.Failed("Incorrect result from the 'Remainder attribute");
   end if;


   -- Check the S'Adjacent attribute.

   TC_Float    :=  4.0;
   TC_SFloat   := -1.0;

   if Float'Adjacent(TC_Float, TC_Float)           /=  TC_Float  or
      Float_Subtype'Adjacent(TC_SFloat, -1.0)      /=  TC_SFloat 
   then
      Report.Failed("Incorrect result from the 'Adjacent attribute");
   end if;


   -- Check the S'Copy_Sign attribute.

   TC_Float    :=  0.0;
   TC_SFloat   := -1.0;
   TC_DFloat_1 :=  5.0;
   TC_DFloat_2 := -2.5;

   if Float'Copy_Sign(TC_Float, -2.0)               /=  0.0  or
      Float_Subtype'Copy_Sign(TC_SFloat, 4.0)       /=  1.0  or
      Derived_Float_1'Copy_Sign(TC_DFloat_1, -2.0)  /= -5.0  or
      Derived_Float_2'Copy_Sign(TC_DFloat_2, -2.0)  /= -2.5
   then
      Report.Failed("Incorrect result from the 'Copy_Sign attribute");
   end if;


   -- Check the S'Leading_Part attribute.

   TC_Float    :=  0.0;
   TC_SFloat   := -1.0;
   TC_DFloat_1 :=  5.88;
   TC_DFloat_2 := -2.52;

   -- Leading part obtained in the variables.
   TC_Float    :=  Float'Leading_Part(TC_Float, 2);
   TC_SFloat   :=  Float_Subtype'Leading_Part(TC_SFloat, 2);
   TC_DFloat_1 :=  Derived_Float_1'Leading_Part(TC_DFloat_1, 2);
   TC_DFloat_2 :=  Derived_Float_2'Leading_Part(TC_DFloat_2, 2);

   -- Checking for the leading part of the variables at this point should
   -- produce the same values.
   if Float'Leading_Part(TC_Float, 2)              /= TC_Float    or
      Float_Subtype'Leading_Part(TC_SFloat, 2)     /= TC_SFloat   or
      Derived_Float_1'Leading_Part(TC_DFloat_1, 2) /= TC_DFloat_1 or
      Derived_Float_2'Leading_Part(TC_DFloat_2, 2) /= TC_DFloat_2
   then
      Report.Failed("Incorrect result from the 'Leading_Part attribute");
   end if;


   -- Check the S'Machine attribute.

   TC_Float    :=  0.0;
   TC_SFloat   := -1.0;
   TC_DFloat_1 :=  5.88;
   TC_DFloat_2 := -2.52;

   -- Closest machine number obtained in the variables.
   TC_Float    :=  Float'Machine(TC_Float);
   TC_SFloat   :=  Float_Subtype'Machine(TC_SFloat);
   TC_DFloat_1 :=  Derived_Float_1'Machine(TC_DFloat_1);
   TC_DFloat_2 :=  Derived_Float_2'Machine(TC_DFloat_2);

   -- Checking for the closest machine number to each of the variables at 
   -- this point should produce the same values.
   if Float'Machine(TC_Float)              /= TC_Float    or
      Float_Subtype'Machine(TC_SFloat)     /= TC_SFloat   or
      Derived_Float_1'Machine(TC_DFloat_1) /= TC_DFloat_1 or
      Derived_Float_2'Machine(TC_DFloat_2) /= TC_DFloat_2
   then
      Report.Failed("Incorrect result from the 'Machine attribute");
   end if;


   -- New Model-Oriented Attributes.
   --
   -- Check the S'Model_Small attribute.

   if Not_Equal 
        (Float'Model_Small,
         Float(Float'Machine_Radix)**(Float'Model_Emin-1),
         TC_Tolerance)
   then
      Report.Failed("Incorrect result from the 'Model_Small attribute");
   end if;


   Report.Result;

end CXA5015;