ceil.py 464 字节
Newer Older
ishellhub's avatar
ishellhub 已提交
1 2 3 4 5 6 7 8
def ceil(x) -> int:
    """
    Return the ceiling of x as an Integral.

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

    >>> import math
9 10
    >>> 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 已提交
11 12
    True
    """
13 14 15
    return (
        x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
    )
ishellhub's avatar
ishellhub 已提交
16 17


18
if __name__ == "__main__":
ishellhub's avatar
ishellhub 已提交
19 20 21
    import doctest

    doctest.testmod()