3.5 Scalar Types
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
range_constraint ::=  range range 
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
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. 
 
Attributes
For every scalar subtype 
S, the following attributes are defined: 
S'First
S'First denotes the lower bound 
of the range of S. The value of this attribute is of the type of S. 
 
S'Last
S'Last denotes the upper bound 
of the range of S. The value of this attribute is of the type of S. 
 
S'Range
S'Range is equivalent to the 
range S'First 
.. S'Last.
 
S'Base
S'Base denotes an unconstrained 
subtype of the type of S. This unconstrained subtype is called the 
base 
subtype of the type. 
 
S'Min
S'Min denotes a function with 
the following specification: 
 
function S'Min(Left, Right : S'Base)
  return S'Base
The function returns the lesser of the 
values of the two parameters. 
S'Max
S'Max denotes a function with 
the following specification: 
 
function S'Max(Left, Right : S'Base)
  return S'Base
The function returns the greater of the 
values of the two parameters.
S'Succ
S'Succ denotes a function with 
the following specification: 
 
function S'Succ(Arg : S'Base)
  return S'Base
For an enumeration 
type, the function returns the value whose position number is one more 
than that of the value of 
Arg; 
Constraint_Error 
is raised if there is no such value of the type. For an integer type, 
the function returns the result of adding one to the value of 
Arg. 
For a fixed point type, the function returns the result of adding 
small 
to the value of 
Arg. For a floating point type, the function returns 
the machine number (as defined in 
3.5.7) 
immediately above the value of 
Arg; 
Constraint_Error 
is raised if there is no such machine number. 
 
S'Pred
S'Pred denotes a function with 
the following specification: 
 
function S'Pred(Arg : S'Base)
  return S'Base
For an enumeration 
type, the function returns the value whose position number is one less 
than that of the value of 
Arg; 
Constraint_Error 
is raised if there is no such value of the type. For an integer type, 
the function returns the result of subtracting one from the value of 
Arg. For a fixed point type, the function returns the result of 
subtracting 
small from the value of 
Arg. For a floating 
point type, the function returns the machine number (as defined in 
3.5.7) 
immediately below the value of 
Arg; 
Constraint_Error 
is raised if there is no such machine number. 
 
   S'Wide_Wide_Image
S'Wide_Wide_Image denotes a function 
with the following specification: 
 
function S'Wide_Wide_Image(Arg : S'Base)
  return Wide_Wide_String
The function returns 
an 
image of the value of 
Arg, that is, a sequence of characters 
representing the value in display form. The lower bound of the result 
is one.
 
The image of an integer value is the corresponding 
decimal literal, without underlines, leading zeros, exponent, or trailing 
spaces, but with a single leading character that is either a minus sign 
or a space. 
The image of an enumeration 
value is either the corresponding identifier in upper case or the corresponding 
character literal (including the two apostrophes); neither leading nor 
trailing spaces are included. For a 
nongraphic character (a value 
of a character type that has no enumeration literal associated with it), 
the result is a corresponding language-defined name in upper case (for 
example, the image of the nongraphic character identified as 
nul 
is “NUL” — the quotes are not part of the image). 
 
The image of a floating point value is 
a decimal real literal best approximating the value (rounded away from 
zero if halfway between) with a single leading character that is either 
a minus sign or a space, a single digit (that is nonzero unless the value 
is zero), a decimal point, S'Digits–1 (see 
3.5.8) 
digits after the decimal point (but one if S'Digits is one), an upper 
case E, the sign of the exponent (either + or –), and two or more 
digits (with leading zeros if necessary) representing the exponent. If 
S'Signed_Zeros is True, then the leading character is a minus sign for 
a negatively signed zero. 
 
The image of a fixed point value is a decimal 
real literal best approximating the value (rounded away from zero if 
halfway between) with a single leading character that is either a minus 
sign or a space, one or more digits before the decimal point (with no 
redundant leading zeros), a decimal point, and S'Aft (see 
3.5.10) 
digits after the decimal point. 
 
