...
Source file
src/runtime/fastlog2.go
Documentation: runtime
1
2
3
4
5 package runtime
6
7
8
9
10
11
12
13
14 func fastlog2(x float64) float64 {
15 const fastlogScaleBits = 20
16 const fastlogScaleRatio = 1.0 / (1 << fastlogScaleBits)
17
18 xBits := float64bits(x)
19
20
21 xExp := int64((xBits>>52)&0x7FF) - 1023
22 xManIndex := (xBits >> (52 - fastlogNumBits)) % (1 << fastlogNumBits)
23 xManScale := (xBits >> (52 - fastlogNumBits - fastlogScaleBits)) % (1 << fastlogScaleBits)
24
25 low, high := fastlog2Table[xManIndex], fastlog2Table[xManIndex+1]
26 return float64(xExp) + low + (high-low)*float64(xManScale)*fastlogScaleRatio
27 }
28
View as plain text