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