Skip to content

Instantly share code, notes, and snippets.

@rubik
Created December 7, 2011 16:22
Show Gist options
  • Save rubik/1443427 to your computer and use it in GitHub Desktop.
Save rubik/1443427 to your computer and use it in GitHub Desktop.
Floor and ceil function without computing division
def floor(x, y):
return (x - x % y) / float(y)
def ceil(x, y):
return floor(x - 1, y) + 1
def integer_part(x, y):
if x * y >= 0:
return floor(x, y)
return ceil(x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment