diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-15 23:12:26 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-15 23:12:26 +0800 |
commit | 311c6f8a3fed5ac03ee4b442fd0f420072bc41b4 (patch) | |
tree | de823080f3704d7690fd7172c9742962b66baf3a /ethutil | |
parent | 266d21209478bdb8c89e1ffb95d7f0de34635968 (diff) | |
download | dexon-311c6f8a3fed5ac03ee4b442fd0f420072bc41b4.tar.gz dexon-311c6f8a3fed5ac03ee4b442fd0f420072bc41b4.tar.zst dexon-311c6f8a3fed5ac03ee4b442fd0f420072bc41b4.zip |
Fixed remote Arithmetic tests
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/big.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/ethutil/big.go b/ethutil/big.go index e23d8f659..bdcf86421 100644 --- a/ethutil/big.go +++ b/ethutil/big.go @@ -1,8 +1,8 @@ package ethutil -import ( - "math/big" -) +import "math/big" + +var MaxInt256 *big.Int = BigD(Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) // Big pow // @@ -37,18 +37,29 @@ func BigD(data []byte) *big.Int { // To256 // // "cast" the big int to a 256 big int (i.e., limit to) -var tt256 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(1)) +var tt256 = new(big.Int).Lsh(big.NewInt(1), 256) +var tt256m1 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(1)) +var tt255 = new(big.Int).Lsh(big.NewInt(1), 255) -func To256(x *big.Int) *big.Int { - x.And(x, tt256) +func U256(x *big.Int) *big.Int { + //if x.Cmp(Big0) < 0 { + // return new(big.Int).Add(tt256, x) + // } - if x.Cmp(new(big.Int)) < 0 { - x.SetInt64(0) - } + x.And(x, tt256m1) return x } +func S256(x *big.Int) *big.Int { + if x.Cmp(tt255) < 0 { + return x + } else { + // We don't want to modify x, ever + return new(big.Int).Sub(x, tt256) + } +} + // Big to bytes // // Returns the bytes of a big integer with the size specified by **base** |