Created
February 2, 2018 16:13
-
-
Save Sciss/3139e5c0008dfc75f60846bc069e86d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def modUp[A](a: A, b: A)(implicit num: Integral[A]): A = { | |
import num._ | |
val am = a - one | |
val z = if (gteq(am, zero)) am % b else { | |
val c = -am % b | |
if (c == zero) zero else b - c | |
} | |
z + one | |
} | |
Seq.tabulate(10)(i => modUp(i, 4)) // List(4, 1, 2, 3, 4, 1, 2, 3, 4, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment