Ada 编程/属性/'Adjacent
外观
S'Adjacent(X, T) 是一个 Ada 属性,其中 X 是任何浮点类型。
'Adjacent 返回 X 在 T 方向上的相邻浮点数。
with Ada.Text_IO; procedure Adjacent is package T_IO renames Ada.Text_IO; package F_IO is new Ada.Text_IO.Float_IO (Float); X : Float := 1.0; begin T_IO.Put (" X = "); F_IO.Put(Item => X, Aft => 10, Exp => 0); T_IO.New_Line; T_IO.Put ("Float'Adjacent(X, Float'First) = "); F_IO.Put(Item => Float'Adjacent(X, Float'First), Aft => 10, Exp => 0); T_IO.New_Line; T_IO.Put ("Float'Adjacent(X, Float'Last) = "); F_IO.Put(Item => Float'Adjacent(X, Float'Last), Aft => 10, Exp => 0); T_IO.New_Line; end Adjacent;
在 x86-64 架构上使用 GNAT 4.6 的输出是
X = 1.0000000000 Float'Adjacent(X, Float'First) = 0.9999999404 Float'Adjacent(X, Float'Last) = 1.0000001192
- 5.3 浮点类型的属性 (带注释)
- 附录 K 语言定义属性 (带注释)