Created
December 7, 2011 16:22
-
-
Save rubik/1443427 to your computer and use it in GitHub Desktop.
Floor and ceil function without computing division
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
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