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

  1.                                        -- Chapter 6 - Program 5
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure FloatVar is
  6.  
  7.    PI     : constant := 3.1416;
  8.    TWO_PI : constant := 2 * PI;
  9.  
  10.    R : FLOAT;
  11.  
  12.    type MY_FLOAT is digits 7;
  13.    type MY_LONG_FLOAT is digits 15;
  14.  
  15.    Area   : MY_FLOAT := 2.345_12e4;     -- This is 23451.2
  16.    Length : MY_FLOAT := 25.123;
  17.    Factor : MY_FLOAT := 8.89;
  18.    Cover  : MY_LONG_FLOAT;
  19.    What   : BOOLEAN;
  20.    Index  : INTEGER := 4;
  21.  
  22.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  23.    use Int_IO;
  24.    package Flt_IO is new Text_IO.Float_IO(MY_FLOAT);
  25.    use Flt_IO;
  26.  
  27. begin
  28.                            -- Arithmetic float operations
  29.    Area := Length + Factor + 12.56;
  30.    Area := Length - Factor - 12.56;
  31.    Area := Length * Factor * 2#111.0#;   -- this is decimal 7.0
  32.    Area := Length / Factor;
  33.    Area := Length ** 3;
  34.    Area := Length ** (-3);
  35.    Area := Length ** Index;
  36.  
  37.                            -- Arithmetic logical compares
  38.    What := Length =  Factor;
  39.    What := Length /= Factor;
  40.    What := Length >  Factor;
  41.    What := Length >= Factor;
  42.    What := Length <  Factor;
  43.    What := Length <= Factor;
  44.  
  45.    Area := 0.0031 + (0.027_3 * TWO_PI) / (Length ** (-Index/2));
  46.    Cover := 27.3 * TWO_PI * MY_LONG_FLOAT(Area);
  47.  
  48.    Put("Area is now ");
  49.    Put(Area);
  50.    Put(Area,5);
  51.    New_Line;
  52.  
  53.    Put("Area is now ");
  54.    Put(Area,5,5);
  55.    Put(Area,5,5,0);
  56.    New_Line;
  57.  
  58.    Put("MY_FLOAT'DIGITS =      ");
  59.    Put(MY_FLOAT'DIGITS);
  60.    New_Line;
  61.    Put("MY_FLOAT'SMALL =       ");
  62.    Put(MY_FLOAT'SMALL);
  63.    New_Line;
  64.    Put("MY_FLOAT'LARGE =       ");
  65.    Put(MY_FLOAT'LARGE);
  66.    New_Line;
  67.    Put("MY_FLOAT'BASE'FIRST =  ");
  68.    Put(MY_FLOAT'BASE'FIRST);
  69.    New_Line;
  70.    Put("MY_FLOAT'BASE'LAST =   ");
  71.    Put(MY_FLOAT'BASE'LAST);
  72.    New_Line;
  73.  
  74. end FloatVar;
  75.  
  76.  
  77.  
  78.  
  79. -- Result of execution
  80.  
  81. -- Area is now  1.082677E+02    1.082677E+02
  82. -- Area is now     1.08268E+02  108.26771
  83. -- MY_FLOAT'DIGITS =           7
  84. -- MY_FLOAT'SMALL =        3.944305E-31
  85. -- MY_FLOAT'LARGE =        1.267651E+30
  86. -- MY_FLOAT'BASE'FIRST =  -1.797693E+308
  87. -- MY_FLOAT'BASE'LAST =    1.797693E+308
  88.  
  89.