Skip to content

Commit 39abea3

Browse files
committed
use a function-call example for coercing an apparent int to a float. ref #27
1 parent 363613d commit 39abea3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

examples/constants/constants.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import "fmt"
7+
import "math"
78

89
// `const` declares a constant value.
910
const s string = "constant"
@@ -18,15 +19,15 @@ func main() {
1819
// Constant expressions perform arithmetic with
1920
// arbitrary precision.
2021
const d = 3e20 / n
22+
fmt.Println(d)
2123

2224
// A numeric constant has no type until it's given
2325
// one, such as by an explicit cast.
2426
fmt.Println(int64(d))
2527

26-
// A number can also be given a type by using it in a
28+
// A number can be given a type by using it in a
2729
// context that requires one, such as a variable
28-
// assignment or function call. The type it gets
29-
// depends on its value.
30-
fmt.Println(n) // int
31-
fmt.Println(d) // float64
30+
// assignment or function call. For example, here
31+
// `math.Sin` expects a `float64`.
32+
fmt.Println(math.Sin(n))
3233
}

0 commit comments

Comments
 (0)