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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Model of Floating Point Arithmetic</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-G-2.html">Previous</A> <A HREF="AA-G-2-2.html">Next</A></P>
<HR>
<H1> G.2.1 Model of Floating Point Arithmetic</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> In the strict mode, the predefined operations
of a floating point type shall satisfy the accuracy requirements specified
here and shall avoid or signal overflow in the situations described.
This behavior is presented in terms of a model of floating point arithmetic
that builds on the concept of the canonical form (see <A HREF="AA-A-5-3.html">A.5.3</A>).
</DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal"> Associated with each floating point type is an
infinite set of model numbers. The model numbers of a type are used to
define the accuracy requirements that have to be satisfied by certain
predefined operations of the type; through certain attributes of the
model numbers, they are also used to explain the meaning of a user-declared
floating point type declaration. The model numbers of a derived type
are those of the parent type; the model numbers of a subtype are those
of its type.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal"> <A NAME="I7253"></A>The <I>model numbers</I> of
a floating point type T are zero and all the values expressible in the
canonical form (for the type T), in which <I>mantissa</I> has T'Model_Mantissa
digits and <I>exponent</I> has a value greater than or equal to T'Model_Emin.
(These attributes are defined in <A HREF="AA-G-2-2.html">G.2.2</A>.)
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>The model is
capable of describing the behavior of most existing hardware that has
a mantissa-exponent representation. As applied to a type T, it is parameterized
by the values of T'Machine_Radix, T'Model_Mantissa, T'Model_Emin, T'Safe_First,
and T'Safe_Last. The values of these attributes are determined by how,
and how well, the hardware behaves. They in turn determine the set of
model numbers and the safe range of the type, which figure in the accuracy
and range (overflow avoidance) requirements.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>In hardware that is free of arithmetic
anomalies, T'Model_Mantissa, T'Model_Emin, T'Safe_First, and T'Safe_Last
will yield the same values as T'Machine_Mantissa, T'Machine_Emin, T'Base'First,
and T'Base'Last, respectively, and the model numbers in the safe range
of the type T will coincide with the machine numbers of the type T. In
less perfect hardware, it is not possible for the model-oriented attributes
to have these optimal values, since the hardware, by definition, and
therefore the implementation, cannot conform to the stringencies of the
resulting model; in this case, the values yielded by the model-oriented
parameters have to be made more conservative (i.e., have to be penalized),
with the result that the model numbers are more widely separated than
the machine numbers, and the safe range is a subrange of the base range.
The implementation will then be able to conform to the requirements of
the weaker model defined by the sparser set of model numbers and the
smaller safe range. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="Normal"> <A NAME="I7254"></A>A <I>model interval</I> of
a floating point type is any interval whose bounds are model numbers
of the type. <A NAME="I7255"></A>The <I>model interval</I> of a type
T <I>associated with a value</I> <I>v</I> is the smallest model interval
of T that includes <I>v</I>. (The model interval associated with a model
number of a type consists of that number only.) </DIV>
<H4 ALIGN=CENTER>Implementation Requirements</H4>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="Normal"> The accuracy requirements for the evaluation of
certain predefined operations of floating point types are as follows.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This subclause
does not cover the accuracy of an operation of a static expression; such
operations have to be evaluated exactly (see <A HREF="AA-4-9.html">4.9</A>).
It also does not cover the accuracy of the predefined attributes of a
floating point subtype that yield a value of the type; such operations
also yield exact results (see <A HREF="AA-3-5-8.html">3.5.8</A> and <A HREF="AA-A-5-3.html">A.5.3</A>).
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Normal"> <A NAME="I7256"></A>An <I>operand interval</I>
is the model interval, of the type specified for the operand of an operation,
associated with the value of the operand.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> For any predefined
arithmetic operation that yields a result of a floating point type T,
the required bounds on the result are given by a model interval of T
(called the <I>result interval</I>) defined in terms of the operand values
as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I7257"></A>The result interval is the smallest
model interval of T that includes the minimum and the maximum of all
the values obtained by applying the (exact) mathematical operation to
values arbitrarily selected from the respective operand intervals. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Normal"> The result interval of an exponentiation is obtained
by applying the above rule to the sequence of multiplications defined
by the exponent, assuming arbitrary association of the factors, and to
the final division in the case of a negative exponent.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal"> The result interval of a conversion of a numeric
value to a floating point type T is the model interval of T associated
with the operand value, except when the source expression is of a fixed
point type with a <I>small</I> that is not a power of T'Machine_Radix
or is a fixed point multiplication or division either of whose operands
has a <I>small</I> that is not a power of T'Machine_Radix; in these cases,
the result interval is implementation defined. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>The
result interval in certain cases of fixed-to-float conversion.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> <A NAME="I7258"></A><A NAME="I7259"></A>For any
of the foregoing operations, the implementation shall deliver a value
that belongs to the result interval when both bounds of the result interval
are in the safe range of the result type T, as determined by the values
of T'Safe_First and T'Safe_Last; otherwise, </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I7260"></A>if T'Machine_Overflows is True, the
implementation shall either deliver a value that belongs to the result
interval or raise Constraint_Error;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>if T'Machine_Overflows is False, the result is implementation
defined. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>The
result of a floating point arithmetic operation in overflow situations,
when the Machine_Overflows attribute of the result type is False.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal"> For any predefined relation on operands of a
floating point type T, the implementation may deliver any value (i.e.,
either True or False) obtained by applying the (exact) mathematical comparison
to values arbitrarily chosen from the respective operand intervals.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Normal"> The result of a membership test is defined in
terms of comparisons of the operand value with the lower and upper bounds
of the given range or type mark (the usual rules apply to these comparisons).
</DIV>
<H4 ALIGN=CENTER>Implementation Permissions</H4>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Normal"> If the underlying floating point hardware implements
division as multiplication by a reciprocal, the result interval for division
(and exponentiation by a negative exponent) is implementation defined.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>The
result interval for division (or exponentiation by a negative exponent),
when the floating point hardware implements division as multiplication
by a reciprocal.</FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>16.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The Ada 95 model numbers of a
floating point type that are in the safe range of the type are comparable
to the Ada 83 safe numbers of the type. There is no analog of the Ada
83 model numbers. The Ada 95 model numbers, when not restricted to the
safe range, are an infinite set. </FONT></DIV>
<H4 ALIGN=CENTER>Inconsistencies With Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>16.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I7261"></A>Giving the
model numbers the hardware radix, instead of always a radix of two, allows
(in conjunction with other changes) some borderline declared types to
be represented with less precision than in Ada 83 (i.e., with single
precision, whereas Ada 83 would have used double precision). Because
the lower precision satisfies the requirements of the model (and did
so in Ada 83 as well), this change is viewed as a desirable correction
of an anomaly, rather than a worrisome inconsistency. (Of course, the
wider representation chosen in Ada 83 also remains eligible for selection
in Ada 95.)</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>As an example of this phenomenon,
assume that Float is represented in single precision and that a double
precision type is also available. Also assume hexadecimal hardware with
clean properties, for example certain IBM hardware. Then, </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.e</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>type</B> T <B>is</B> <B>digits</B> Float'Digits <B>range</B> -Float'Last .. Float'Last;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.f</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>results in T being represented
in double precision in Ada 83 and in single precision in Ada 95. The
latter is intuitively correct; the former is counterintuitive. The reason
why the double precision type is used in Ada 83 is that Float has model
and safe numbers (in Ada 83) with 21 binary digits in their mantissas,
as is required to model the hypothesized hexadecimal hardware using a
binary radix; thus Float'Last, which is not a model number, is slightly
outside the range of safe numbers of the single precision type, making
that type ineligible for selection as the representation of T even though
it provides adequate precision. In Ada 95, Float'Last (the same value
as before) is a model number and is in the safe range of Float on the
hypothesized hardware, making Float eligible for the representation of
T. </FONT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>16.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I7262"></A>Giving the
model numbers the hardware radix allows for practical implementations
on decimal hardware. </FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>16.h</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The wording of the model of floating
point arithmetic has been simplified to a large extent. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-G-2.html">Previous</A> <A HREF="AA-G-2-2.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|