Contents   Index   Search   Previous   Next


A.5.3 Attributes of Floating Point Types

Static Semantics

1
   {representation-oriented attributes (of a floating point subtype)} The following representation-oriented attributes are defined for every subtype S of a floating 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
   {canonical form} The values of other representation-oriented attributes of a floating point subtype, and of the ``primitive function'' attributes of a floating point subtype described later, are defined in terms of a particular representation of nonzero values called the canonical form. The canonical form (for the type T) is the form
    ± mantissa · T'Machine_Radixexponent
where
4
5
6
   S'Machine_Mantissa
Yields the largest value of p such that every value expressible in the canonical form (for the type T), having a p-digit mantissa and an exponent between T'Machine_Emin and T'Machine_Emax, is a machine number (see 3.5.7) of the type T. This attribute yields a value of the type universal_integer.
6.a
Ramification: Values of a type held in an extended register are, in general, not machine numbers of the type, since they cannot be expressed in the canonical form with a sufficiently short mantissa.
7
   S'Machine_Emin
Yields the smallest (most negative) value of exponent such that every value expressible in the canonical form (for the type T), having a mantissa of T'Machine_Mantissa digits, is a machine number (see 3.5.7) of the type T. This attribute yields a value of the type universal_integer.
8
   S'Machine_Emax
Yields the largest (most positive) value of exponent such that every value expressible in the canonical form (for the type T), having a mantissa of T'Machine_Mantissa digits, is a machine number (see 3.5.7) of the type T. This attribute yields a value of the type universal_integer.
8.a
Ramification: Note that the above definitions do not determine unique values for the representation-oriented attributes of floating point types. The implementation may choose any set of values that collectively satisfies the definitions.
9
   S'Denorm
Yields the value True if every value expressible in the form
    ± mantissa · T'Machine_RadixT'Machine_Emin
where mantissa is a nonzero T'Machine_Mantissa-digit fraction in the number base T'Machine_Radix, the first digit of which is zero, is a machine number (see 3.5.7) of the type T; yields the value False otherwise. The value of this attribute is of the predefined type Boolean.
10
    {denormalized number} The values described by the formula in the definition of S'Denorm are called denormalized numbers. {normalized number} A nonzero machine number that is not a denormalized number is a normalized number. {represented in canonical form} {canonical-form representation} A normalized number x of a given type T is said to be represented in canonical form when it is expressed in the canonical form (for the type T) with a mantissa having T'Machine_Mantissa digits; the resulting form is the canonical-form representation of x.
10.a
Discussion: The intent is that S'Denorm be True when such denormalized numbers exist and are generated in the circumstances defined by IEC 559:1989, though the latter requirement is not formalized here.
11
    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.
11.a
Discussion: It is difficult to be more precise about what it means to round the result of a predefined operation. If the implementation does not use extended registers, so that every arithmetic result is necessarily a machine number, then rounding seems to imply two things:
11.b
11.c
11.d
Technically, this attribute should yield False when extended registers are used, since a few computed results will cross over the half-way point as a result of double rounding, if and when a value held in an extended register has to be reduced in precision to that of the machine numbers. It does not seem desirable to preclude the use of extended registers when S'Machine_Rounds could otherwise be True.
12
    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.
13
    S'Signed_Zeros
Yields the value True if the hardware representation for the type T has the capability of representing both positively and negatively signed zeros, these being generated and used by the predefined operations of the type T as specified in IEC 559:1989; yields the value False otherwise. The value of this attribute is of the predefined type Boolean.
14
    {normalized exponent} For every value x of a floating point type T, the normalized exponent of x is defined as follows:
15
16
16.a
Ramification: The normalized exponent of a normalized number x is the value of exponent in the canonical-form representation of x.
16.b
The normalized exponent of a denormalized number is less than the value of T'Machine_Emin.
17
    {primitive function} The following primitive function attributes are defined for any subtype S of a floating point type T.
18
    S'Exponent
S'Exponent denotes a function with the following specification:
19
function S'Exponent (X : T)
  return universal_integer
20
The function yields the normalized exponent of X.
21
    S'Fraction
S'Fraction denotes a function with the following specification:
22
function S'Fraction (X : T)
  return T
23
The function yields the value X · T'Machine_Radix-k, where k is the normalized exponent of X. A zero result[, which can only occur when X is zero,] has the sign of X.
23.a
Discussion: Informally, when X is a normalized number, the result is the value obtained by replacing the exponent by zero in the canonical-form representation of X.
23.b
Ramification: Except when X is zero, the magnitude of the result is greater than or equal to the reciprocal of T'Machine_Radix and less than one; consequently, the result is always a normalized number, even when X is a denormalized number.
23.c
Implementation Note: When X is a denormalized number, the result is the value obtained by replacing the exponent by zero in the canonical-form representation of the result of scaling X up sufficiently to normalize it.
24
    S'Compose
