Source file
src/math/logb.go
1
2
3
4
5 package math
6
7
8
9
10
11
12
13 func Logb(x float64) float64 {
14
15 switch {
16 case x == 0:
17 return Inf(-1)
18 case IsInf(x, 0):
19 return Inf(1)
20 case IsNaN(x):
21 return x
22 }
23 return float64(ilogb(x))
24 }
25
26
27
28
29
30
31
32 func Ilogb(x float64) int {
33
34 switch {
35 case x == 0:
36 return MinInt32
37 case IsNaN(x):
38 return MaxInt32
39 case IsInf(x, 0):
40 return MaxInt32
41 }
42 return ilogb(x)
43 }
44
45
46
47 func ilogb(x float64) int {
48 x, exp := normalize(x)
49 return int((Float64bits(x)>>shift)&mask) - bias + exp
50 }
51
View as plain text