You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
When chaining multiple operations, it is necessary to use a seperate declaration in order to pass the variable to the second and following operation:
This could by simplified by adding "in-place" variants of all operations that use the receiver as the first argument, f.i.:
resulting in:
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:
vs.
Are there any objections to such an API extension? Otherwise I'll cook up a patch.
The text was updated successfully, but these errors were encountered: