跳轉到內容

Ada 程式設計/屬性/'截斷

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

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

X'Truncation(Y) 是一個 Ada 屬性,其中 X 是任何浮點型別,Y 是該型別的任何例項。此屬性表示將 Y 截斷為整數。

如果 Y 為負數,則截斷等效於 X'Ceiling(Y)。如果 Y 為正數,則截斷等效於 X'Floor(Y).

X : Float :=  1.5;
Y : Float :=  1.0;
Z : Float := -1.999;
 
pragma Assert (Float'Truncation(X) =  1.0);  -- Ok
pragma Assert (Float'Truncation(Y) =  1.0);  -- Ok
pragma Assert (Float'Truncation(Z) = -1.0);  -- Ok
pragma Assert (Float'Truncation(Z) = -2.0);  -- Wrong

另請參閱

[編輯 | 編輯原始碼]

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

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