Documentation ¶
Overview ¶
Package log10 calculates log base 10 of an integer. This is a simple task. This package focuses on performance, as there are non-obvious techniques for speed.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Uint32 ¶
Uint32 returns the number of digits required to hold the base 10 representation of x. As a special case, Uint32(0) == 1.
Note that if you are making a byte buffer for a base 10 representation of x, you will often get better results by calling make with a large-enough constant. Be sure to benchmark both approaches.
Implementation inspired by https://lemire.me/blog/2021/05/28/computing-the-number-of-digits-of-an-integer-quickly/#comment-585476 and tweaked for the Go compiler.
Example ¶
package main import ( "fmt" "github.com/josharian/log10" ) func main() { examples := []uint32{0, 1, 9, 10, 11} for _, e := range examples { fmt.Printf("log10.Uint32(%d) = %d\n", e, log10.Uint32(e)) } }
Output: log10.Uint32(0) = 1 log10.Uint32(1) = 1 log10.Uint32(9) = 1 log10.Uint32(10) = 2 log10.Uint32(11) = 2
Types ¶
This section is empty.