When viewing the source for the math.Ceil
method, I found this syntax where there's an exported function signature with no body, and a non-exported version of the same signature that includes the implementation:
// Ceil returns the least integer value greater than or equal to x.
//
// Special cases are:
// Ceil(±0) = ±0
// Ceil(±Inf) = ±Inf
// Ceil(NaN) = NaN
func Ceil(x float64) float64
func ceil(x float64) float64 {
return -Floor(-x)
}
I assume this is some syntax which allows you to easily export a local function. Is that correct? And why would one do this instead of just having a single exported function and using it within the package?
Function Signature A function's signature includes the function's name and the number, order and type of its formal parameters. Two overloaded functions must not have the same signature. The return value is not part of a function's signature.
A function signature (or type signature, or method signature) defines input and output of functions or methods. A signature can include: parameters and their types. a return value and type.
C++ Reference. Programming Terms. Function Signatures. A function signature consists of the function prototype. What it tells you is the general information about a function, its name, parameters, what scope it is in, and other miscellaneous information.
For functions that are specializations of function templates, the signature includes the return type. For functions that are not specializations, the return type is not part of the signature.
According to the Go language specification.
A function declaration may omit the body. Such a declaration provides the signature for a function implemented outside Go, such as an assembly routine.
In this case, the Ceil
function is implemented by an architecture specific assembly file for 386 in floor_386.s
. Both the amd64 and arm architectures each have an assembly file that implements Ceil()
as well, but those assembly files are just glue to call the unexported ceil()
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With