Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

3.5 Scalar Types -- TOC

Scalar types comprise enumeration types, integer types, and real types. Enumeration types and integer types are called discrete types; each value of a discrete type has a position number which is an integer value. Integer types and real types are called numeric types. All scalar types are ordered, that is, all relational operators are predefined for their values.
       range_constraint ::=  range range
       range ::=  range_attribute_reference
          | simple_expression .. simple_expression
A range has a lower bound and an upper bound and specifies a subset of the values of some scalar type (the type of the range). A range with lower bound L and upper bound R is described by ``L .. R''. If R is less than L, then the range is a null range, and specifies an empty set of values. Otherwise, the range specifies the values of the type from the lower bound to the upper bound, inclusive. A value belongs to a range if it is of the type of the range, and is in the subset of values specified by the range. A value satisfies a range constraint if it belongs to the associated range. One range is included in another if all values that belong to the first range also belong to the second.
Name Resolution Rules
For a subtype_indication containing a range_constraint, either directly or as part of some other scalar_constraint, the type of the range shall resolve to that of the type determined by the subtype_mark of the subtype_indication. For a range of a given type, the simple_expressions of the range (likewise, the simple_expressions of the equivalent range for a range_attribute_reference) are expected to be of the type of the range.
Static Semantics
The base range of a scalar type is the range of finite values of the type that can be represented in every unconstrained object of the type; it is also the range supported at a minimum for intermediate values during the evaluation of expressions involving predefined operators of the type.
A constrained scalar subtype is one to which a range constraint applies. The range of a constrained scalar subtype is the range associated with the range constraint of the subtype. The range of an unconstrained scalar subtype is the base range of its type.
Dynamic Semantics
A range is compatible with a scalar subtype if and only if it is either a null range or each bound of the range belongs to the range of the subtype. A range_constraint is compatible with a scalar subtype if and only if its range is compatible with the subtype.
The elaboration of a range_constraint consists of the evaluation of the range. The evaluation of a range determines a lower bound and an upper bound. If simple_expressions are given to specify bounds, the evaluation of the range evaluates these simple_expressions in an arbitrary order, and converts them to the type of the range. If a range_attribute_reference is given, the evaluation of the range consists of the evaluation of the range_attribute_reference.
For every scalar subtype S, the following attributes are defined:
           function S'Min(Left, Right : S'Base)
             return S'Base
           function S'Max(Left, Right : S'Base)
             return S'Base
           function S'Succ(Arg : S'Base)
             return S'Base
           function S'Pred(Arg : S'Base)
             return S'Base
           function S'Wide_Image(Arg : S'Base)
             return Wide_String
           function S'Image(Arg : S'Base)
             return String
           function S'Wide_Value(Arg : Wide_String)
             return S'Base
           function S'Value(Arg : String)
             return S'Base
Implementation Permissions
An implementation may extend the Wide_Value, Value, Wide_Image, and Image attributes of a floating point type to support special values such as infinities and NaNs.

Examples of ranges:
       -10 .. 10
       X .. X + 1
       0.0 .. 2.0*Pi
       Red .. Green     -- see 3.5.1
       1 .. 0           -- a null range
       Table'Range      -- a range attribute reference (see 3.6)
Examples of range constraints:
       range -999.0 .. +999.0
       range S'First+1 .. S'Last-1


  1. Enumeration Types
  2. Character Types
  3. Boolean Types
  4. Integer Types
  5. Operations of Discrete Types
  6. Real Types
  7. Floating Point Types
  8. Operations of Floating Point Types
  9. Fixed Point Types
  10. Operations of Fixed Point Types

Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe --
Copyright statement
Page last generated: 95-03-12