Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gnat.dg / fixedpnt5.adb
blob7175ddc13f518096e61439cbd66145185ae24d0a
1 -- { dg-do run }
3 with Text_IO; use Text_IO;
4 with Ada.Numerics; use Ada.Numerics;
5 with Unchecked_Conversion;
7 procedure Fixedpnt5 is
8 -- Test conversions from Floating point to Fixed point types when the
9 -- fixed type has a Small that is not a power of two. Verify that the
10 -- conversions are reversible, so that:
12 -- Fixed_T (Float_T (Fixed_Var)) = Fixed_Var
14 -- for a range of fixed values, in particular at the boundary of type.
16 type T_Fixed_Type is delta PI/32768.0 range -PI .. PI - PI/32768.0;
17 for T_Fixed_Type'Small use PI/32768.0;
19 function To_Fix is new Unchecked_Conversion (Short_Integer, T_Fixed_Type);
20 Fixed_Point_Var : T_Fixed_Type;
21 Float_Var : Float;
23 begin
24 Fixed_Point_Var := -PI;
25 Float_Var := Float(Fixed_Point_Var);
26 Fixed_Point_Var := T_Fixed_Type (Float_Var);
28 Fixed_Point_Var := T_Fixed_Type'First;
29 Float_Var := Float(Fixed_Point_Var);
30 Fixed_Point_Var := T_Fixed_Type (Float_Var);
32 if Fixed_Point_Var /= T_Fixed_Type'First then
33 raise Program_Error;
34 end if;
36 fixed_point_var := t_fixed_type'Last;
37 Float_Var := Float(Fixed_Point_Var);
38 Fixed_Point_Var := T_Fixed_Type (Float_Var);
40 if Fixed_Point_Var /= T_Fixed_Type'Last then
41 raise Program_Error;
42 end if;
44 for I in -32768 .. 32767 loop
45 fixed_Point_Var := To_Fix (Short_Integer (I));
46 Float_Var := Float (Fixed_Point_Var);
47 if T_Fixed_Type (Float_Var) /= FIxed_Point_Var then
48 Put_Line ("Not reversibloe");
49 Put_Line (Integer'Image (I));
50 raise Program_Error;
51 end if;
52 end loop;
54 Fixed_Point_Var := T_Fixed_Type (Float_Var * 2.0);
55 raise Program_Error;
56 exception
57 when others => null;
58 end Fixedpnt5;