aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/big.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-27 23:15:44 +0800
committerobscuren <geffobscura@gmail.com>2014-04-27 23:16:53 +0800
commit338b6980915c990c6e6287a7249ddd98e6be20eb (patch)
treed5c33a03c473dab1de0daade37a2d12986084faa /ethutil/big.go
parent16e52327a4baa5547c38965fce53b3ff40b98173 (diff)
downloadgo-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.gz
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.bz2
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.lz
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.xz
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.tar.zst
go-tangerine-338b6980915c990c6e6287a7249ddd98e6be20eb.zip
Refactoring and added documentation comments
Diffstat (limited to 'ethutil/big.go')
-rw-r--r--ethutil/big.go31
1 files changed, 21 insertions, 10 deletions
diff --git a/ethutil/big.go b/ethutil/big.go
index c0488a71f..891d476ad 100644
--- a/ethutil/big.go
+++ b/ethutil/big.go
@@ -12,7 +12,9 @@ var BigTrue *big.Int = big.NewInt(1)
// False
var BigFalse *big.Int = big.NewInt(0)
-// Returns the power of two integers
+// Big pow
+//
+// Returns the power of two big integers
func BigPow(a, b int) *big.Int {
c := new(big.Int)
c.Exp(big.NewInt(int64(a)), big.NewInt(int64(b)), big.NewInt(0))
@@ -20,7 +22,9 @@ func BigPow(a, b int) *big.Int {
return c
}
-// Like big.NewInt(uint64); this takes a string instead.
+// Big
+//
+// Shortcut for new(big.Int).SetString(..., 0)
func Big(num string) *big.Int {
n := new(big.Int)
n.SetString(num, 0)
@@ -28,7 +32,9 @@ func Big(num string) *big.Int {
return n
}
-// Like big.NewInt(uint64); this takes a byte buffer instead.
+// BigD
+//
+// Shortcut for new(big.Int).SetBytes(...)
func BigD(data []byte) *big.Int {
n := new(big.Int)
n.SetBytes(data)
@@ -36,21 +42,26 @@ func BigD(data []byte) *big.Int {
return n
}
+// Big to bytes
+//
+// Returns the bytes of a big integer with the size specified by **base**
+// Attempts to pad the byte array with zeros.
func BigToBytes(num *big.Int, base int) []byte {
ret := make([]byte, base/8)
return append(ret[:len(ret)-len(num.Bytes())], num.Bytes()...)
}
-// Functions like the build in "copy" function
-// but works on big integers
-func BigCopy(src *big.Int) (ret *big.Int) {
- ret = new(big.Int)
- ret.Add(ret, src)
-
- return
+// Big copy
+//
+// Creates a copy of the given big integer
+func BigCopy(src *big.Int) *big.Int {
+ return new(big.Int).Set(src)
}
+// Big max
+//
+// Returns the maximum size big integer
func BigMax(x, y *big.Int) *big.Int {
if x.Cmp(y) <= 0 {
return x