mirror of
https://github.com/golang/go
synced 2024-11-25 07:57:56 -07:00
spec: clarify implementation restrictions on untyped floats
Drop reference to "machine type." Specify that integer overflow must be an error. Drop requirement that exponent must be 128 bits--that's a lot. Clarify that floating point expressions may be rounded, including intermediate values. This is a reworking of https://golang.org/cl/5577068/ . Fixes #2789. R=r, rsc, r, gri, ken, ken, iant CC=golang-dev, remyoudompheng https://golang.org/cl/5655049
This commit is contained in:
parent
9a4487458a
commit
9126c6570c
@ -589,11 +589,33 @@ functions return and test for those values at run time.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Implementation restriction: A compiler may implement numeric constants by choosing
|
Implementation restriction: Although numeric constants have arbitrary
|
||||||
an internal representation with at least twice as many bits as any machine type;
|
precision in the language, a compiler may implement them using an
|
||||||
for floating-point values, both the mantissa and exponent must be twice as large.
|
internal representation with limited precision. That said, every
|
||||||
|
implementation must:
|
||||||
</p>
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>Represent integer constants with at least 256 bits.</li>
|
||||||
|
|
||||||
|
<li>Represent floating-point constants, including the parts of
|
||||||
|
a complex constant, with a mantissa of at least 256 bits
|
||||||
|
and a signed exponent of at least 32 bits.</li>
|
||||||
|
|
||||||
|
<li>Give an error if unable to represent an integer constant
|
||||||
|
precisely.</li>
|
||||||
|
|
||||||
|
<li>Give an error if unable to represent a floating-point or
|
||||||
|
complex constant due to overflow.</li>
|
||||||
|
|
||||||
|
<li>Round to the nearest representable constant if unable to
|
||||||
|
represent a floating-point or complex constant due to limits
|
||||||
|
on precision.</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
These requirements apply both to literal constants and to the result
|
||||||
|
of evaluating <a href="#Constant_expressions">constant
|
||||||
|
expressions</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
<h2 id="Types">Types</h2>
|
<h2 id="Types">Types</h2>
|
||||||
|
|
||||||
@ -3574,6 +3596,16 @@ int8(^1) // same as int8(-2)
|
|||||||
^int8(1) // same as -1 ^ int8(1) = -2
|
^int8(1) // same as -1 ^ int8(1) = -2
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Implementation restriction: A compiler may use rounding while
|
||||||
|
computing untyped floating-point or complex constant expressions; see
|
||||||
|
the implementation restriction in the section
|
||||||
|
on <a href="#Constants">constants</a>. This rounding may cause a
|
||||||
|
floating-point constant expression to be invalid in an integer
|
||||||
|
context, even if it would be integral when calculated using infinite
|
||||||
|
precision.
|
||||||
|
</p>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<p>
|
<p>
|
||||||
<span class="alert">
|
<span class="alert">
|
||||||
|
Loading…
Reference in New Issue
Block a user