跳轉到內容

Ada 程式設計/屬性/'機器基數

來自華夏公益教科書,開放的書籍,開放的世界

Ada. Time-tested, safe and secure.
Ada. 經久耐用,安全可靠。

X'Machine_Radix 是一個 Ada 屬性,其中 X 是任何浮點或定點型別。它返回型別 X 的硬體表示的基數。在大多數機器上,這將是 2。

Machine_Radix 也是一個 Ada 方面,可以透過屬性定義子句為十進位制定點型別設定。該值被限制為 2 或 10。

 with Ada.Text_IO;

 procedure Machine_Radix is

   package T_IO renames Ada.Text_IO;
   package I_IO is new  Ada.Text_IO.Integer_IO (Integer);

   type My_Fixed_Point_Type is delta 0.1 range -1.0 .. 1.0;
   type My_Decimal_Type is delta 0.01 digits 10;
 begin
   T_IO.Put ("Radix of Float type            = ");
   I_IO.Put (Float'Machine_Radix);
   T_IO.New_Line;

   T_IO.Put ("Radix of My_Fixed_Point_Type   = ");
   I_IO.Put (My_Fixed_Point_Type'Machine_Radix);
   T_IO.New_Line;

   T_IO.Put ("Radix of My_Decimal_Type type  = ");
   I_IO.Put (My_Decimal_Type'Machine_Radix);
   T_IO.New_Line;
 end Machine_Radix;


在 x86-64 架構上使用 GNAT 4.6 的輸出是

Radix of Float type            =           2
Radix of My_Fixed_Point_Type   =           2
Radix of My_Decimal_Type type  =           2

另請參閱

[編輯 | 編輯原始碼]

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

[編輯 | 編輯原始碼]
華夏公益教科書