forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceil.py
24 lines (17 loc) · 485 Bytes
/
ceil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
"""
defceil(x: float) ->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
"""
returnint(x) ifx-int(x) <=0elseint(x) +1
if__name__=="__main__":
importdoctest
doctest.testmod()