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

support negative values #107

Merged
merged 3 commits into from
Jun 8, 2022
Merged

support negative values #107

merged 3 commits into from
Jun 8, 2022

Conversation

abice
Copy link
Owner

@abice abice commented Jun 8, 2022

Add support for negative values (also fix max uint64 value offset).

Fixes #104

@abice abice merged commit 8268238 into master Jun 8, 2022
@abice abice deleted the abice/negativeValues branch June 8, 2022 15:43
@coveralls
Copy link

coveralls commented Jun 8, 2022

Coverage Status

Coverage decreased (-5.05%) to 88.267% when pulling 3750fe1 on abice/negativeValues into b8f9fa6 on master.

Comment on lines +418 to +423
switch d.(type) {
case uint64:
return d.(uint64) + 1
case int64:
return d.(int64) + 1
}
Copy link
Contributor

@dsonck92 dsonck92 Jun 8, 2022

Choose a reason for hiding this comment

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

Just noting that type assertion switch cases can do the conversion for you:

Suggested change
switch d.(type) {
case uint64:
return d.(uint64) + 1
case int64:
return d.(int64) + 1
}
switch v := d.(type) {
case uint64:
return v + 1
case int64:
return v + 1
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

Very true, my mind blanked when I was writing it this morning. I'll probably lump that change in when I bump dependencies

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, well, I do like the elegant solution, making sure the signedness of the underlying type get used internally so any hardcoded values will have to match.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah, had about 3 or 4 iterations before I landed on this one. Definitely felt like the right level of safety and flexibility. Thanks for double checking my work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negative enum values not supported
3 participants