S'Compose denotes a function with the following specification:
25
function S'Compose (Fraction : T;
                    Exponent : universal_integer)
  return T
26
{Constraint_Error (raised by failure of run-time check)} Let v be the value Fraction · T'Machine_RadixExponent-k, where k is the normalized exponent of Fraction. If v is a machine number of the type T, or if |v| >= T'Model_Small, the function yields v; otherwise, it yields either one of the machine numbers of the type T adjacent to v. {Range_Check [partial]} {check, language-defined (Range_Check)} Constraint_Error is optionally raised if v is outside the base range of S. A zero result has the sign of Fraction when S'Signed_Zeros is True.
26.a
Discussion: Informally, when Fraction and v are both normalized numbers, the result is the value obtained by replacing the exponent by Exponent in the canonical-form representation of Fraction.
26.b
Ramification: If Exponent is less than T'Machine_Emin and Fraction is nonzero, the result is either zero, T'Model_Small, or (if T'Denorm is True) a denormalized number.
27
    S'Scaling
S'Scaling denotes a function with the following specification:
28
function S'Scaling (X : T;
                    Adjustment : universal_integer)
  return T
29
{Constraint_Error (raised by failure of run-time check)} Let v be the value X · T'Machine_RadixAdjustment. If v is a machine number of the type T, or if |v| >= T'Model_Small, the function yields v; otherwise, it yields either one of the machine numbers of the type T adjacent to v. {Range_Check [partial]} {check, language-defined (Range_Check)} Constraint_Error is optionally raised if v is outside the base range of S. A zero result has the sign of X when S'Signed_Zeros is True.
29.a
Discussion: Informally, when X and v are both normalized numbers, the result is the value obtained by increasing the exponent by Adjustment in the canonical-form representation of X.
29.b
Ramification: If Adjustment is sufficiently small (i.e., sufficiently negative), the result is either zero, T'Model_Small, or (if T'Denorm is True) a denormalized number.
30
    S'Floor
S'Floor denotes a function with the following specification:
31
function S'Floor (X : T)
  return T
32
The function yields the value Floor(X), i.e., the largest (most positive) integral value less than or equal to X. When X is zero, the result has the sign of X; a zero result otherwise has a positive sign.
33
    S'Ceiling
S'Ceiling denotes a function with the following specification:
34
function S'Ceiling (X : T)
  return T
35
The function yields the value Ceiling(X), i.e., the smallest (most negative) integral value greater than or equal to X. When X is zero, the result has the sign of X; a zero result otherwise has a negative sign when S'Signed_Zeros is True.
36
    S'Rounding
S'Rounding denotes a function with the following specification:
37
function S'Rounding (X : T)
  return T
38
The function yields the integral value nearest to X, rounding away from zero if X lies exactly halfway between two integers. A zero result has the sign of X when S'Signed_Zeros is True.
39
    S'Unbiased_Rounding
S'Unbiased_Rounding denotes a function with the following specification:
40
function S'Unbiased_Rounding (X : T)
  return T
41
The function yields the integral value nearest to X, rounding toward the even integer if X lies exactly halfway between two integers. A zero result has the sign of X when S'Signed_Zeros is True.
42
    S'Truncation
S'Truncation denotes a function with the following specification:
43
function S'Truncation (X : T)
  return T
44
The function yields the value Ceiling(X) when X is negative, and Floor(X) otherwise. A zero result has the sign of X when S'Signed_Zeros is True.
45
    S'Remainder
S'Remainder denotes a function with the following specification:
46
function S'Remainder (XY : T)
  return T
47
{Constraint_Error (raised by failure of run-time check)} For nonzero Y, let v be the value X - n · Y, where n is the integer nearest to the exact value of X/Y; if |n - X/Y| = 1/2, then n is chosen to be even. If v is a machine number of the type T, the function yields v; otherwise, it yields zero. {Division_Check [partial]} {check, language-defined (Division_Check)} Constraint_Error is raised if Y is zero. A zero result has the sign of X when S'Signed_Zeros is True.
47.a
Ramification: The magnitude of the result is less than or equal to one-half the magnitude of Y.
47.b
Discussion: Given machine numbers X and Y of the type T, v is necessarily a machine number of the type T, except when Y is in the neighborhood of zero, X is sufficiently close to a multiple of Y, and T'Denorm is False.
48
    S'Adjacent
