I was reading the source code of package math and I don't understand how the Max
function is defined.
Namely, there seems to be a function definition for Max
that somehow hangs, for lack of a better word.
Also, there seems to be another non-exported function named max
with the same signature as Max
, but this time, its implementation is present.
Why doesn't the compiler complain about function Max
in eg
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println("Max(1.1, 2.2)=", math.Max(1.1, 2.2))
}
whereas if one does something like
package main
import (
"fmt"
)
func A() bool
func a() bool { return true }
func main() {
fmt.Println(A())
}
in the Playground, the compiler produces./prog.go:7:6: missing function body
?
How is it possible to call math.Max
and obtain a result, when the body of the function, in its source file, is missing?
Edit
I think it's not a duplicate of the cited questions because this question is predominantly interested about math.Max
and its implementation and only circumstantially touches upon the issue addresed in the linked questions which is function definitions without a body. Also, it might prove useful to a future search about Max
to read the comments about the implementation of Max
in assembly outside of Go.