Skip to content

Instantly share code, notes, and snippets.

@cc2011
Last active May 23, 2016 17:49
Show Gist options
  • Save cc2011/c93cbdeb7160c3ef96eeb69de6cd23cc to your computer and use it in GitHub Desktop.
Save cc2011/c93cbdeb7160c3ef96eeb69de6cd23cc to your computer and use it in GitHub Desktop.
Func Golang
func hypot(x, y float64) float64 {
return math.Sqrt(x*x + y*y)
}
fmt.Println(hypot(3, 4)) // "5"
x and y are parameters in the declaration, 3 and 4 are arguments of the call, and the function returns a float64 value.
Arguments are passed by value, so the function receives a copy of each argument;
modifica- tions to the copy do not affect the caller. However, if the argument contains some kind of ref- erence,
like a pointer, slice, map, function, or channel, then the caller may be affected by any modifications the function
makes to variables indirectly referred to by the argument.
You may occasionally encounter a function declaration without a body,
indicating that the function is implemented in a language other than Go.
Such a declaration defines the function signature.package math
func Sin(x float64) float64 // implemented in assembly language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment