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

Does not handle negative integers! #5

Open
dhrp opened this issue Aug 1, 2019 · 1 comment
Open

Does not handle negative integers! #5

dhrp opened this issue Aug 1, 2019 · 1 comment

Comments

@dhrp
Copy link

dhrp commented Aug 1, 2019

While the library claims to deal with int64 and *big.Int, what is not written is that it does not deal well with negative numbers.

e.g. try:

hash := base62.EncodeInt64(-8357271895528378933)
""
@dhrp
Copy link
Author

dhrp commented Aug 1, 2019

Ok, actually, after my surprise that this doesn't work, it actually makes sense that it would not work, as Base62 (or baseXX)-encoding would not be able to represent a negative number anyway..

I've solved my problem by inlining this function:

	makeAbs := func(n int64) int64 {
		if n < 0 {
			return -n
		}
		return n
	}

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

No branches or pull requests

1 participant