I skimmed through math package in Golang GitHub repo. Some of them have two difference function declarations. In the code below, sqrt.go
has Sqrt
and sqrt
func. My questions are:
Why do they implement it this way? What are the benefits? Is this because of the exported and unexported identifier (lowercase vs uppercase first letter)?
func Sqrt(x float64) float64
// Note: Sqrt is implemented in assembly on some systems.
// Others have assembly stubs that jump to func sqrt below.
// On systems where Sqrt is a single instruction, the compiler
// may turn a direct call into a direct use of that instruction instead.
func sqrt(x float64) float64 {
math.Sqrt()