HP OpenVMS Systems

Content starts here

DEC Ada
Technical Overview and Comparison on DIGITAL Platforms


Previous Contents Index


Chapter 2
Types and Objects

One of the key features of Ada is its strong type definition. Given that a type is a collection of objects (values) together with the operations used to manipulate them, for each Ada object, the DEC Ada compiler determines the following:

  • How much storage is required
  • Where and when that storage is allocated and deallocated
  • How the different values of the object are represented

In general, the compiler chooses storage sizes and representations that make the best compromise between CPU time, the amount of memory required for the generated code, and the amount of memory required for the objects.

Types can be predefined (language-defined), implementation-defined, or user-defined.

DEC Ada provides the following types:

  • Scalar types (integer, real, and types defined by the enumeration of their values)
  • Composite types (array and record)
  • Access types
  • Private types
  • Task types

2.1 Integer Types

DEC Ada provides the predefined integer types shown in Table 2-1.

Table 2-1 Predefined Integer Types
Predefined Type Range of Values Platform
LONG_INTEGER --2 31 .. 2 31--1
(or --2,147,483,648 .. 2,147,483,647)

--2 63 .. 2 63--1

OpenVMS VAX


OpenVMS Alpha,
DIGITAL UNIX

     
INTEGER --2 31 .. 2 31--1
(or --2,147,483,648 .. 2,147,483,647)
All
     
SHORT_INTEGER --2 15 .. 2 15--1
(or --32,768 .. 32,767)
All
     
SHORT_SHORT_INTEGER --2 7 .. 2 7--1
(or --128 .. 127)
All

Additional integer types are declared in the package SYSTEM for convenience in working with hardware-oriented storage.

On OpenVMS Alpha systems, the value of LONG_INTEGER is 64 bits. User-defined integer types can be 64 bits, provided that their range is large enough. On OpenVMS VAX systems, the maximum integer size is 32 bits. These sizes are defined in the package STANDARD.

OpenVMS VAX, OpenVMS Alpha, and DIGITAL UNIX systems define the following types:

  • INTEGER_8
  • INTEGER_16
  • INTEGER_32

OpenVMS Alpha and DIGITAL UNIX systems also define the type INTEGER_64.

Values for objects of all four integer types are represented as signed, two's complement (binary) numbers.

Unsigned representation for integer objects can be achieved by declaring an integer type with a length representation clause. However, because of the way the Ada language defined integer operations, operations on these unsigned objects involve signed intermediate values.

Data representation depends on the properties of the underlying hardware and/or operating system. DEC Ada represents integer and enumeration types as follows:

  • On OpenVMS VAX and on ULTRIX systems, signed and unsigned 8-bit (byte), 16-bit (word), and 32-bit (longword) quantities are used.
  • On OpenVMS Alpha and DIGITAL UNIX systems, signed and unsigned 8-bit (byte), 16-bit (word), 32-bit (longword), and 64-bit (quadword) quantities are used.

These can optionally be packed and bit-aligned within records and arrays.

For a size specification for a discrete type, the given size must not exceed the maximum size (in bits) for the given type. On OpenVMS VAX systems, the maximum size is 32 bits. On OpenVMS Alpha, DIGITAL UNIX, and ULTRIX systems, the maximum size is 64 bits for integer and enumeration types.

2.2 Floating-Point Types

Floating-point types provide approximations to the real numbers (with relative bounds on the errors). For each floating-point type (predefined and nonpredefined), the compiler chooses a hardware floating-point representation depending on:

  • Required range and accuracy of the floating-point type
  • Value of the pragma FLOAT_REPRESENTATION
  • Value of the pragma LONG_FLOAT

On OpenVMS VAX systems, the following floating-point representations are possible:

  • F-floating
  • D-floating
  • G-floating
  • H-floating

On OpenVMS Alpha systems, the following floating-point representations are possible:

  • F-floating
  • D-floating
  • G-floating
  • IEEE single float
  • IEEE double float

On OpenVMS Alpha systems, data is stored as D-floating and is converted to G-floating for operations (such as addition). G-floating instructions involve loss of precision.

Note

Note that there are no H-floating instructions on OpenVMS Alpha machines, and there is no way to simulate an H-floating type.

On DIGITAL UNIX systems, the following floating-point representations are possible:

  • IEEE single float
  • IEEE double float

The compiler uses chosen representation and size for all objects of the type, regardless of the objects' subtypes and regardless of whether or not the objects are themselves part of packed array or record objects.

DEC Ada provides the floating-point types declared in the package STANDARD as shown in Table 2-2.