S'Wide_Image
S'Wide_Image denotes a function 
with the following specification: 
 
function S'Wide_Image(Arg : S'Base)
  return Wide_String
The function returns 
an image of the value of 
Arg as a Wide_String. The lower bound 
of the result is one. The image has the same sequence of graphic characters 
as defined for S'Wide_Wide_Image if all the graphic characters are defined 
in Wide_Character; otherwise, the sequence of characters is implementation 
defined (but no shorter than that of S'Wide_Wide_Image for the same value 
of Arg). 
 
Paragraphs 
31 through 34 were moved to Wide_Wide_Image. 
S'Image
S'Image denotes a function with 
the following specification: 
 
function S'Image(Arg : S'Base)
  return String
The function returns an image of the value 
of Arg as a String. The lower bound of the result is one. The 
image has the same sequence of graphic characters as that defined for 
S'Wide_Wide_Image if all the graphic characters are defined in Character; 
otherwise, the sequence of characters is implementation defined (but 
no shorter than that of S'Wide_Wide_Image for the same value of Arg). 
   S'Wide_Wide_Width
S'Wide_Wide_Width denotes the 
maximum length of a Wide_Wide_String returned by S'Wide_Wide_Image over 
all values of the subtype S. It denotes zero for a subtype that has a 
null range. Its type is 
universal_integer.
 
S'Wide_Width
S'Wide_Width denotes the maximum 
length of a Wide_String returned by S'Wide_Image over all values of the 
subtype S. It denotes zero for a subtype that has a null range. Its type 
is 
universal_integer.
 
S'Width
S'Width denotes the maximum length 
of a String returned by S'Image over all values of the subtype S. It 
denotes zero for a subtype that has a null range. Its type is 
universal_integer.
 
   S'Wide_Wide_Value
S'Wide_Wide_Value denotes a function 
with the following specification: 
 
function S'Wide_Wide_Value(Arg : Wide_Wide_String)
  return S'Base
This function returns a value given an 
image of the value as a Wide_Wide_String, ignoring any leading or trailing 
spaces.
For 
the evaluation of a call on S'Wide_Wide_Value for an enumeration subtype 
S, if the sequence of characters of the parameter (ignoring leading and 
trailing spaces) has the syntax of an enumeration literal and if it corresponds 
to a literal of the type of S (or corresponds to the result of S'Wide_Wide_Image 
for a nongraphic character of the type), the result is the corresponding 
enumeration value; 
otherwise, 
Constraint_Error is raised. 
 
For the evaluation 
of a call on S'Wide_Wide_Value for an integer subtype S, if the sequence 
of characters of the parameter (ignoring leading and trailing spaces) 
has the syntax of an integer literal, with an optional leading sign character 
(plus or minus for a signed type; only plus for a modular type), and 
the corresponding numeric value belongs to the base range of the type 
of S, then that value is the result; 
otherwise, 
Constraint_Error is raised.
 
For the evaluation 
of a call on S'Wide_Wide_Value for a real subtype S, if the sequence 
of characters of the parameter (ignoring leading and trailing spaces) 
has the syntax of one of the following: 
with an optional leading 
sign character (plus or minus), and if the corresponding numeric value 
belongs to the base range of the type of S, then that value is the result; 
otherwise, Constraint_Error is 
raised. The sign of a zero value is preserved (positive if none has been 
specified) if S'Signed_Zeros is True.
 
S'Wide_Value
S'Wide_Value denotes a function 
with the following specification: 
 
function S'Wide_Value(Arg : Wide_String)
  return S'Base
This function returns a value given an 
image of the value as a Wide_String, ignoring any leading or trailing 
spaces.
For 
the evaluation of a call on S'Wide_Value for an enumeration subtype S, 
if the sequence of characters of the parameter (ignoring leading and 
trailing spaces) has the syntax of an enumeration literal and if it corresponds 
to a literal of the type of S (or corresponds to the result of S'Wide_Image 
for a value of the type), the result is the corresponding enumeration 
value; 
otherwise, Constraint_Error 
is raised. For a numeric subtype S, the evaluation of a call on S'Wide_Value 
with 
Arg of type Wide_String is equivalent to a call on S'Wide_Wide_Value 
for a corresponding 
Arg of type Wide_Wide_String. 
 
Paragraphs 
44 through 51 were moved to Wide_Wide_Value. 
S'Value
S'Value denotes a function with 
the following specification: 
 
function S'Value(Arg : String)
  return S'Base
This function returns a value given an 
image of the value as a String, ignoring any leading or trailing spaces.
For 
the evaluation of a call on S'Value for an enumeration subtype S, if 
the sequence of characters of the parameter (ignoring leading and trailing 
spaces) has the syntax of an enumeration literal and if it corresponds 
to a literal of the type of S (or corresponds to the result of S'Image 
for a value of the type), the result is the corresponding enumeration 
value; 
otherwise, Constraint_Error 
is raised. For a numeric subtype S, the evaluation of a call on S'Value 
with 
Arg of type String is equivalent to a call on S'Wide_Wide_Value 
for a corresponding 
Arg of type Wide_Wide_String. 
 
   For a 
prefix 
X that denotes an object of a scalar type (after any implicit dereference), 
the following attributes are defined:
 
   X'Wide_Wide_Image
X'Wide_Wide_Image denotes the 
result of calling function S'Wide_Wide_Image with 
Arg being X, 
where S is the nominal subtype of X.
 
   X'Wide_Image
X'Wide_Image denotes the result 
of calling function S'Wide_Image with 
Arg being X, where S is 
the nominal subtype of X.
 
   X'Image
X'Image denotes the result of 
calling function S'Image with 
Arg being X, where S is the nominal 
subtype of X.
 
Implementation Permissions
 An implementation may extend the Wide_Wide_Value, 
Wide_Value, Value, Wide_Wide_Image, Wide_Image, and Image attributes 
of a floating point type to support special values such as infinities 
and NaNs.
   An implementation may extend the Wide_Wide_Value, 
Wide_Value, and Value attributes of a character type to accept strings 
of the form “Hex_
hhhhhhhh” (ignoring case) for any 
character (not just the ones for which Wide_Wide_Image would produce 
that form — see 
3.5.2), as well as 
three-character strings of the form “'
X'”, where 
X 
is any character, including nongraphic characters. 
 
Static Semantics
   For a scalar type, 
the following language-defined representation aspect may be specified 
with an 
aspect_specification 
(see 
13.1.1): 
 
   Default_Value
This aspect shall be specified by a static expression, and that expression 
shall be explicit, even if the aspect has a boolean type. Default_Value 
shall be specified only on a 
full_type_declaration.
 
 
   If a derived type with no primitive subprograms 
inherits a boolean Default_Value aspect, the aspect may be specified 
to have any value for the derived type. 
Name Resolution Rules
27  The evaluation of S'First or S'Last 
never raises an exception. If a scalar subtype S has a nonnull range, 
S'First and S'Last belong to this range. These values can, for example, 
always be assigned to a variable of subtype S. 
28  For a subtype of a scalar type, the 
result delivered by the attributes Succ, Pred, and Value might not belong 
to the subtype; similarly, the actual parameters of the attributes Succ, 
Pred, and Image need not belong to the subtype.
29  For any value V (including any nongraphic 
character) of an enumeration subtype S, S'Value(S'Image(V)) equals V, 
as do S'Wide_Value(S'Wide_Image(V)) and S'Wide_Wide_Value(S'Wide_Wide_Image(V)). 
None of these expressions ever raise Constraint_Error. 
Examples
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
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe