2.161703872847352815363655e+00,
}
var logb = []float64{
- 3.0000000000000000e+00,
- 3.0000000000000000e+00,
- -1.0000000000000000e+00,
- 3.0000000000000000e+00,
- 4.0000000000000000e+00,
+ 2.0000000000000000e+00,
+ 2.0000000000000000e+00,
+ -2.0000000000000000e+00,
2.0000000000000000e+00,
3.0000000000000000e+00,
+ 1.0000000000000000e+00,
2.0000000000000000e+00,
1.0000000000000000e+00,
- 4.0000000000000000e+00,
+ 0.0000000000000000e+00,
+ 3.0000000000000000e+00,
}
var log10 = []float64{
6.9714316642508290997617083e-01,
func TestIlogb(t *testing.T) {
for i := 0; i < len(vf); i++ {
- if e := Ilogb(vf[i]); frexp[i].i != e {
- t.Errorf("Ilogb(%g) = %d, want %d", vf[i], e, frexp[i].i)
+ a := frexp[i].i - 1 // adjust because fr in the interval [½, 1)
+ if e := Ilogb(vf[i]); a != e {
+ t.Errorf("Ilogb(%g) = %d, want %d", vf[i], e, a)
}
}
for i := 0; i < len(vflogbSC); i++ {
package math
-// Logb(x) returns the binary logarithm of non-zero x.
+// Logb(x) returns the binary exponent of non-zero x.
//
// Special cases are:
// Logb(±Inf) = +Inf
case x != x: // IsNaN(x):
return x
}
- return float64(int((Float64bits(x)>>shift)&mask) - bias)
+ return float64(int((Float64bits(x)>>shift)&mask) - (bias + 1))
}
-// Ilogb(x) returns the binary logarithm of non-zero x as an integer.
+// Ilogb(x) returns the binary exponent of non-zero x as an integer.
//
// Special cases are:
// Ilogb(±Inf) = MaxInt32
case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
return MaxInt32
}
- return int((Float64bits(x)>>shift)&mask) - bias
+ return int((Float64bits(x)>>shift)&mask) - (bias + 1)
}