S'Adjacent denotes a function with the following specification:
49
function S'Adjacent (XTowards : T)
  return T
50
{Constraint_Error (raised by failure of run-time check)} If Towards = X, the function yields X; otherwise, it yields the machine number of the type T adjacent to X in the direction of Towards, if that machine number exists. {Range_Check [partial]} {check, language-defined (Range_Check)} If the result would be outside the base range of S, Constraint_Error is raised. When T'Signed_Zeros is True, a zero result has the sign of X. When Towards is zero, its sign has no bearing on the result.
50.a
Ramification: The value of S'Adjacent(0.0, 1.0) is the smallest normalized positive number of the type T when T'Denorm is False and the smallest denormalized positive number of the type T when T'Denorm is True.
51
    S'Copy_Sign
S'Copy_Sign denotes a function with the following specification:
52
function S'Copy_Sign (ValueSign : T)
  return T
53
{Constraint_Error (raised by failure of run-time check)} If the value of Value is nonzero, the function yields a result whose magnitude is that of Value and whose sign is that of Sign; otherwise, it yields the value zero. {Range_Check [partial]} {check, language-defined (Range_Check)} Constraint_Error is optionally raised if the result is outside the base range of S. A zero result has the sign of Sign when S'Signed_Zeros is True.
53.a
Discussion: S'Copy_Sign is provided for convenience in restoring the sign to a quantity from which it has been temporarily removed, or to a related quantity. When S'Signed_Zeros is True, it is also instrumental in determining the sign of a zero quantity, when required. (Because negative and positive zeros compare equal in systems conforming to IEC 559:1989, a negative zero does not appear to be negative when compared to zero.) The sign determination is accomplished by transferring the sign of the zero quantity to a nonzero quantity and then testing for a negative result.
54
    S'Leading_Part
S'Leading_Part denotes a function with the following specification:
55
function S'Leading_Part (X : T;
                         Radix_Digits : universal_integer)
  return T
56
Let v be the value T'Machine_Radixk-Radix_Digits, where k is the normalized exponent of X. The function yields the value
57
58
59
{Constraint_Error (raised by failure of run-time check)} {Range_Check [partial]} {check, language-defined (Range_Check)} Constraint_Error is raised when Radix_Digits is zero or negative. A zero result[, which can only occur when X is zero,] has the sign of X.
59.a
Discussion: Informally, if X is nonzero, the result is the value obtained by retaining only the specified number of (leading) significant digits of X (in the machine radix), setting all other digits to zero.
59.b
Implementation Note: The result can be obtained by first scaling X up, if necessary to normalize it, then masking the mantissa so as to retain only the specified number of leading digits, then scaling the result back down if X was scaled up.
60
    S'Machine
S'Machine denotes a function with the following specification:
61
function S'Machine (X : T)
  return T
62
{Constraint_Error (raised by failure of run-time check)} If X is a machine number of the type T, the function yields X; otherwise, it yields the value obtained by rounding or truncating X to either one of the adjacent machine numbers of the type T. {Range_Check [partial]} {check, language-defined (Range_Check)} Constraint_Error is raised if rounding or truncating X to the precision of the machine numbers results in a value outside the base range of S. A zero result has the sign of X when S'Signed_Zeros is True.
62.a
Discussion: All of the primitive function attributes except Rounding and Machine correspond to subprograms in the Generic_Primitive_Functions generic package proposed as a separate ISO standard (ISO/IEC DIS 11729) for Ada 83. The Scaling, Unbiased_Rounding, and Truncation attributes correspond to the Scale, Round, and Truncate functions, respectively, in Generic_Primitive_Functions. The Rounding attribute rounds away from zero; this functionality was not provided in Generic_Primitive_Functions. The name Round was not available for either of the primitive function attributes that perform rounding, since an attribute of that name is used for a different purpose for decimal fixed point types. Likewise, the name Scale was not available, since an attribute of that name is also used for a different purpose for decimal fixed point types. The functionality of the Machine attribute was also not provided in Generic_Primitive_Functions. The functionality of the Decompose procedure of Generic_Primitive_Functions is only provided in the form of the separate attributes Exponent and Fraction. The functionality of the Successor and Predecessor functions of Generic_Primitive_Functions is provided by the extension of the existing Succ and Pred attributes.
62.b
Implementation Note: The primitive function attributes may be implemented either with appropriate floating point arithmetic operations or with integer and logical operations that act on parts of the representation directly. The latter is strongly encouraged when it is more efficient than the former; it is mandatory when the former cannot deliver the required accuracy due to limitations of the implementation's arithmetic operations.
63
    {model-oriented attributes (of a floating point subtype)} The following model-oriented attributes are defined for any subtype S of a floating point type T.
