aboutsummaryrefslogtreecommitdiffstats
path: root/common/number/int.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/number/int.go')
-rw-r--r--common/number/int.go43
1 files changed, 21 insertions, 22 deletions
diff --git a/common/number/int.go b/common/number/int.go
index 6dab2436d..5b5066970 100644
--- a/common/number/int.go
+++ b/common/number/int.go
@@ -34,13 +34,12 @@ func limitUnsigned256(x *Number) *Number {
func limitSigned256(x *Number) *Number {
if x.num.Cmp(tt255) < 0 {
return x
- } else {
- x.num.Sub(x.num, tt256)
- return x
}
+ x.num.Sub(x.num, tt256)
+ return x
}
-// Number function
+// Initialiser is a Number function
type Initialiser func(n int64) *Number
// A Number represents a generic integer with a bounding function limiter. Limit is called after each operations
@@ -51,65 +50,65 @@ type Number struct {
limit func(n *Number) *Number
}
-// Returns a new initialiser for a new *Number without having to expose certain fields
+// NewInitialiser returns a new initialiser for a new *Number without having to expose certain fields
func NewInitialiser(limiter func(*Number) *Number) Initialiser {
return func(n int64) *Number {
return &Number{big.NewInt(n), limiter}
}
}
-// Return a Number with a UNSIGNED limiter up to 256 bits
+// Uint256 returns a Number with a UNSIGNED limiter up to 256 bits
func Uint256(n int64) *Number {
return &Number{big.NewInt(n), limitUnsigned256}
}
-// Return a Number with a SIGNED limiter up to 256 bits
+// Int256 returns Number with a SIGNED limiter up to 256 bits
func Int256(n int64) *Number {
return &Number{big.NewInt(n), limitSigned256}
}
-// Returns a Number with a SIGNED unlimited size
+// Big returns a Number with a SIGNED unlimited size
func Big(n int64) *Number {
return &Number{big.NewInt(n), func(x *Number) *Number { return x }}
}
-// Sets i to sum of x+y
+// Add sets i to sum of x+y
func (i *Number) Add(x, y *Number) *Number {
i.num.Add(x.num, y.num)
return i.limit(i)
}
-// Sets i to difference of x-y
+// Sub sets i to difference of x-y
func (i *Number) Sub(x, y *Number) *Number {
i.num.Sub(x.num, y.num)
return i.limit(i)
}
-// Sets i to product of x*y
+// Mul sets i to product of x*y
func (i *Number) Mul(x, y *Number) *Number {
i.num.Mul(x.num, y.num)
return i.limit(i)
}
-// Sets i to the quotient prodject of x/y
+// Div sets i to the quotient prodject of x/y
func (i *Number) Div(x, y *Number) *Number {
i.num.Div(x.num, y.num)
return i.limit(i)
}
-// Sets i to x % y
+// Mod sets i to x % y
func (i *Number) Mod(x, y *Number) *Number {
i.num.Mod(x.num, y.num)
return i.limit(i)
}
-// Sets i to x << s
+// Lsh sets i to x << s
func (i *Number) Lsh(x *Number, s uint) *Number {
i.num.Lsh(x.num, s)
return i.limit(i)
}
-// Sets i to x^y
+// Pow sets i to x^y
func (i *Number) Pow(x, y *Number) *Number {
i.num.Exp(x.num, y.num, big.NewInt(0))
return i.limit(i)
@@ -117,13 +116,13 @@ func (i *Number) Pow(x, y *Number) *Number {
// Setters
-// Set x to i
+// Set sets x to i
func (i *Number) Set(x *Number) *Number {
i.num.Set(x.num)
return i.limit(i)
}
-// Set x bytes to i
+// SetBytes sets x bytes to i
func (i *Number) SetBytes(x []byte) *Number {
i.num.SetBytes(x)
return i.limit(i)
@@ -140,12 +139,12 @@ func (i *Number) Cmp(x *Number) int {
// Getters
-// Returns the string representation of i
+// String returns the string representation of i
func (i *Number) String() string {
return i.num.String()
}
-// Returns the byte representation of i
+// Bytes returns the byte representation of i
func (i *Number) Bytes() []byte {
return i.num.Bytes()
}
@@ -160,17 +159,17 @@ func (i *Number) Int64() int64 {
return i.num.Int64()
}
-// Returns the signed version of i
+// Int256 returns the signed version of i
func (i *Number) Int256() *Number {
return Int(0).Set(i)
}
-// Returns the unsigned version of i
+// Uint256 returns the unsigned version of i
func (i *Number) Uint256() *Number {
return Uint(0).Set(i)
}
-// Returns the index of the first bit that's set to 1
+// FirstBitSet returns the index of the first bit that's set to 1
func (i *Number) FirstBitSet() int {
for j := 0; j < i.num.BitLen(); j++ {
if i.num.Bit(j) > 0 {