From Go's FAQ,
The standard library's purpose is to support the runtime, connect to the operating system, and provide key functionality that many Go programs require, such as formatted I/O and networking. It also contains elements important for web programming, including cryptography and support for standards like HTTP, JSON, and XML.
There is no clear criterion that defines what is included because for a long time, this was the only Go library. There are criteria that define what gets added today, however.
New additions to the standard library are rare and the bar for inclusion is high. Code included in the standard library bears a large ongoing maintenance cost (often borne by those other than the original author), is subject to the Go 1 compatibility promise (blocking fixes to any flaws in the API), and is subject to the Go release schedule, preventing bug fixes from being available to users quickly.
Most new code should live outside of the standard library and be accessible via the go tool's go get command. Such code can have its own maintainers, release cycle, and compatibility guarantees. Users can find packages and read their documentation at godoc.org.
In response to how easy it is to create integer versions of the math package's float functions, Go team member Russ Cox once quipped,
Ceil, Floor, and Trunc are even easier!
A reasonable interpretation would be that since this function is trivial to write (if x < 0, x = -x), it does not meet the bar for inclusion. Compare with the float version:
func Abs(x float64) float64 {
return Float64frombits(Float64bits(x) &^ (1 << 63))
}
This being useful but also not obvious is a compelling reason to include it in the standard library.
math
package and then back to integers is almost never the correct thing to do. The only reason most of the simplemath
functions exists forfloat64
is that floats often have a number of corner cases (e.g. involving NaN and infinities) that are annoying to get correct; integers don't have those issues. – Shoshone