File: fixedpnt5.adb

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (58 lines) | stat: -rw-r--r-- 1,754 bytes parent folder | download | duplicates (2)
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
--  { dg-do run }

with Text_IO; use Text_IO;
with Ada.Numerics; use Ada.Numerics;
with Unchecked_Conversion;

procedure Fixedpnt5 is
   --  Test conversions from Floating point to Fixed point types when the
   --  fixed type has a Small that is not a power of two. Verify that the
   --  conversions are reversible, so that:
   --
   --        Fixed_T (Float_T (Fixed_Var)) = Fixed_Var
   --
   --  for a range of fixed values, in particular at the boundary of type.

   type T_Fixed_Type is delta PI/32768.0 range -PI .. PI - PI/32768.0;
   for T_Fixed_Type'Small use PI/32768.0;

   function To_Fix is new Unchecked_Conversion (Short_Integer, T_Fixed_Type);
   Fixed_Point_Var : T_Fixed_Type;
   Float_Var       : Float;

begin
   Fixed_Point_Var := -PI;
   Float_Var       := Float(Fixed_Point_Var);
   Fixed_Point_Var := T_Fixed_Type (Float_Var);

   Fixed_Point_Var := T_Fixed_Type'First;
   Float_Var       := Float(Fixed_Point_Var);
   Fixed_Point_Var := T_Fixed_Type (Float_Var);

   if Fixed_Point_Var /= T_Fixed_Type'First then
      raise Program_Error;
   end if;

   fixed_point_var := t_fixed_type'Last;
   Float_Var       := Float(Fixed_Point_Var);
   Fixed_Point_Var := T_Fixed_Type (Float_Var);

   if Fixed_Point_Var /= T_Fixed_Type'Last then
      raise Program_Error;
   end if;

   for I in  -32768 ..  32767 loop
      fixed_Point_Var := To_Fix (Short_Integer (I));
      Float_Var := Float (Fixed_Point_Var);
      if T_Fixed_Type (Float_Var) /= FIxed_Point_Var then
         Put_Line ("Not reversibloe");
         Put_Line (Integer'Image (I));
         raise Program_Error;
      end if;
   end loop;

   Fixed_Point_Var := T_Fixed_Type (Float_Var * 2.0);
   raise Program_Error;
exception
   when others => null;
end Fixedpnt5;