跳轉到內容

Ada 程式設計/屬性/'Machine Mantissa

來自 Wikibooks,開放的書籍,為開放的世界

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

X'Machine_Mantissa 是一個 Ada 屬性,其中 X 是任何浮點型別。

浮點型別表示為

其中

sign 是 1 或 -1
mantissa 是以基數為底的幾分之一
radix 是硬體基數(通常為 2)
exponent 是一個整數

'Machine_Mantissa 返回尾數中最大位數。

with Ada.Text_IO;

procedure Machine_Mantissa is

   package T_IO renames Ada.Text_IO;
   package I_IO is new  Ada.Text_IO.Integer_IO (Integer);
begin
   T_IO.Put ("Mantissa of Float type       = ");
   I_IO.Put (Float'Machine_Mantissa);
   T_IO.New_Line;
   
   T_IO.Put ("Mantissa of Long_Float type  = ");
   I_IO.Put (Long_Float'Machine_Mantissa);
   T_IO.New_Line;

end Machine_Mantissa;

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

Mantissa of Float type       =          24
Mantissa of Long_Float type  =          53

另請參閱

[編輯 | 編輯原始碼]

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

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