-
Notifications
You must be signed in to change notification settings - Fork 77
Open
Description
When chaining multiple operations, it is necessary to use a seperate declaration in order to pass the variable to the second and following operation:
x := new(uint256.Int)
x.Mul(a, b).Div(x, c).AddUint64(x, 1)
This could by simplified by adding "in-place" variants of all operations that use the receiver as the first argument, f.i.:
func (z *Int) IDiv(b *Int) *Int {
return z.Div(z, b)
}
resulting in:
x := new(uint256.Int).Mul(a, b).IDiv(c).IAddUint64(1)
Especially when having multiple of these chained operations, this improves readability by providing a uniform picture and makes it easier to avoid mixing up arguments:
x := new(uint256.Int)
x.Mul(a, b).Div(x, c).AddUint64(x, 1)
y := new(uint256.Int)
y.Div(b, a).Mul(y, c).SubUint64(y, 1)
z := new(uint256.Int)
z.Add(a, b).Div(z, c)
vs.
x := new(uint256.Int).Mul(a, b).IDiv(c).IAddUint64(1)
y := new(uint256.Int).Div(b, a).IMul(c).ISubUint64(1)
z := new(uint256.Int).Add(a, b).IDiv(c)
Are there any objections to such an API extension? Otherwise I'll cook up a patch.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels