Last active
October 9, 2015 18:35
-
-
Save caelifer/aa0901ca5df5b0a1a536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from https://github.com/mdempsky/maligned/blob/master/maligned.go#L227. | |
// Corrected for the negative x. | |
// align returns the smallest y >= x such that y % a == 0. | |
func align(x, a int64) int64 { | |
sign := int64(1) | |
if x < 0 { | |
x = -x | |
sign = -1 | |
} | |
if a < 0 { | |
a = -a // align size is always positive | |
} | |
y := x + a - 1 | |
return sign * (y - y%a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working code - http://play.golang.org/p/WtFXA4CI-b