ceil.py 478 字节
Newer Older
1 2 3 4 5
"""
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
"""


ishellhub's avatar
ishellhub 已提交
6 7 8 9 10 11 12 13
def ceil(x) -> int:
    """
    Return the ceiling of x as an Integral.

    :param x: the number
    :return: the smallest integer >= x.

    >>> import math
14 15
    >>> 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))
ishellhub's avatar
ishellhub 已提交
16 17
    True
    """
18
    return int(x) if x - int(x) <= 0 else int(x) + 1
ishellhub's avatar
ishellhub 已提交
19 20


21
if __name__ == "__main__":
ishellhub's avatar
ishellhub 已提交
22 23 24
    import doctest

    doctest.testmod()