Update ceil and floor function (#3710)

* Update ceil and floor function

* add end line

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Du Yuanchao
2020-10-26 00:02:24 +08:00
committed by GitHub
parent 1b5c1b8344
commit 81b82bea47
3 changed files with 16 additions and 9 deletions

View File

@ -1,18 +1,19 @@
"""
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
"""
def floor(x) -> int:
"""
Return the floor of x as an Integral.
:param x: the number
:return: the largest integer <= x.
>>> import math
>>> all(floor(n) == math.floor(n) for n
... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
True
"""
return (
x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
)
return int(x) if x - int(x) >= 0 else int(x) - 1
if __name__ == "__main__":