Skip to content

Instantly share code, notes, and snippets.

@mominul
Created January 30, 2016 17:21
Show Gist options
  • Select an option

  • Save mominul/f1d747b5d96b8c935e1d to your computer and use it in GitHub Desktop.

Select an option

Save mominul/f1d747b5d96b8c935e1d to your computer and use it in GitHub Desktop.
Swift: Get remainder in a Integer
// Calculates remainder in a integer
// It's work like the '%' operator in swift
// Currently integer values are supported
// Public Domain ;)
// By Muhammad Mominul Huque
func getRemainder(var realNum: Int, goesTo: Int) ->Int {
while(realNum > goesTo) {
realNum -= goesTo
}
return realNum
}
var rel1 = getRemainder(9, goesTo: 4)
var rel2 = 9 % 4
print("\(rel1) is equal to \(rel2)")
assert(rel1 == rel2)
/* It's my first program in swift! */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment