025.Ada的浮点类型变量

with Ada.Text_IO;
use Ada.Text_IO;

procedure FloatVar is
   
   PI	: constant :=3.1416;
   TWO_PI:constant :=2*PI;
   
   R : Float;
   
   type MY_FLOAT is digits 7;
   type MY_LONG_FLOAT is digits 15;
   
   Area :MY_FLOAT:=2.345_12e4; -- This is 23451.2
   Length:MY_FLOAT:=25.123;
   Factor :MY_FLOAT:=8.89;
   Cover :MY_LONG_FLOAT;
   What :Boolean;
   Index :Integer :=4;
   -- instantiate a copy of the Integer_IO package and a copy
   -- of the Float_IO package for use with the types INTEGER
   -- and MY_FLOAT and use it in lines 49 through 55.
   package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
   use Int_IO;
   
   package Flt_IO is new Ada.Text_IO.Float_IO(MY_FLOAT);
   use Flt_IO;
   
begin
   -- Arithmetic float operations
   Area :=Length+Factor+12.56;
   Area :=Length-Factor-12.56;
   Area := Length * Factor * 2#111.0#;   -- this is decimal 7.0
   Area := Length / Factor;
   Area := Length ** 3;
   Area := Length ** (-3);
   Area := Length ** Index;

   -- Arithmetic logical compares
   What := Length =  Factor;
   What := Length /= Factor;
   What := Length >  Factor;
   What := Length >= Factor;
   What := Length <  Factor;
   What := Length <= Factor;

   Area := 0.0031 + (0.027_3 * TWO_PI) / (Length ** (-Index/2));
   Cover := 27.3 * TWO_PI * MY_LONG_FLOAT(Area);

   Put("Area is now ");
   Put(Area);
   Put(Area,5);
   New_Line;

   Put("Area is now ");
   Put(Area,5,5);
   Put(Area,5,5,0);
   New_Line;

   Put("MY_FLOAT'DIGITS =      ");
   Put(MY_FLOAT'DIGITS);
   New_Line;
   Put("MY_FLOAT'BASE'FIRST =  ");
   Put(MY_FLOAT'BASE'FIRST);
   New_Line;
   Put("MY_FLOAT'BASE'LAST =   ");
   Put(MY_FLOAT'BASE'LAST);
   New_Line;

end FloatVar;   
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值