Python/maths/ceil.py
Christian Clauss 9316e7c014
Set the Python file maximum line length to 88 characters (#2122)
* flake8 --max-line-length=88

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-16 10:09:19 +02:00

22 lines
464 B
Python

def ceil(x) -> int:
"""
Return the ceiling of x as an Integral.
:param x: the number
:return: the smallest integer >= x.
>>> import math
>>> all(ceil(n) == math.ceil(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 + 1) if x > 0 else int(x)
)
if __name__ == "__main__":
import doctest
doctest.testmod()