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


3.5 Scalar Types -- TOC

(1)
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.
Syntax
(2)
       range_constraint ::=  range range
(3)
       range ::=  range_attribute_reference
          | simple_expression .. simple_expression
(4)
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
(5)
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
(6)
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.
(7)
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
(8)
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.
(9)
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.
(10)
Attributes
(11)
For every scalar subtype S, the following attributes are defined:
(12)
S'First
(13)
S'Last
(14)
S'Range
(15)
S'Base
(16)
S'Min
(17)
           function S'Min(Left, Right : S'Base)
             return S'Base
(18)
(19)
S'Max
(20)
           function S'Max(Left, Right : S'Base)
             return S'Base
(21)
(22)
S'Succ
(23)
           function S'Succ(Arg : S'Base)
             return S'Base
(24)
(25)
S'Pred
(26)
           function S'Pred(Arg : S'Base)
             return S'Base
(27)
(28)
S'Wide_Image
(29)
           function S'Wide_Image(Arg : S'Base)
             return Wide_String
(30)
(31)
(32)
(33)
(34)
(35)
S'Image
(36)
           function S'Image(Arg : S'Base)
             return String
(37)
(38)
S'Wide_Width
(39)
S'Width
(40)
S'Wide_Value
(41)
           function S'Wide_Value(Arg : Wide_String)
             return S'Base
(42)
(43)
(44)
(45)
(46)
(47)
(48)
(49)
(50)
(51)
(52)
S'Value
(53)
           function S'Value(Arg : String)
             return S'Base
(54)
(55)
Implementation Permissions
(56)
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.

(57)
(58)
(59)
Examples
(60)
Examples of ranges:
(61)
       -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)
(62)
Examples of range constraints:
(63)
       range -999.0 .. +999.0
       range S'First+1 .. S'Last-1

Subclauses

  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 -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12