Table 2-2 Predefined Floating-Point Types---Package STANDARD
Type Platform Default Representation1 Size (Bits) Digits of Precision
FLOAT OpenVMS

DIGITAL UNIX

F-floating

IEEE single float

32

32

6

6

LONG_FLOAT OpenVMS

DIGITAL UNIX

G-floating

IEEE double float

64

64

15

15

LONG_LONG_FLOAT OpenVMS VAX

OpenVMS Alpha

DIGITAL UNIX

H-floating

G-floating

IEEE double float

128

64

64

33

15

15


1On some platforms, the pragmas FLOAT_REPRESENTATION and LONG_FLOAT can be used to change the representation.

DEC Ada provides additional floating-point types declared in the package SYSTEM as shown in Table 2-3.

Table 2-3 Predefined Floating-Point Types---Package SYSTEM
Predefined Type Platform Size (Bits)
F_FLOAT OpenVMS 32
D_FLOAT OpenVMS 64
G_FLOAT OpenVMS 64
H_FLOAT OpenVMS VAX only 128
IEEE_SINGLE_FLOAT OpenVMS Alpha only 32
IEEE_DOUBLE_FLOAT OpenVMS Alpha only 64

Note

For users porting applications using H_FLOAT from OpenVMS VAX systems to OpenVMS Alpha systems and requiring H_FLOAT precision, there is a simple (although unsupported) way to convert between H_FLOAT and X_FLOAT (IEEE Extended Floating-Point). There is a user-defined package containing a private type called "x_float" and all the usual arithmetic operations defined on it. These operations are implemented in Fortran (which does support x_float directly as REAL*16). See Appendix B for the exact code.

It would be necessary to modify the application to use this package. Most arithmetic operations would not need to be changed because Ada overloading handles +, -, *, /. However, some constructs, such as floating-point literals, would need source changes.

DEC Ada supports user-defined floating-point types. The choice of representation for nonpredefined floating-point types that are not explicitly derived depends on the precision (digits) and the range specified. The compiler chooses the first of the types FLOAT, LONG_FLOAT, and LONG_LONG_FLOAT (OpenVMS VAX systems only) that has adequate precision and range and uses it as the parent type from which the new type is derived.

The type SHORT_FLOAT is not supported by the DEC Ada compiler.

2.2.1 Pragma FLOAT_REPRESENTATION

DEC Ada provides the pragma FLOAT_REPRESENTATION, which acts as a program library switch to allow control over the internal representation chosen for the predefined floating-point types declared in the packages STANDARD and SYSTEM. The format of this pragma is as follows:

pragma FLOAT_REPRESENTATION(VAX_FLOAT | IEEE_FLOAT);

This pragma controls the representation of floating-point types as follows:

  • If the value VAX_FLOAT is specified, then floating-point types are represented with the VAX hardware types F-floating, D-floating, G-floating, and H-floating. H-floating is available on OpenVMS VAX systems only.
    If the value is VAX_FLOAT, the default representation of the predefined type LONG_FLOAT is G-floating. The representation can be changed with the pragma LONG_FLOAT.
  • If the value IEEE_FLOAT is specified, then floating-point types are represented with the IEEE single and double floating-point types.

On OpenVMS VAX systems, VAX_FLOAT is the default and only allowable value for the pragma.

On OpenVMS Alpha systems, the values allowed are VAX_FLOAT and IEEE_FLOAT. The predefined library is compiled with VAX_FLOAT specified for the pragma FLOAT_REPRESENTATION, and VAX_FLOAT is required for interface to system routine calls. System service calls expect VAX floating-point format, not IEEE format. Therefore, it is not advisable to change the format of floating-point numbers passed to system calls. An explicit type conversion may be necessary to use the predefined library.

On DIGITAL UNIX systems, IEEE_FLOAT is the only allowable and default value for the pragma.

Table 2-4 summarizes these choices.

Table 2-4 Pragma FLOAT_REPRESENTATION Values and Defaults
Platform Allowable Values Default
OpenVMS VAX VAX_FLOAT VAX_FLOAT
OpenVMS Alpha VAX_FLOAT
IEEE_FLOAT
VAX_FLOAT
DIGITAL UNIX IEEE_FLOAT IEEE_FLOAT

Use of the pragma FLOAT_REPRESENTATION is interpreted as an explicit recompilation of the predefined STANDARD environment. Therefore, if the value of the pragma FLOAT_REPRESENTATION changes, all units that depend on the value must be recompiled.

2.2.2 Pragma LONG_FLOAT (OpenVMS Systems Only)

On OpenVMS systems, DEC Ada provides the pragma LONG_FLOAT to allow control over the internal representation chosen for the predefined type LONG_FLOAT and for floating-point type declarations with digits specified in the range 7 .. 15. The format of this pragma is as follows:

