From 39abea3d12e39498325d6bd838d7fde953684adf Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Mon, 5 Nov 2012 11:09:00 -0800 Subject: [PATCH] use a function-call example for coercing an apparent int to a float. ref #27 --- examples/constants/constants.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/constants/constants.go b/examples/constants/constants.go index 76f59c1..5ed88a4 100644 --- a/examples/constants/constants.go +++ b/examples/constants/constants.go @@ -4,6 +4,7 @@ package main import "fmt" +import "math" // `const` declares a constant value. const s string = "constant" @@ -18,15 +19,15 @@ func main() { // Constant expressions perform arithmetic with // arbitrary precision. const d = 3e20 / n + fmt.Println(d) // A numeric constant has no type until it's given // one, such as by an explicit cast. fmt.Println(int64(d)) - // A number can also be given a type by using it in a + // A number can be given a type by using it in a // context that requires one, such as a variable - // assignment or function call. The type it gets - // depends on its value. - fmt.Println(n) // int - fmt.Println(d) // float64 + // assignment or function call. For example, here + // `math.Sin` expects a `float64`. + fmt.Println(math.Sin(n)) }