mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
math/big: replace local versions of bitLen, nlz with math/bits versions
Verified that BenchmarkBitLen time went down from 2.25 ns/op to 0.65 ns/op an a 2.3 GHz Intel Core i7, before removing that benchmark (now covered by math/bits benchmarks). Change-Id: I3890bb7d1889e95b9a94bd68f0bdf06f1885adeb Reviewed-on: https://go-review.googlesource.com/38464 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
536a2257fb
commit
70ea0ec30f
17 changed files with 17 additions and 141 deletions
|
|
@ -14,6 +14,7 @@ package big
|
|||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/bits"
|
||||
)
|
||||
|
||||
const debugFloat = false // enable for debugging
|
||||
|
|
@ -498,8 +499,8 @@ func (z *Float) setBits64(neg bool, x uint64) *Float {
|
|||
}
|
||||
// x != 0
|
||||
z.form = finite
|
||||
s := nlz64(x)
|
||||
z.mant = z.mant.setUint64(x << s)
|
||||
s := bits.LeadingZeros64(x)
|
||||
z.mant = z.mant.setUint64(x << uint(s))
|
||||
z.exp = int32(64 - s) // always fits
|
||||
if z.prec < 64 {
|
||||
z.round(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue