From 2c3946282818e97cb4f8552754ee8880a35062b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 2 Nov 2016 11:13:31 +0200 Subject: [PATCH] common/math: fix go vet issues on exp calculation --- common/math/exp.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/common/math/exp.go b/common/math/exp.go index 6301bc590a..ebb375be61 100644 --- a/common/math/exp.go +++ b/common/math/exp.go @@ -6,14 +6,8 @@ import ( "github.com/ethereum/go-ethereum/common" ) -const ( - // Perverted constants straight out of big.Int - // https://golang.org/src/math/big/arith.go - _m = ^big.Word(0) - _logS = _m>>8&1 + _m>>16&1 + _m>>32&1 - _S = 1 << _logS - _W = _S << 3 // word size in bits -) +// wordSize is the size number of bytes in a big.Int Word. +const wordSize = 32 << (uint64(^big.Word(0))>>63) // Exp implement exponentiation by squaring algorithm. // @@ -22,7 +16,7 @@ func Exp(base, exponent *big.Int) *big.Int { result := big.NewInt(1) for _, word := range exponent.Bits() { - for i := 0; i < _W; i++ { + for i := 0; i < wordSize; i++ { if word&1 == 1 { common.U256(result.Mul(result, base)) }