aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/util/modulo.go
blob: ec2957ad2a3776f70ed160e8f593eb13998f2a2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
package util

// PostitiveMod returns a modulo operator like JavaScripts
func PositiveMod(x, d int) int {
	x = x % d
	if x >= 0 {
		return x
	}
	if d < 0 {
		return x - d
	}
	return x + d
}