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