pragma LONG_FLOAT(D_FLOAT | G_FLOAT);

This pragma is allowed only at the start of a compilation before the first compilation unit (if any). For this pragma to have an effect, the pragma FLOAT_REPRESENTATION must also have a value of VAX_FLOAT.

If the value D_FLOAT is specified and the range is adequate, then a D-floating representation is used for the predefined type LONG_FLOAT and for floating-point types declared with digits in the range 7 .. 9.

Similarly, if the value G_FLOAT is specified and the range is adequate, then a G-floating representation is used for the predefined type LONG_FLOAT and for floating-point types declared with digits in the range 7 .. 15.

F-floating and H-floating representations are used for floating-point types with digits in other ranges as follows:

Pragma Argument Digits Specified Representation
D_FLOAT 1 .. 6 F-floating
  7 .. 9 D-floating
  10 .. 15 G-floating 1
  10 .. 33 H-floating 2
G_FLOAT 1 .. 6 F-floating
  7 .. 15 G-floating
  16 .. 33 H-floating 2

1On OpenVMS Alpha and DIGITAL UNIX systems.
2On OpenVMS VAX systems.

Use of the pragma LONG_FLOAT is interpreted as an implicit recompilation of the predefined STANDARD environment. Therefore, if the value of the pragma LONG_FLOAT changes, all units that depend on the value must be recompiled. Whenever a program library is reinitialized, the G-floating representation is established by default.

When the value of the pragma FLOAT_REPRESENTATION is VAX_FLOAT, the choice of floating-point representation is not affected by the pragma LONG_FLOAT in the cases as shown in the following cases:

Digits Specified Representation Platform
1 .. 6 F-floating All OpenVMS
10 .. 15 G-floating OpenVMS Alpha
16 .. 33 H-floating OpenVMS VAX

2.2.3 Representation Attributes for Floating-Point Types

The values of the representation attributes for floating-point types are summarized in Table 2-5.

Table 2-5 Representation Attributes for Floating-Point Types
Attribute F-floating D-floating G-floating H-floating IEEE Single Float IEEE Double Float
MACHINE_ROUNDS TRUE TRUE TRUE TRUE TRUE TRUE
MACHINE_OVERFLOWS TRUE TRUE TRUE TRUE TRUE TRUE
MACHINE_RADIX 2 2 2 2 2 2
MACHINE_MANTISSA 24 56 53 113 24 53
MACHINE_EMAX 127 127 1023 16383 128 1024
MACHINE_EMIN --127 --127 --1023 --16383 --125 --1021

For both floating-point and fixed-point types, T'MACHINE_ROUNDS yields the value TRUE if every predefined arithmetic operation on values of the base type of T either returns an exact result or performs rounding. It yields the value FALSE otherwise. The value of this attribute is of the predefined type BOOLEAN.

On all systems, this value is TRUE for floating-point types.

T'MACHINE_MANTISSA yields the number of digits in the mantissa for the machine representation of the base type of T. The digits are extended digits in the range 0 to T'MACHINE_RADIX - 1. The value of this attribute is of the type universal_integer.

T'MACHINE_EMAX yields the largest value of exponent for the machine representation of the base type of T. The value of this attribute is of the type universal_integer.

T'MACHINE_EMIN yields the smallest (most negative) value of exponent for the machine representation of the base type of T. The value of this attribute is of the type universal_integer.

2.2.4 Model Numbers for Floating-Point Types

Table 2-6 lists the model numbers for each underlying floating-point type (and, therefore, for each DEC Ada floating-point type). The ranges in the table are approximate. Exact ranges can be found by evaluating language-defined attributes T'SMALL and T'LARGE, where T is the floating-point type.

Table 2-6 Model Numbers Defined for Each Floating-Point Type
DEC Ada Representations
and Types
Digits(D) Mantissa
Bits
(B)
Exponent
Range
(--E..+E)
Approximate Magnitude
F-floating
F_FLOAT
FLOAT
6 21 --84..84 2.6E--26..1.9E+25
D-floating
D_FLOAT
LONG_FLOAT
9 31 --124..124 2.3E--38..2.1E+37
G-floating
G_FLOAT
LONG_FLOAT
15 51 --204..204 1.9E--62..2.6E+61
H-floating 1
H_FLOAT
LONG_LONG_FLOAT
33 111 --444..444 1.1E--134..4.5E+133
IEEE single float 2
IEEE_SINGLE_FLOAT
FLOAT
6 21 --84..84 2.6E--26..1.9E+25
IEEE double float 2
IEEE_DOUBLE_FLOAT
LONG_FLOAT
15 51 --204..204 1.9E--62..2.6E+61

