]> Cypherpunks repositories - gostls13.git/commit
spec: explicitly define notion of "representability" (clarification)
authorgriesemer <gri@golang.org>
Mon, 21 Aug 2017 13:47:51 +0000 (15:47 +0200)
committerRobert Griesemer <gri@golang.org>
Fri, 25 Aug 2017 19:54:57 +0000 (19:54 +0000)
commitb40831b115e46e9de719bddccf2d27d7d4940756
treef2ff1411f6b26b55bed6eb0ef29e56325072800d
parent25bbb695c87213ae3a609a76362975188f6be4a7
spec: explicitly define notion of "representability" (clarification)

Throughout the spec we use the notion of a constant x being
representable by a value of type T. While intuitively clear,
at least for floating-point and complex constants types, the
concept was not well-defined. In the section on Conversions
there was an extra rule for floating-point types only and it
missed the case of floating-point values overflowing to an
infinity after rounding.

Since the concept is important to Go, and a compiler most
certainly will have a function to test "representability",
it seems warranted to define the term explicitly in the spec.

This change introduces a new entry "Representability" under
the section on "Properties of types and values", and defines
the term explicitly, together with examples.

The phrase used is "representable by" rather than "representable as"
because the former use is prevalent in the spec.

Additionally, it clarifies that a floating-point constant
that overflows to an infinity after rounding is never
representable by a value of a floating-point type, even though
infinities are valid values of IEEE floating point types.
This is required because there are not infinite value constants
in the language (like there is also no -0.0) and representability
also matters for constant conversions. This is not a language
change, and type-checkers have been following this rule before.

The change also introduces links throughout the spec to the new
section as appropriate and removes duplicate text and examples
elsewhere (Constants and Conversions sections), leading to
simplifications in the relevant paragraphs.

Fixes #15389.

Change-Id: I8be0e071552df0f18998ef4c5ef521f64ffe8c44
Reviewed-on: https://go-review.googlesource.com/57530
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
doc/go_spec.html