aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerrel Shumway <gopher@shumway.us>2016-08-30 07:58:52 -0600
committerRobert Griesemer <gri@golang.org>2016-08-30 17:36:32 +0000
commitfcb45e7ceff09548eb0308909256296086eedf9c (patch)
tree3b29dd5f510c6991efdecf3c83fb44483ce7ebe6
parentd6098e4277bab633c2df752ed90e1e826918ca67 (diff)
downloadgo-fcb45e7ceff09548eb0308909256296086eedf9c.tar.xz
doc: clarify FAQ wording for float sizes
I was confused by the current wording. This wording answers the question more clearly. Thanks to Robert Griesemer for suggestions. Fixes #16916 Change-Id: I50187c8df2db661b9581f4b3c5d5c279d2f9af41 Reviewed-on: https://go-review.googlesource.com/28052 Reviewed-by: Robert Griesemer <gri@golang.org>
-rw-r--r--doc/go_faq.html14
1 files changed, 10 insertions, 4 deletions
diff --git a/doc/go_faq.html b/doc/go_faq.html
index 50108c075b..905bf9c9a3 100644
--- a/doc/go_faq.html
+++ b/doc/go_faq.html
@@ -1262,11 +1262,17 @@ size of value should use an explicitly sized type, like <code>int64</code>.
Prior to Go 1.1, the 64-bit Go compilers (both gc and gccgo) used
a 32-bit representation for <code>int</code>. As of Go 1.1 they use
a 64-bit representation.
+</p>
+
+<p>
On the other hand, floating-point scalars and complex
-numbers are always sized: <code>float32</code>, <code>complex64</code>,
-etc., because programmers should be aware of precision when using
-floating-point numbers.
-The default size of a floating-point constant is <code>float64</code>.
+types are always sized (there are no <code>float</code> or <code>complex</code> basic types),
+because programmers should be aware of precision when using floating-point numbers.
+The default type used for an (untyped) floating-point constant is <code>float64</code>.
+Thus <code>foo := 3.0</code> declares a variable <code>foo</code> of type <code>float64</code>.
+For a <code>float32</code> variable initialized by a constant, the variable type must be specified explicitly
+in the variable declaration <code>var foo float32 = 3.0</code>, or the constant must be given a
+type with a conversion as in <code>foo := float32(3.0)</code>.
</p>
<h3 id="stack_or_heap">