3 with Text_IO
; use Text_IO
;
4 with Ada
.Numerics
; use Ada
.Numerics
;
5 with Unchecked_Conversion
;
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
;
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
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
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
));
54 Fixed_Point_Var
:= T_Fixed_Type
(Float_Var
* 2.0);