A.5.4 Attributes of Fixed Point Types
Static Semantics
The
following
representation-oriented attributes are defined for every
subtype S of a fixed point type
T.
S'Machine_Radix
Yields the radix of the hardware
representation of the type
T. The value
of this attribute is of the type
universal_integer.
S'Machine_Rounds
Yields the value True if rounding
is performed on inexact results of every predefined operation that yields
a result of the type
T; yields the
value False otherwise. The value of this attribute is of the predefined
type Boolean.
S'Machine_Overflows
Yields the value True if overflow
and divide-by-zero are detected and reported by raising Constraint_Error
for every predefined operation that yields a result of the type
T;
yields the value False otherwise. The value of this attribute is of the
predefined type Boolean.
{
AI22-0057-1}
A fixed point type has integral values if
its Small value is an integer or the reciprocal of an integer. A generic
formal type is defined to have integral values.
{
AI22-0057-1}
The following primitive function attributes are
defined for every subtype S of a fixed point type T
that has integral values.
S'Ceiling
{
AI22-0057-1}
S'Ceiling denotes
a function with the following specification:
function S'Ceiling (X : T)
return T
The function yields
the value Ceiling(X), that is, the smallest (most negative) integral
value greater than or equal to X.
S'Floor
{
AI22-0057-1}
S'Floor denotes a
function with the following specification:
function S'Floor (X : T)
return T
The function yields
the value Floor(X), that is, the largest (most positive) integral
value less than or equal to X.
S'Rounding
{
AI22-0057-1}
S'Rounding denotes
a function with the following specification:
function S'Rounding (X : T)
return T
The function yields
the integral value nearest to X, rounding
away from zero if X lies exactly halfway
between two integers.
S'Unbiased_Rounding
{
AI22-0057-1}
S'Unbiased_Rounding
denotes a function with the following specification:
function S'Unbiased_Rounding (X : T)
return T
The function yields
the integral value nearest to X, rounding
toward the even integer if X lies exactly
halfway between two integers.
S'Machine_Rounding
{
AI22-0057-1}
S'Machine_Rounding
denotes a function with the following specification:
function S'Machine_Rounding (X : T)
return T
The function yields
the integral value nearest to X. If
X lies exactly halfway between two
integers, one of those integers is returned, but which of them is returned
is unspecified. This function provides access to the rounding behavior
which is most efficient on the target processor.
Discussion: We
leave the rounding unspecified, so that users cannot depend on a particular
rounding. This attribute is intended for use in cases where the particular
rounding chosen is irrelevant. If there is a need to know which way values
halfway between two integers are rounded, one of the other rounding attributes
should be used.
S'Truncation
{
AI22-0057-1}
S'Truncation denotes
a function with the following specification:
function S'Truncation (X : T)
return T
The function yields
the value Ceiling(X) when X
is negative, and Floor(X) otherwise.
{
AI22-0057-1}
For all of these attributes, if T
is a generic formal type, Program_Error is raised if the actual subtype
does not have integral values.
To be honest: {
AI22-0057-1}
The check that the type of the prefix has integral
values is considered a Legality Rules.
Reason: {
AI22-0057-1}
The rules here for generic formal types are classic
assume-the-best rules for legality checking; the check is redone in the
specification of the instance. We use a runtime check on the actual subtype
to avoid assume-the-worst in generic bodies (which would mean the attributes
could never be used in a generic body on a formal subtype). For implementations
that expand generic bodies, it is always possible to provide a warning
about the exception being raised.
Incompatibilities With Ada 83
The Mantissa, Large, Safe_Small,
and Safe_Large attributes of fixed point types are removed from the language.
Implementations are encouraged to eliminate
the resulting incompatibility by retaining these attributes, during a
transition period, in the form of implementation-defined attributes with
their former values.
Extensions to Ada 83
The Machine_Radix attribute
is now allowed for fixed point types. It is also specifiable in an attribute
definition clause (see
F.1).
Extensions to Ada 2022
{
AI22-0057-1}
The Floor, Ceiling, Rounding,
Unbiased_Rounding, Machine_Rounding, and Trunaction attributes are new
for fixed point types.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe