Ada 程式設計/屬性/'機器基數
外觀
X'Machine_Radix 是一個 Ada 屬性,其中 X 是任何浮點或定點型別。它返回型別 X 的硬體表示的基數。在大多數機器上,這將是 2。
Machine_Radix 也是一個 Ada 方面,可以透過屬性定義子句為十進位制定點型別設定。該值被限制為 2 或 10。
withAda.Text_IO;procedureMachine_RadixispackageT_IOrenamesAda.Text_IO;packageI_IOisnewAda.Text_IO.Integer_IO (Integer);typeMy_Fixed_Point_Typeisdelta0.1range-1.0 .. 1.0;typeMy_Decimal_Typeisdelta0.01digits10;beginT_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;endMachine_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
