From: Russ Cox Date: Mon, 11 Feb 2013 12:47:41 +0000 (-0500) Subject: spec: document fp rounding during explicit constant conversion X-Git-Tag: go1.1rc2~1077 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7576179aa3de1afc372da5ac9e9d4bcbdf226560;p=gostls13.git spec: document fp rounding during explicit constant conversion The gc compilers already behave this way. It was an explicit decision during the very long constant design discussions, but it appears not to have made it into the spec. Fixes #4398. R=golang-dev, r CC=golang-dev https://golang.org/cl/7313069 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index aa4330d420..246a3656ad 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -3470,6 +3470,14 @@ type T in any of these cases: x is representable by a value of type T.
  • + x is a floating-point constant, + T is a floating-point type, + and x is representable by a value + of type T after rounding using + IEEE 754 round-to-even rules. + The constant T(x) is the rounded value. +
  • +
  • x is an integer constant and T is a string type. The same rule as for non-constant x applies in this case @@ -3485,6 +3493,7 @@ Converting a constant yields a typed constant as result. uint(iota) // iota value of type uint float32(2.718281828) // 2.718281828 of type float32 complex128(1) // 1.0 + 0.0i of type complex128 +float32(0.49999999) // 0.5 of type float32 string('x') // "x" of type string string(0x266c) // "♬" of type string MyString("foo" + "bar") // "foobar" of type MyString