home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / fixed.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  2.2 KB  |  89 lines

  1.                                        -- Chapter 6 - Program 6
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Fixed is
  6.  
  7.    COARSE_PI : constant := 3.15;
  8.  
  9.    type MY_FIXED is delta 0.1  range -40.0..120.0;
  10.    type ANGLE    is delta 0.05 range -COARSE_PI..COARSE_PI;
  11.  
  12.    Theta, Omega, Phi : ANGLE := 0.50;
  13.    Funny_Value : MY_FIXED;
  14.  
  15.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  16.    use Int_IO;
  17.    package Fix_IO is new Text_IO.Fixed_IO(MY_FIXED);
  18.    use Fix_IO;
  19.    package Fix2_IO is new Text_IO.Fixed_IO(ANGLE);
  20.    use Fix2_IO;
  21.    package Flt_IO is new Text_IO.Float_IO(FLOAT);
  22.    use Flt_IO;
  23.  
  24. begin
  25.  
  26.    Put("Theta starts off with the value");
  27.    Put(Theta,5,2,0);
  28.    New_Line(2);
  29.  
  30.    Theta := Omega + Phi;
  31.    Theta := Omega - Phi;
  32.    Theta := 5 * Omega - 2 * Phi;
  33.    Theta := ANGLE(Omega * Phi);
  34.    Theta := ANGLE(3 * Omega / Phi);
  35.    Theta := abs(Omega - 3 * Phi);
  36.  
  37.    Funny_Value := 5.1;
  38.    for Index in 1..10 loop
  39.       Put("Funny_Value is now");
  40.       Put(Funny_Value,5,1,0);
  41.       Put(Funny_Value,5,5,0);
  42.       Funny_Value := MY_FIXED(Funny_Value * MY_FIXED(1.1));
  43.       New_Line;
  44.    end loop;
  45.  
  46.    New_Line;
  47.    Put("MY_FIXED'DELTA = ");
  48.    Put(MY_FIXED(MY_FIXED'DELTA));
  49.    New_Line;
  50.    Put("MY_FIXED'SMALL = ");
  51.    Put(FLOAT(MY_FIXED'SMALL));
  52.    New_Line;
  53.    Put("MY_FIXED'LARGE = ");
  54.    Put(FLOAT(MY_FIXED'LARGE));
  55.    New_Line;
  56.    Put("MY_FIXED'FIRST = ");
  57.    Put(MY_FIXED'FIRST);
  58.    New_Line;
  59.    Put("MY_FIXED'LAST =  ");
  60.    Put(MY_FIXED'LAST);
  61.    New_Line;
  62.  
  63. end Fixed;
  64.  
  65.  
  66.  
  67.  
  68. -- Result of execution
  69.  
  70. -- Theta starts off with the value    0.50
  71. --
  72. -- Funny_Value is now    5.1    5.06250
  73. -- Funny_Value is now    5.4    5.37500
  74. -- Funny_Value is now    5.7    5.68750
  75. -- Funny_Value is now    6.0    6.00000
  76. -- Funny_Value is now    6.4    6.37500
  77. -- Funny_Value is now    6.8    6.75000
  78. -- Funny_Value is now    7.1    7.12550
  79. -- Funny_Value is now    7.6    7.56250
  80. -- Funny_Value is now    8.0    8.00000
  81. -- Funny_Value is now    8.5    8.50000
  82. --
  83. -- MY_FIXED'DELTA =    0.1
  84. -- MY_FIXED'SMALL =  6.25000000000000E-02
  85. -- MY_FIXED'LARGE =  1.27937500000000E+02
  86. -- MY_FIXED'FIRST =  -40.0
  87. -- MY_FIXED'LAST  =  120.0
  88.  
  89.