Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Ada Programming/Attributes/'Compose

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Attributes 'Compose __TOC__ Description X'Compose(Fraction : X, Exponent : Integer) is an Ada attribute where X is any floating point type. Floating point types are represented as: where sign is 1 or -1 mantissa is a fraction in base radix radix is the hardware radix (usually 2) exponent is an integer 'Compose(Fraction, Exponent) returns the floating point number Fraction with the exponent replaced with Exponent. Example with Ada.Text_IO; procedure Compose 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, Exp => 0); T_IO.New_Line; for Exp in -2..2 loop T_IO.Put ("Float'Compose(X, " & Integer'Image(Exp) & ") = "); F_IO.Put(Item => Float'Compose(X, Exp), Exp => 0); T_IO.New_Line; end loop; end Compose; The output with GNAT 4.6 on the x86-64 architecture is: X = 1.00000 Float'Compose(X, -2) = 0.12500 Float'Compose(X, -1) = 0.25000 Float'Compose(X, 0) = 0.50000 Float'Compose(X, 1) = 1.00000 Float'Compose(X, 2) = 2.00000 See also Wikibook Ada Programming Ada Programming/Attributes Ada Programming/Attributes/'Fraction Ada Reference Manual 5 3 Attributes of Floating Point Types K Language-Defined Attributes Address Address