Annotated Ada Reference Manual (Ada 202y Draft 4)Legal Information
Contents   Index   References   Search   Previous   Next 

A.5.4 Attributes of Fixed Point Types

Static Semantics

1
The following representation-oriented attributes are defined for every subtype S of a fixed point type T.
2
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.
3
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.
4
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. 
5/7
{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.
6/7
{AI22-0057-1} The following primitive function attributes are defined for every subtype S of a fixed point type T that has integral values. 
7/7
S'Ceiling
{AI22-0057-1} S'Ceiling denotes a function with the following specification: 
7.1/7
function S'Ceiling (X : T)
   return T
7.2/7
The function yields the value Ceiling(X), that is, the smallest (most negative) integral value greater than or equal to X.
8/7
S'Floor
{AI22-0057-1} S'Floor denotes a function with the following specification: 
8.1/7
function S'Floor (X : T)
   return T
8.2/7
The function yields the value Floor(X), that is, the largest (most positive) integral value less than or equal to X.
9/7
S'Rounding
{AI22-0057-1} S'Rounding denotes a function with the following specification: 
9.1/7
function S'Rounding (X : T)
   return T
9.2/7
The function yields the integral value nearest to X, rounding away from zero if X lies exactly halfway between two integers.
10/7
S'Unbiased_Rounding

{AI22-0057-1} S'Unbiased_Rounding denotes a function with the following specification: 
10.1/7
function S'Unbiased_Rounding (X : T)
   return T
10.2/7
The function yields the integral value nearest to X, rounding toward the even integer if X lies exactly halfway between two integers.
11/7
S'Machine_Rounding

{AI22-0057-1} S'Machine_Rounding denotes a function with the following specification: 
11.1/7
function S'Machine_Rounding (X : T)
   return T
11.2/7
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.
11.a.1/7
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. 
12/7
S'Truncation
{AI22-0057-1} S'Truncation denotes a function with the following specification: 
12.1/7
function S'Truncation (X : T)
   return T
12.2/7
The function yields the value Ceiling(X) when X is negative, and Floor(X) otherwise.
13/7
{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.
13.a/7
To be honest: {AI22-0057-1} The check that the type of the prefix has integral values is considered a Legality Rules. 
13.b/7
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

13.c
The Mantissa, Large, Safe_Small, and Safe_Large attributes of fixed point types are removed from the language.
13.d
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

13.e
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

13.f/7
{AI22-0057-1} The Floor, Ceiling, Rounding, Unbiased_Rounding, Machine_Rounding, and Trunaction attributes are new for fixed point types. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe