Skip to content

Commit fcb45e7

Browse files
Terrel Shumwaygriesemer
Terrel Shumway
authored andcommitted
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 <[email protected]>
1 parent d6098e4 commit fcb45e7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

doc/go_faq.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,17 @@ <h3 id="q_int_sizes">
12621262
Prior to Go 1.1, the 64-bit Go compilers (both gc and gccgo) used
12631263
a 32-bit representation for <code>int</code>. As of Go 1.1 they use
12641264
a 64-bit representation.
1265+
</p>
1266+
1267+
<p>
12651268
On the other hand, floating-point scalars and complex
1266-
numbers are always sized: <code>float32</code>, <code>complex64</code>,
1267-
etc., because programmers should be aware of precision when using
1268-
floating-point numbers.
1269-
The default size of a floating-point constant is <code>float64</code>.
1269+
types are always sized (there are no <code>float</code> or <code>complex</code> basic types),
1270+
because programmers should be aware of precision when using floating-point numbers.
1271+
The default type used for an (untyped) floating-point constant is <code>float64</code>.
1272+
Thus <code>foo := 3.0</code> declares a variable <code>foo</code> of type <code>float64</code>.
1273+
For a <code>float32</code> variable initialized by a constant, the variable type must be specified explicitly
1274+
in the variable declaration <code>var foo float32 = 3.0</code>, or the constant must be given a
1275+
type with a conversion as in <code>foo := float32(3.0)</code>.
12701276
</p>
12711277

12721278
<h3 id="stack_or_heap">

0 commit comments

Comments
 (0)