-
Notifications
You must be signed in to change notification settings - Fork 7
perf(int256): Optimize int256 Pacakge
#1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…out decimal parsing
…ion and related tests - Remove panic on zero amount to allow valid handling - Update test case to reflect new behavior, ensuring zero amount does not panic and validates the result correctly
jinoosss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a structural issue with Int256 package operations.
When overflow occurs, the value is set to the minimum or maximum value of uint256, not the minimum or maximum value of int256.
As this is a structural issue, thorough discussion will likely be necessary.
func (z *Int) Add(x, y *Int) *Int {
z = z.initiateAbs()
if x.neg == y.neg {
// If both numbers have the same sign, add their absolute values
z.abs.Add(x.abs, y.abs)
z.neg = x.neg
} else {
// If signs are different, subtract the smaller absolute value from the larger
if x.abs.Cmp(y.abs) >= 0 {
z.abs.Sub(x.abs, y.abs)
z.neg = x.neg
} else {
z.abs.Sub(y.abs, x.abs)
z.neg = y.neg
}
}
// Ensure zero is always positive
if z.abs.IsZero() {
z.neg = false
}
return z
}
|
|
replaced by #1021 |



Summary
This PR optimizes the
int256package by removing unused functions and improving initialization performance.Changes
MaxInt256andMinInt256initialization using direct word arrays instead of decimal parsingSetInt64calls when creating newInt256arraysRemoved Functions
The following functions were removed as they are not used in any contract:
AddUint256,SubUint256,MulUint256,DivUint256AddDelta,AddDeltaOverflowQuo,Rem,ModAnd(bitwise operation)Neq,Lte,Gte(comparison operations)SetUint64,SetUint256NegOverflow,AbsGt,AbsLt,AbsOverflow