Ada Programming/Attributes/'Adjacent


Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Description edit

S'Adjacent(X, T) is an Ada attribute where X is any floating point type.

'Adjacent returns the adjacent floating point number to X in the direction of T.

Example edit

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;

The output with GNAT 4.6 on the x86-64 architecture is:

                             X =  1.0000000000
Float'Adjacent(X, Float'First) =  0.9999999404
Float'Adjacent(X, Float'Last)  =  1.0000001192

See also edit

Wikibook edit

Ada Reference Manual edit