summaryrefslogtreecommitdiff
path: root/libgo/go/math/logb.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/math/logb.go')
-rw-r--r--libgo/go/math/logb.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/libgo/go/math/logb.go b/libgo/go/math/logb.go
index 22ec06325d5..072281ddf9f 100644
--- a/libgo/go/math/logb.go
+++ b/libgo/go/math/logb.go
@@ -4,7 +4,7 @@
package math
-// Logb(x) returns the binary exponent of non-zero x.
+// Logb(x) returns the binary exponent of x.
//
// Special cases are:
// Logb(±Inf) = +Inf
@@ -22,10 +22,10 @@ func Logb(x float64) float64 {
case x != x: // IsNaN(x):
return x
}
- return float64(int((Float64bits(x)>>shift)&mask) - (bias + 1))
+ return float64(ilogb(x))
}
-// Ilogb(x) returns the binary exponent of non-zero x as an integer.
+// Ilogb(x) returns the binary exponent of x as an integer.
//
// Special cases are:
// Ilogb(±Inf) = MaxInt32
@@ -43,5 +43,12 @@ func Ilogb(x float64) int {
case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
return MaxInt32
}
- return int((Float64bits(x)>>shift)&mask) - (bias + 1)
+ return ilogb(x)
+}
+
+// logb returns the binary exponent of x. It assumes x is finite and
+// non-zero.
+func ilogb(x float64) int {
+ x, exp := normalize(x)
+ return int((Float64bits(x)>>shift)&mask) - bias + exp
}