use a function-call example for coercing an apparent int to a float. ref #27
This commit is contained in:
parent
363613d951
commit
39abea3d12
@ -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))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user