1On OpenVMS VAX systems only.
2On OpenVMS Alpha and DIGITAL UNIX systems only.

2.2.5 Safe Numbers for Floating-Point Types

For both predefined and nonpredefined types, the Ada language rules about safe numbers also apply.

For each hardware floating-point type, there are representable numbers that are not safe numbers, and there is a small set of numbers that are outside the range of safe numbers.

The representation of a literal can be different on different platforms. A literal that is not a safe number can be represented by the safe number above or below the universal-real value.

The safe number for a floating-point literal computed at compile time is not guaranteed to be the same as the safe number computed at run time.

Table 2-7 lists the safe numbers for each underlying floating-point type (and, thereby, for each DEC Ada floating-point type). The ranges in the table are approximate. Exact ranges can be found by evaluating language-defined attributes T'SMALL and T'LARGE, where T is the floating-point type.

Table 2-7 Safe Numbers Defined for Each Floating-Point Type
DEC Ada Representations and Types Digits(D) Mantissa
Bits
(B)
Exponent
Range
(--E..+E)
SAFE_SMALL..
SAFE_LARGE
F-floating
F_FLOAT
FLOAT
6 21 --127..127 2.9E--39..1.7E+38
D-floating
D_FLOAT
LONG_FLOAT
9 31 --127..127 2.9E--39..1.7E+38
G-floating
G_FLOAT
LONG_FLOAT
15 51 --1023..1023 5.5E--309..8.9E+307
H-floating 1
H_FLOAT
LONG_LONG_FLOAT
33 111 --16383..16383 8.4E--4933..5.9E+4931
IEEE single float 2
IEEE_SINGLE_FLOAT
FLOAT
6 21 --126..127 1.2E--38..4.3E+37
IEEE double float 2
IEEE_DOUBLE_FLOAT
LONG_FLOAT
15 51 --1022..1023 2.2E--308..2.3E+307

1On OpenVMS VAX systems only.
2On OpenVMS Alpha and DIGITAL UNIX systems only.

2.2.6 Floating-Point Computations

The results of floating-point computations on OpenVMS Alpha and DIGITAL UNIX systems do not compare exactly to the results on OpenVMS VAX systems. The floating-point representations on these systems are entirely different one from the other.

The binary mantissa for a floating-point number must use enough bits to ensure that the guaranteed number of significant digits can be represented accurately. The extra bits that do not affect the value of the number within the guaranteed accuracy may differ between platforms and between values computed at compile time and those computed at run time.

Because a comparison for equality of two floating-point numbers takes these extra bits into account, such a comparison may fail, depending on the source of the two numbers. For example if a text representation of a floating-point number converted at run time is compared for equality with a text representation converted at compile time, the comparison may fail.

2.3 Fixed-Point Types

Fixed-point types provide approximations to the real numbers with absolute bounds on errors determined by the value of T'SMALL, where T is the fixed-point type. T'SMALL is defined to be less than or equal to the delta specified in the type declaration.

To implement fixed point numbers, DEC Ada uses a set of anonymous predefined fixed point types of the form:


type fixed_point_type is delta S range -L .. U;

Where S is a value in the range 2.0-62 .. 2.031, L = 2.031*S, and
U = (2.031 - 1)*S.

Each fixed-point type has a storage size determined by its delta and range, rounded up to an 8-, 16-, or 32-bit boundary. The size may be changed by a representation clause.

For a size specification for a discrete type, the given size must not exceed the maximum size (in bits) for the given type. For fixed-point types, the maximum size is 32 bits. Unless the language specifies otherwise, operations on fixed-point types are handled as follows:

  • On OpenVMS VAX systems, rounding is towards zero for negative numbers and away from zero for positive numbers. Therefore, +0.5 rounds to 1 and -0.5 rounds to zero.
  • On OpenVMS Alpha and DIGITAL UNIX systems, rounding is away from zero for both positive and negative numbers. Therefore, +0.5 rounds to 1 and -0.5 rounds to -1.

Both model numbers and model intervals are used to define the permissible legal values for the results of operations on real (in this case, fixed-point) types. Any value that falls in the defined model interval for an operation is a legal result value for that operation.

For any fixed-point type where the value of T'SMALL is a power of two, T'MACHINE_ROUNDS yields the value FALSE. The value is TRUE for all other fixed-point types.

Data representation depends on the properties of the underlying hardware and/or operating system. DEC Ada represents fixed-point types as signed 8-bit (byte), 16-bit (word), or 32-bit (longword) quantities with an implicit binary scale factor.


Previous Next Contents Index