| // Copyright 2010 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // Logb(x) returns the binary logarithm of non-zero x. |
| func Logb(x float64) float64 { |
| // TODO(rsc): Remove manual inlining of IsNaN, IsInf |
| // when compiler does it for us |
| case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0): |
| case x != x: // IsNaN(x): |
| return float64(int((Float64bits(x)>>shift)&mask) - bias) |
| // Ilogb(x) returns the binary logarithm of non-zero x as an integer. |
| // Ilogb(±Inf) = MaxInt32 |
| func Ilogb(x float64) int { |
| // TODO(rsc): Remove manual inlining of IsNaN, IsInf |
| // when compiler does it for us |
| case x != x: // IsNaN(x): |
| case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0): |
| return int((Float64bits(x)>>shift)&mask) - bias |