base62 icon indicating copy to clipboard operation
base62 copied to clipboard

Does not handle negative integers!

Open dhrp opened this issue 6 years ago • 1 comments

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 avatar Aug 01 '19 16:08 dhrp

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
	}

dhrp avatar Aug 01 '19 16:08 dhrp