diff options
| author | Russ Cox <rsc@golang.org> | 2015-01-16 14:33:27 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-01-19 15:26:45 +0000 |
| commit | 7ef59e4ed8c2bc4d79d1a40ece6e262677214ace (patch) | |
| tree | 888d4fa225bd2a867163969726ceee099dc42557 /src | |
| parent | e12b1ddc9908602c7307d27a40c5b11529db6200 (diff) | |
| download | go-7ef59e4ed8c2bc4d79d1a40ece6e262677214ace.tar.xz | |
runtime: rename float64 constants to avoid name space pollution
Otherwise, if you mistakenly refer to an undeclared 'shift' variable, you get 52.
Change-Id: I845fb29f23baee1d8e17b37bde0239872eb54316
Reviewed-on: https://go-review.googlesource.com/2909
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/sqrt.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/runtime/sqrt.go b/src/runtime/sqrt.go index e3a27014b5..d483f8a01f 100644 --- a/src/runtime/sqrt.go +++ b/src/runtime/sqrt.go @@ -86,10 +86,10 @@ import "unsafe" // Notes: Rounding mode detection omitted. const ( - mask = 0x7FF - shift = 64 - 11 - 1 - bias = 1023 - maxFloat64 = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52 + float64Mask = 0x7FF + float64Shift = 64 - 11 - 1 + float64Bias = 1023 + maxFloat64 = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52 ) func float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) } @@ -105,25 +105,25 @@ func sqrt(x float64) float64 { } ix := float64bits(x) // normalize x - exp := int((ix >> shift) & mask) + exp := int((ix >> float64Shift) & float64Mask) if exp == 0 { // subnormal x - for ix&1<<shift == 0 { + for ix&1<<float64Shift == 0 { ix <<= 1 exp-- } exp++ } - exp -= bias // unbias exponent - ix &^= mask << shift - ix |= 1 << shift + exp -= float64Bias // unbias exponent + ix &^= float64Mask << float64Shift + ix |= 1 << float64Shift if exp&1 == 1 { // odd exp, double x to make it even ix <<= 1 } exp >>= 1 // exp = exp/2, exponent of square root // generate sqrt(x) bit by bit ix <<= 1 - var q, s uint64 // q = sqrt(x) - r := uint64(1 << (shift + 1)) // r = moving bit from MSB to LSB + var q, s uint64 // q = sqrt(x) + r := uint64(1 << (float64Shift + 1)) // r = moving bit from MSB to LSB for r != 0 { t := s + r if t <= ix { @@ -138,6 +138,6 @@ func sqrt(x float64) float64 { if ix != 0 { // remainder, result not exact q += q & 1 // round according to extra bit } - ix = q>>1 + uint64(exp-1+bias)<<shift // significand + biased exponent + ix = q>>1 + uint64(exp-1+float64Bias)<<float64Shift // significand + biased exponent return float64frombits(ix) } |
