1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Integer Types</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-3-5-3.html">Previous</A> <A HREF="AA-3-5-5.html">Next</A></P>
<HR>
<H1> 3.5.4 Integer Types</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1661"></A><A NAME="I1662"></A><A NAME="I1663"></A>An
<FONT FACE="Arial, Helvetica">integer_type_definition</FONT> defines
an integer type; it defines either a <I>signed</I> integer type, or a
<I>modular</I> integer type. The base range of a signed integer type
includes at least the values of the specified range. A modular type is
an integer type with all arithmetic modulo a specified positive <I>modulus</I>;
such a type corresponds to an unsigned type with wrap-around semantics.
<A NAME="I1664"></A></DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">integer_type_definition<A NAME="I1665"></A>
::= </FONT><A NAME="I1666"></A><FONT FACE="Arial, Helvetica">signed_integer_type_definition</FONT> | <A NAME="I1667"></A><FONT FACE="Arial, Helvetica">modular_type_definition</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">signed_integer_type_definition<A NAME="I1668"></A>
::= </FONT><B>range</B> <I>static_</I><A NAME="I1669"></A><FONT FACE="Arial, Helvetica">simple_expression</FONT> .. <I>static_</I><A NAME="I1670"></A><FONT FACE="Arial, Helvetica">simple_expression</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>We don't call
this a <FONT FACE="Arial, Helvetica">range_constraint</FONT>, because
it is rather different -- not only is it required to be static, but the
associated overload resolution rules are different than for normal range
constraints. A similar comment applies to <FONT FACE="Arial, Helvetica">real_range_specification</FONT>.
This used to be <FONT FACE="Arial, Helvetica">integer_range_specification</FONT>
but when we added support for modular types, it seemed overkill to have
three levels of syntax rules, and just calling these <FONT FACE="Arial, Helvetica">signed_integer_range_specification</FONT>
and <FONT FACE="Arial, Helvetica">modular_range_specification</FONT>
loses the fact that they are defining different classes of types, which
is important for the generic type matching rules. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">modular_type_definition<A NAME="I1671"></A>
::= </FONT><B>mod</B> <I>static_</I><A NAME="I1672"></A><FONT FACE="Arial, Helvetica">expression</FONT></DIV>
<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1673"></A>Each <FONT FACE="Arial, Helvetica">simple_expression</FONT>
in a <FONT FACE="Arial, Helvetica">signed_integer_type_definition</FONT>
is expected to be of any integer type; they need not be of the same type.
<A NAME="I1674"></A>The <FONT FACE="Arial, Helvetica">expression</FONT>
in a <FONT FACE="Arial, Helvetica">modular_type_definition</FONT> is
likewise expected to be of any integer type. </DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Normal"> The <FONT FACE="Arial, Helvetica">simple_expression</FONT>s
of a <FONT FACE="Arial, Helvetica">signed_integer_type_definition</FONT>
shall be static, and their values shall be in the range System.Min_Int
.. System.Max_Int.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1675"></A><A NAME="I1676"></A><A NAME="I1677"></A>The
<FONT FACE="Arial, Helvetica">expression</FONT> of a <FONT FACE="Arial, Helvetica">modular_type_definition</FONT>
shall be static, and its value (the <I>modulus</I>) shall be positive,
and shall be no greater than System.Max_Binary_Modulus if a power of
2, or no greater than System.Max_Nonbinary_Modulus if not. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>For a 2's-complement
machine, supporting nonbinary moduli greater than System.Max_Int can
be quite difficult, whereas essentially any binary moduli are straightforward
to support, up to 2*System.Max_Int+2, so this justifies having two separate
limits. </FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal"> The set of values for a signed integer type is
the (infinite) set of mathematical integers[, though only values of the
base range of the type are fully supported for run-time operations].
The set of values for a modular integer type are the values from 0 to
one less than the modulus, inclusive.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1678"></A>A <FONT FACE="Arial, Helvetica">signed_integer_type_definition</FONT>
defines an integer type whose base range includes at least the values
of the <FONT FACE="Arial, Helvetica">simple_expression</FONT>s and is
symmetric about zero, excepting possibly an extra negative value. <A NAME="I1679"></A><A NAME="I1680"></A>A
<FONT FACE="Arial, Helvetica">signed_integer_type_definition</FONT> also
defines a constrained first subtype of the type, with a range whose bounds
are given by the values of the <FONT FACE="Arial, Helvetica">simple_expression</FONT>s,
converted to the type being defined. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>The
base range of a signed integer type might be much larger than is necessary
to satisfy the aboved requirements. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B><U>The conversion
mentioned above is not an <I>implicit subtype conversion</I> (which is
something that happens at overload resolution, see <A HREF="AA-4-6.html">4.6</A>),
although it happens implicitly. Therefore, the freezing rules are not
invoked on the type (which is important so that representation items
can be given for the type). <A NAME="I1681"></A></U></FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1682"></A>A <FONT FACE="Arial, Helvetica">modular_type_definition</FONT>
defines a modular type whose base range is from zero to one less than
the given modulus. <A NAME="I1683"></A><A NAME="I1684"></A>A <FONT FACE="Arial, Helvetica">modular_type_definition</FONT>
also defines a constrained first subtype of the type with a range that
is the same as the base range of the type.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1685"></A>There is a predefined signed
integer subtype named Integer[, declared in the visible part of package
Standard]. It is constrained to the base range of its type. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Integer is a constrained
subtype, rather than an unconstrained subtype. This means that on assignment
to an object of subtype Integer, a range check is required. On the other
hand, an object of subtype Integer'Base is unconstrained, and no range
check (only overflow check) is required on assignment. For example, if
the object is held in an extended-length register, its value might be
outside of Integer'First .. Integer'Last. All parameter and result subtypes
of the predefined integer operators are of such unconstrained subtypes,
allowing extended-length registers to be used as operands or for the
result. In an earlier version of Ada 95, Integer was unconstrained. However,
the fact that certain Constraint_Errors might be omitted or appear elsewhere
was felt to be an undesirable upward inconsistency in this case. Note
that for Float, the opposite conclusion was reached, partly because of
the high cost of performing range checks when not actually necessary.
Objects of subtype Float are unconstrained, and no range checks, only
overflow checks, are performed for them. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I1686"></A><A NAME="I1687"></A>Integer
has two predefined subtypes, [declared in the visible part of package
Standard:] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Examples"><TT><B>subtype</B> Natural <B>is</B> Integer <B>range</B> 0 .. Integer'Last;<BR>
<B>subtype</B> Positive <B>is</B> Integer <B>range</B> 1 .. Integer'Last;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1688"></A><A NAME="I1689"></A><A NAME="I1690"></A>A
type defined by an <FONT FACE="Arial, Helvetica">integer_type_definition</FONT>
is implicitly derived from <I>root_integer</I>, an anonymous predefined
(specific) integer type, whose base range is System.Min_Int .. System.Max_Int.
However, the base range of the new type is not inherited from <I>root_integer</I>,
but is instead determined by the range or modulus specified by the <FONT FACE="Arial, Helvetica">integer_type_definition</FONT>.
<A NAME="I1691"></A><A NAME="I1692"></A>[Integer literals are all of
the type <I>universal_integer</I>, the universal type (see <A HREF="AA-3-4-1.html">3.4.1</A>)
for the class rooted at <I>root_integer</I>, allowing their use with
the operations of any integer type.] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This implicit
derivation is not considered exactly equivalent to explicit derivation
via a <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>. In
particular, integer types defined via a <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>
inherit their base range from their parent type. A type defined by an
<FONT FACE="Arial, Helvetica">integer_type_definition</FONT> does not
necessarily inherit its base range from <I>root_integer</I>. It is not
specified whether the implicit derivation from <I>root_integer</I> is
direct or indirect, not that it really matters. All we want is for all
integer types to be descendants of <I>root_integer</I>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>{<I><A HREF="defect2.html#8652/0099">8652/0099</A></I>}
<U>Note that this derivation does not imply any inheritance of subprograms.
Subprograms are inherited only for types derived by a <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>
(see <A HREF="AA-3-4.html">3.4</A>), or a <FONT FACE="Arial, Helvetica">private_extension_declaration</FONT>
(see <A HREF="AA-7-3.html">7.3</A>, <A HREF="AA-7-3-1.html">7.3.1</A>,
and <A HREF="AA-12-5-1.html">12.5.1</A>).</U> </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>It
is the intent that even nonstandard integer types (see below) will be
descendants of <I>root_integer</I>, even though they might have a base
range that exceeds that of <I>root_integer</I>. This causes no problem
for static calculations, which are performed without range restrictions
(see <A HREF="AA-4-9.html">4.9</A>). However for run-time calculations,
it is possible that Constraint_Error might be raised when using an operator
of <I>root_integer</I> on the result of 'Val applied to a value of a
nonstandard integer type. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1693"></A>The <I>position number</I>
of an integer value is equal to the value.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Wide" Style="margin-bottom: 0.4em"> For every modular
subtype S, the following attribute is defined: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DL Class="Hanging"><DT> S'Modulus<DD Class="Hanging">
<A NAME="I1694"></A><A NAME="I1695"></A>S'Modulus yields the modulus
of the type of S, as a value of the type <I>universal_integer</I>. </DL>
<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1696"></A>The elaboration of an <FONT FACE="Arial, Helvetica">integer_type_definition</FONT>
creates the integer type and its first subtype.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<DIV Class="Normal"> For a modular type, if the result of the execution
of a predefined operator (see <A HREF="AA-4-5.html">4.5</A>) is outside
the base range of the type, the result is reduced modulo the modulus
of the type to a value that is within the base range of the type.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1697"></A><A NAME="I1698"></A><A NAME="I1699"></A>For
a signed integer type, the exception Constraint_Error is raised by the
execution of an operation that cannot deliver the correct result because
it is outside the base range of the type. [<A NAME="I1700"></A><A NAME="I1701"></A>
<A NAME="I1702"></A>For any integer type, Constraint_Error is raised
by the operators "/", "<B>rem</B>", and "<B>mod</B>"
if the right operand is zero.]</DIV>
<H4 ALIGN=CENTER>Implementation Requirements</H4>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1703"></A>In an implementation, the
range of Integer shall include the range -2**15+1 .. +2**15-1.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1704"></A>If Long_Integer is predefined
for an implementation, then its range shall include the range -2**31+1
.. +2**31-1.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<DIV Class="Normal"> System.Max_Binary_Modulus shall be at least 2**16.
</DIV>
<H4 ALIGN=CENTER>Implementation Permissions</H4>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<DIV Class="Normal"> For the execution of a predefined operation of
a signed integer type, the implementation need not raise Constraint_Error
if the result is outside the base range of the type, so long as the correct
result is produced. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Constraint_Error
is never raised for operations on modular types, except for divide-by-zero
(and <B>rem</B>/<B>mod</B>-by-zero). </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1705"></A><A NAME="I1706"></A>An implementation
may provide additional predefined signed integer types[, declared in
the visible part of Standard], whose first subtypes have names of the
form Short_Integer, Long_Integer, Short_Short_Integer, Long_Long_Integer,
etc. Different predefined integer types are allowed to have the same
base range. However, the range of Integer should be no wider than that
of Long_Integer. Similarly, the range of Short_Integer (if provided)
should be no wider than Integer. Corresponding recommendations apply
to any other predefined integer types. There need not be a named integer
type corresponding to each distinct base range supported by an implementation.
The range of each first subtype should be the base range of its type.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>The
predefined integer types declared in Standard.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1707"></A>An implementation may provide
<I>nonstandard integer types</I>, descendants of <I>root_integer</I>
that are declared outside of the specification of package Standard, which
need not have all the standard characteristics of a type defined by an
<FONT FACE="Arial, Helvetica">integer_type_definition</FONT>. For example,
a nonstandard integer type might have an asymmetric base range or it
might not be allowed as an array or loop index (a very long integer).
Any type descended from a nonstandard integer type is also nonstandard.
An implementation may place arbitrary restrictions on the use of such
types; it is implementation defined whether operators that are predefined
for ``any integer type'' are defined for a particular nonstandard integer
type. [In any case, such types are not permitted as <FONT FACE="Arial, Helvetica">explicit_generic_actual_parameter</FONT>s
for formal scalar types -- see <A HREF="AA-12-5-2.html">12.5.2</A>.]
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>Any
nonstandard integer types and the operators defined for them.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1708"></A>For a one's complement machine,
the high bound of the base range of a modular type whose modulus is one
less than a power of 2 may be equal to the modulus, rather than one less
than the modulus. It is implementation defined for which powers of 2,
if any, this permission is exercised.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.1/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0003">8652/0003</A></I>}
<U>For a one's complement machine, implementations may support non-binary
modulus values greater than System.Max_Nonbinary_Modulus. It is implementation
defined which specific values greater than System.Max_Nonbinary_Modulus,
if any, are supported.</U> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B><U>On a one's complement
machine, the natural full word type would have a modulus of 2**Word_Size-1.
However, we would want to allow the all-ones bit pattern (which represents
negative zero as a number) in logical operations. These permissions are
intended to allow that and the natural modulus value without burdening
implementations with supporting expensive modulus values.</U> </FONT></DIV>
<H4 ALIGN=CENTER>Implementation Advice</H4>
<DIV Class="Paranum"><FONT SIZE=-2>28</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1709"></A>An implementation should
support Long_Integer in addition to Integer if the target machine supports
32-bit (or longer) arithmetic. No other named integer subtypes are recommended
for package Standard. Instead, appropriate named integer subtypes should
be provided in the library package Interfaces (see <A HREF="AA-B-2.html">B.2</A>).
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>28.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>To
promote portability, implementations should explicitly declare the integer
(sub)types Integer and Long_Integer in Standard, and leave other predefined
integer types anonymous. For implementations that already support Byte_Integer,
etc., upward compatibility argues for keeping such declarations in Standard
during the transition period, but perhaps generating a warning on use.
A separate package Interfaces in the predefined environment is available
for pre-declaring types such as Integer_8, Integer_16, etc. See <A HREF="AA-B-2.html">B.2</A>.
In any case, if the user declares a subtype (first or not) whose range
fits in, for example, a byte, the implementation can store variables
of the subtype in a single byte, even if the base range of the type is
wider. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1710"></A>An implementation for a two's
complement machine should support modular types with a binary modulus
up to System.Max_Int*2+2. An implementation should support a nonbinary
modulus up to Integer'Last. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Modular types provide
bit-wise "<B>and</B>", "<B>or</B>", "<B>xor</B>",
and "<B>not</B>" operations. It is important for systems programming
that these be available for all integer types of the target hardware.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Note that
on a one's complement machine, the largest supported modular type would
normally have a nonbinary modulus. On a two's complement machine, the
largest supported modular type would normally have a binary modulus.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Supporting
a nonbinary modulus greater than Integer'Last can impose an undesirable
implementation burden on some machines. </FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>30</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>25 <A NAME="I1711"></A><A NAME="I1712"></A>Integer
literals are of the anonymous predefined integer type <I>universal_integer</I>.
Other integer types have no literals. However, the overload resolution
rules (see <A HREF="AA-8-6.html">8.6</A>, ``<A HREF="AA-8-6.html">The
Context of Overload Resolution</A>'') allow expressions of the type <I>universal_integer</I>
whenever an integer type is expected.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>31</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>26 The same arithmetic operators
are predefined for all signed integer types defined by a <FONT FACE="Arial, Helvetica">signed_integer_type_definition</FONT>
(see <A HREF="AA-4-5.html">4.5</A>, ``<A HREF="AA-4-5.html">Operators
and Expression Evaluation</A>''). For modular types, these same operators
are predefined, plus bit-wise logical operators (<B>and</B>, <B>or</B>,
<B>xor</B>, and <B>not</B>). In addition, for the unsigned types declared
in the language-defined package Interfaces (see <A HREF="AA-B-2.html">B.2</A>),
functions are defined that provide bit-wise shifting and rotating.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>32</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>27 Modular types match a
<FONT FACE="Arial, Helvetica">generic_formal_parameter_declaration</FONT>
of the form "<B>type</B> T <B>is mod</B> <>;"; signed
integer types match "<B>type</B> T <B>is range</B> <>;"
(see <A HREF="AA-12-5-2.html">12.5.2</A>). </FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>33</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Examples of
integer types and subtypes: </I></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>34</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B> Page_Num <B>is</B> <B>range</B> 1 .. 2_000;<BR>
<B>type</B> Line_Size <B>is</B> <B>range</B> 1 .. Max_Line_Size;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35</FONT></DIV>
<DIV Class="Examples"><TT><B>subtype</B> Small_Int <B>is</B> Integer <B>range</B> -10 .. 10;<BR>
<B>subtype</B> Column_Ptr <B>is</B> Line_Size <B>range</B> 1 .. 10;<BR>
<B>subtype</B> Buffer_Size <B>is</B> Integer <B>range</B> 0 .. Max;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B> Byte <B>is</B> <B>mod</B> 256; <I>-- an unsigned byte</I><BR>
<B>type</B> Hash_Index <B>is</B> <B>mod</B> 97; <I>-- modulus is prime</I></TT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>36.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I1713"></A>An implementation
is allowed to support any number of distinct base ranges for integer
types, even if fewer integer types are explicitly declared in Standard.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Modular (unsigned, wrap-around)
types are new. </FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>36.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Ada 83's integer types are now
called "signed" integer types, to contrast them with "modular"
integer types.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Standard.Integer, Standard.Long_Integer,
etc., denote constrained subtypes of predefined integer types, consistent
with the Ada 95 model that only subtypes have names.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We now impose minimum requirements
on the base range of Integer and Long_Integer.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.f</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We no longer explain integer type
definition in terms of an equivalence to a normal type derivation, except
to say that all integer types are by definition implicitly derived from
<I>root_integer</I>. This is for various reasons.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>First of all, the equivalence
with a type derivation and a subtype declaration was not perfect, and
was the source of various AIs (for example, is the conversion of the
bounds static? Is a numeric type a derived type with respect to other
rules of the language?)</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.h</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Secondly, we don't want to require
that every integer size supported shall have a corresponding named type
in Standard. Adding named types to Standard creates nonportabilities.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.i</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Thirdly, we don't want the set
of types that match a formal derived type "type T is new Integer;"
to depend on the particular underlying integer representation chosen
to implement a given user-defined integer type. Hence, we would have
needed anonymous integer types as parent types for the implicit derivation
anyway. We have simply chosen to identify only one anonymous integer
type -- <I>root_integer</I>, and stated that every integer type is derived
from it.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.j</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Finally, the ``fiction'' that
there were distinct preexisting predefined types for every supported
representation breaks down for fixed point with arbitrary smalls, and
was never exploited for enumeration types, array types, etc. Hence, there
seems little benefit to pushing an explicit equivalence between integer
type definition and normal type derivation. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-3-5-3.html">Previous</A> <A HREF="AA-3-5-5.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|