The operations of a subtype with reduced accuracy AI00407/07 1
930624 BI WA
 !standard 04.05.07 (00) 930624 AI00407/07
!standard 03.05.08 (16)
!standard 03.05.10 (15)
!standard 05.02 (03)
!class binding interpretation 851229
 !status approved by WG9 930618 (see AI00571)
!status approved by WG9/AJPO 880205
!status approved by Director, AJPO 880205
!status approved by WG9/Ada Board 871207
!status approved by Ada Board 870730
!status panel/committeeapproved (1003) 870217 (by ballot)
!status panel/committeeapproved (303) 861114 (pending letter ballot)
!status workitem 861005
!status received 851229
!references 8300691
!topic The operations of a subtype with reduced accuracy
 !SUMMARY 930624
When assigning a fixed or floating point value to a variable, the stored
 value must be represented with at least the accuracy of the variable's base
 type. Furthermore, if no exception is raised by the assignment, the stored
value belongs to the subtype of the variable.
If a real subtype is used as the type mark in a membership test,
qualification, or explicit conversion, the corresponding operation is
performed with the accuracy of the base type and the range of the subtype.
For a real subtype, the value of the attribute FIRST or LAST is represented
with at least the accuracy of the base type. The values of other attributes
of a real subtype are given exactly.
!QUESTION 861005
3.5.8(16) says:
The operations of a subtype are the corresponding operations of the
type except for the following: assignment, membership tests,
qualification, explicit conversion, and the attributes of the first
group [BASE, FIRST, LAST, SIZE, DIGITS, MANTISSA, EPSILON, EMAX,
SMALL, and LARGE]; the effects of these operations are redefined in
terms of the subtype.
3.5.7(15) says:
The elaboration of [a subtype indication consisting of a type mark
followed by a floating point constraint] ... creates a floating point
subtype whose model numbers are defined by the corresponding floating
accuracy definition.
What do these two paragraphs together imply about the accuracy with which the
The operations of a subtype with reduced accuracy AI00407/07 2
930624 BI WA
assignment, membership tests, qualification, explicit conversion, and
attribute operations are performed? For example, consider:
type T is digits 5;
subtype ST is T digits 3 range 12345.0 .. 15099.0;
X : ST := 12345.0;
What does "redefining the effect" of assignment in terms of subtype ST mean
here? The effect of assignment is defined in 5.2(3):
For the execution of an assignment statement, the variable name and
the expression are first evaluated ... A check is then made that the
value of the expression belongs to the subtype of the variable ...
Finally, the value of the expression becomes the new value of the
variable.
In the case of X's initialization, evaluation of the expression means
implicitly converting 12345.0 to T's base type and checking that the
converted value belongs to T's range. Since T's base type has at least 5
digits of accuracy, 12345.0 is a model number. This value certainly belongs
to T's subtype, so it is then assigned to X. Or was the intent to allow the
value of X to be approximated as a model number for ST rather than requiring
that the stored value have at least 5 digits of accuracy, i.e., should one
understand "becomes the new value of the variable" to mean "is allowed to
become a model number of the variable's subtype?" If so, this would seem to
allow the approximation to a model number of ST to occur after the range
check has been performed, and this is too late. 12345.0 belongs to the model
interval 12344.0 .. 12352.0 (since ST'MANTISSA = 11, and 12345.0 is
16#3039.0#). If 12345.0 is approximated as 12344.0 and becomes the value of
X, can the expression, X in ST, be FALSE after the assignment? Can 12344.0
in ST evaluate to TRUE? Can it be the case that ST'(12345.0) will raise
CONSTRAINT_ERROR? If the initialization expression for X were ST'FIRST
instead of the literal 12345.0, could CONSTRAINT_ERROR be raised? In short,
what does it mean for the "effects" of the operations listed in 3.5.8(16) to
be "redefined in terms of the subtype?"
Note that the same questions arise for fixed point types, although for fixed
point, the relevant attributes are BASE, FIRST, LAST, SIZE, DELTA, MANTISSA,
SMALL, LARGE, FORE, and AFT.
 !RECOMMENDATION 930624

 When assigning a fixed or a floating point value to a variable, the stored
 value must be represented with at least the accuracy of the base type.
If a real subtype is used as the type mark in a membership test,
qualification, or explicit conversion, the corresponding operation is
performed with the accuracy of the base type and the range of the subtype.
The operations of a subtype with reduced accuracy AI00407/07 3
930624 BI WA
For a real subtype, the value of the attribute FIRST or LAST is represented
with at least the accuracy of the base type. The values of other attributes
of a real subtype are given exactly.
 !DISCUSSION 930624
3.5.7(1012) says that the declaration:
type T is digits 5;
is equivalent to:
type 'floating_point_type' is new predefined_floating_point_type;
subtype T is 'floating_point_type' digits 5;
The only operations declared for type T are those declared for the base type
 no operations are declared by the subtype declaration itself.
Consequently, all operations for type T are performed using the safe numbers
of the base type. Suppose T'BASE'DIGITS = T'DIGITS, i.e., the base type has
exactly the accuracy of the subtype. Now consider the effect of the
declaration of subtype ST:
subtype ST is T digits 3 range 12345.0 .. 15099.0;
No new operations are declared. Let's consider, however, the effect of
evaluating a conversion to subtype ST:
ST(12345.0)
According to 4.6(4), the universal_real value, 12345.0, is first converted to
ST's base type. The converted value is then checked to see if it belongs to
subtype ST. This check is performed using the predefined operations of the
base type, i.e., the check is performed with the accuracy of ST's base type.
The only sense in which the effect of converting to subtype ST is different
from the effect of converting to the base type is that ST's range is used
instead of the range associated with T's base type. Since 12345.0 is a model
number of T's base type, the conversion is performed exactly. Since ST's
range constraint is specified with model numbers of type T, the check to see
if the converted value belongs to subtype ST is equivalent to evaluating:
12345.0 in 12345.0 .. 15099.0
This evaluation must yield TRUE, so no exception can be raised by the
conversion. The fact that ST has reduced accuracy does not affect how the
conversion is performed. Similar reasoning applies for qualification.
Now consider the membership test, 12345.0 in ST. Since the membership test
operation is declared for T's base type, it is performed with the accuracy of
the base type, but uses the range constraint associated with subtype ST. As
for conversion and qualification, the reduced accuracy of subtype ST does not
affect how the membership test is evaluated.
The operations of a subtype with reduced accuracy AI00407/07 4
930624 BI WA
In short, for membership tests, conversion, and qualification, redefining the
effect of these operations in terms of the subtype means using the range of
the subtype but otherwise using the operations of the base type.
 A similar conclusion applies to the assignment operation; see AI00571 for
 further discussion of why this conclusion is both correct and desirable.
For floating point subtypes, the attributes affected by a subtype declaration
are given in the question. The attributes DIGITS, MANTISSA, EPSILON, EMAX,
SMALL, and LARGE return values that depend on the accuracy specified for the
subtype, and in this sense, the effect of these attributes is defined by the
subtype declaration. Since the values returned by EPSILON, SMALL, and LARGE
are model numbers of the subtype, no inaccuracy is allowed in evaluating
these attributes.
The attributes FIRST and LAST are declared as operations of the base type.
When applied to a subtype, the returned value is therefore a value of the
base type, although the value actually returned depends on the range
specified for the subtype. Hence, for the example given in the question,
since 12345.0 is a model number of the base type, ST'FIRST is exactly equal
to 12345.0, even though ST'FIRST is not a model number of subtype ST.
Similar reasoning applies to fixed point operations.