[Ada Information Clearinghouse]
Ada '83 Rationale, Sec 7.4: The Explanation of Numeric Types

"Rationale for the Design of the
Ada® Programming Language"

[Ada '83 Rationale, HTML Version]

Copyright ©1986 owned by the United States Government. All rights reserved.
Direct inquiries to the Ada Information Clearinghouse at adainfo@sw-eng.falls-church.va.us.

CHAPTER 7: Derived Types

7.4 The Explanation of Numeric Types

The explanation of numeric types is based on the use of derived types. A type declaration such as

    type REAL is digits 8 range -1.0E30 .. 1.0E30;

is explained as being equivalent to the following succession of declarations

type hidden_real is new predefined_floating_point_type;
subtype REAL is hidden_real digits 8 range   hidden_real (-1.0E30) .. hidden_real (1.0E30);

This means that REAL is a subtype of a type hidden_real obtained by copying a predefined floating point type. The selection of this predefined type is done by the compiler; the type chosen must support the precision required - here it must have at least 8 digits; furthermore it must support at least the range required. The fact that this selection is performed by the compiler ensures portability: the programmer need not know which floating point type is actually used.

The role played by derivation in this explanation is to provide a distinct replica of the floating point type. Thus if we write

    type MY_REAL is digits 8;

we are sure of getting a new type. In particular this means that REAL and MY_REAL are distinct types.

The reason to consider REAL as a subtype of hidden_real is that for operations on values of this type, the compiler may generate code that corresponds to one of the hardware floating point types: range checks are used for assignments but not for intermediate results in expressions.


NEXTPREVIOUSUPTOCINDEX
Address any questions or comments to adainfo@sw-eng.falls-church.va.us.