Skip to content
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

Make math.Add64 and math.Mul64 generic #3205

Merged
merged 4 commits into from
Jul 19, 2024
Merged

Conversation

StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Jul 19, 2024

Why this should be merged

Resolves the asymmetry between math.Sub and math.Add64/math.Mul64.

How this works

^uint(0) == maxUint

How this was tested

  • Added test of wrap-around behavior for all unsigned int types.
  • CI

@StephenButtolph StephenButtolph added the cleanup Code quality improvement label Jul 19, 2024
@StephenButtolph StephenButtolph added this to the v1.11.10 milestone Jul 19, 2024
@StephenButtolph StephenButtolph self-assigned this Jul 19, 2024
Comment on lines +18 to +22
// Deprecated: Add64 is deprecated. Use Add[uint64] instead.
Add64 = Add[uint64]

// Deprecated: Mul64 is deprecated. Use Mul[uint64] instead.
Mul64 = Mul[uint64]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are used by coreth. I was too lazy to make a PR to update the dependency with this. We should remove these once coreth has removed their usage.

require := require.New(t)

sum, err := Add64(0, maxUint64)
require.Equal(uint(math.MaxUint), MaxUint[uint]())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asserts throughout. And the bike shed should be purple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avalanchego uses require exclusively - not going to bring that convo into this PR haha

@StephenButtolph StephenButtolph added this pull request to the merge queue Jul 19, 2024
@StephenButtolph StephenButtolph removed this pull request from the merge queue due to a manual request Jul 19, 2024
@StephenButtolph StephenButtolph added this pull request to the merge queue Jul 19, 2024
Merged via the queue into master with commit 9a6418c Jul 19, 2024
20 checks passed
@StephenButtolph StephenButtolph deleted the generic-add-mul branch July 19, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants