-
Notifications
You must be signed in to change notification settings - Fork 56
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
Conversation
switch d.(type) { | ||
case uint64: | ||
return d.(uint64) + 1 | ||
case int64: | ||
return d.(int64) + 1 | ||
} |
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.
Just noting that type assertion switch cases can do the conversion for you:
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 | |
} |
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.
Very true, my mind blanked when I was writing it this morning. I'll probably lump that change in when I bump dependencies
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.
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.
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.
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!
Add support for negative values (also fix max uint64 value offset).
Fixes #104