Ada Programming/Attributes/'Machine Radix


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

Description

X'Machine_Radix is an Ada attribute where X is any floating or fixed point type. It returns the radix of the hardware representation of type X. On most machines this will be 2.

Machine_Radix is also an Ada aspect that may be set for decimal fixed point types via an attribute definition clause. The value is constrained to either 2 or 10.

Example

 with Ada.Text_IO;

 procedure Machine_Radix is

   package T_IO renames Ada.Category:Book:Ada Programming/Pages containing deprecated templatesText_IO;
   package I_IO is new  Ada.Category:Book:Ada Programming/Pages containing deprecated templatesText_IO.Category:Book:Ada Programming/Pages containing deprecated templatesInteger_IO (Integer);

   type My_Fixed_Point_Type is delta 0.Category:Book:Ada Programming/Pages containing deprecated templates1 range -1.Category:Book:Ada Programming/Pages containing deprecated templates0 ..Category:Book:Ada Programming/Pages containing deprecated templates 1.Category:Book:Ada Programming/Pages containing deprecated templates0;
   type My_Decimal_Type is delta 0.Category:Book:Ada Programming/Pages containing deprecated templates01 digits 10;
 begin
   T_IO.Category:Book:Ada Programming/Pages containing deprecated templatesPut ("Radix of Float type            = ");
   I_IO.Category:Book:Ada Programming/Pages containing deprecated templatesPut (Float'Machine_Radix);
   T_IO.Category:Book:Ada Programming/Pages containing deprecated templatesNew_Line;

   T_IO.Category:Book:Ada Programming/Pages containing deprecated templatesPut ("Radix of My_Fixed_Point_Type   = ");
   I_IO.Category:Book:Ada Programming/Pages containing deprecated templatesPut (My_Fixed_Point_Type'Machine_Radix);
   T_IO.Category:Book:Ada Programming/Pages containing deprecated templatesNew_Line;

   T_IO.Category:Book:Ada Programming/Pages containing deprecated templatesPut ("Radix of My_Decimal_Type type  = ");
   I_IO.Category:Book:Ada Programming/Pages containing deprecated templatesPut (My_Decimal_Type'Machine_Radix);
   T_IO.Category:Book:Ada Programming/Pages containing deprecated templatesNew_Line;
 end Machine_Radix;


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

Radix of Float type            =           2
Radix of My_Fixed_Point_Type   =           2
Radix of My_Decimal_Type type  =           2

See also

Wikibook

Ada Reference Manual

Category:Book:Ada Programming#Address Category:Book:Ada Programming/Representation attributes#Address
Category:Book:Ada Programming Category:Book:Ada Programming/Pages containing deprecated templates Category:Book:Ada Programming/Representation attributes