64
    S'Model_Mantissa
If the Numerics Annex is not supported, this attribute yields an implementation defined value that is greater than or equal to Ceiling(d · log(10) / log(T'Machine_Radix)) + 1, where d is the requested decimal precision of T, and less than or equal to the value of T'Machine_Mantissa. See G.2.2 for further requirements that apply to implementations supporting the Numerics Annex. The value of this attribute is of the type universal_integer.
65
    S'Model_Emin
If the Numerics Annex is not supported, this attribute yields an implementation defined value that is greater than or equal to the value of T'Machine_Emin. See G.2.2 for further requirements that apply to implementations supporting the Numerics Annex. The value of this attribute is of the type universal_integer.
66
    S'Model_Epsilon
Yields the value T'Machine_Radix1 - T'Model_Mantissa. The value of this attribute is of the type universal_real.
66.a
Discussion: In most implementations, this attribute yields the absolute value of the difference between one and the smallest machine number of the type T above one which, when added to one, yields a machine number different from one. Further discussion can be found in G.2.2.
67
    S'Model_Small
Yields the value T'Machine_RadixT'Model_Emin - 1. The value of this attribute is of the type universal_real.
67.a
Discussion: In most implementations, this attribute yields the smallest positive normalized number of the type T, i.e. the number corresponding to the positive underflow threshold. In some implementations employing a radix-complement representation for the type T, the positive underflow threshold is closer to zero than is the negative underflow threshold, with the consequence that the smallest positive normalized number does not coincide with the positive underflow threshold (i.e., it exceeds the latter). Further discussion can be found in G.2.2.
68
    S'Model
S'Model denotes a function with the following specification:
69
function S'Model (X : T)
  return T
70
If the Numerics Annex is not supported, the meaning of this attribute is implementation defined; see G.2.2 for the definition that applies to implementations supporting the Numerics Annex.
71
    S'Safe_First
Yields the lower bound of the safe range (see 3.5.7) of the type T. If the Numerics Annex is not supported, the value of this attribute is implementation defined; see G.2.2 for the definition that applies to implementations supporting the Numerics Annex. The value of this attribute is of the type universal_real.
72
    S'Safe_Last
Yields the upper bound of the safe range (see 3.5.7) of the type T. If the Numerics Annex is not supported, the value of this attribute is implementation defined; see G.2.2 for the definition that applies to implementations supporting the Numerics Annex. The value of this attribute is of the type universal_real.
72.a
Discussion: A predefined floating point arithmetic operation that yields a value in the safe range of its result type is guaranteed not to overflow.
72.b
To be honest: An exception is made for exponentiation by a negative exponent in 4.5.6.
72.c
Implementation defined: The values of the Model_Mantissa, Model_Emin, Model_Epsilon, Model, Safe_First, and Safe_Last attributes, if the Numerics Annex is not supported.

Incompatibilities With Ada 83

72.d
{incompatibilities with Ada 83} The Epsilon and Mantissa attributes of floating point types are removed from the language and replaced by Model_Epsilon and Model_Mantissa, which may have different values (as a result of changes in the definition of model numbers); the replacement of one set of attributes by another is intended to convert what would be an inconsistent change into an incompatible change.
72.e
The Emax, Small, Large, Safe_Emax, Safe_Small, and Safe_Large attributes of floating point types are removed from the language. Small and Safe_Small are collectively replaced by Model_Small, which is functionally equivalent to Safe_Small, though it may have a slightly different value. The others are collectively replaced by Safe_First and Safe_Last. Safe_Last is functionally equivalent to Safe_Large, though it may have a different value; Safe_First is comparable to the negation of Safe_Large but may differ slightly from it as well as from the negation of Safe_Last. Emax and Safe_Emax had relatively few uses in Ada 83; T'Safe_Emax can be computed in the revised language as Integer'Min(T'Exponent(T'Safe_First), T'Exponent(T'Safe_Last)).
72.f
Implementations are encouraged to eliminate the incompatibilities discussed here by retaining the old attributes, during a transition period, in the form of implementation-defined attributes with their former values.

Extensions to Ada 83

72.g
{extensions to Ada 83} The Model_Emin attribute is new. It is conceptually similar to the negation of Safe_Emax attribute of Ada 83, adjusted for the fact that the model numbers now have the hardware radix. It is a fundamental determinant, along with Model_Mantissa, of the set of model numbers of a type (see G.2.1).
72.h
The Denorm and Signed_Zeros attributes are new, as are all of the primitive function attributes.

Contents   Index   Search   Previous   Next   Legal