2020-10-25 16:02:24 +00:00
|
|
|
"""
|
|
|
|
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2022-10-12 18:42:30 +00:00
|
|
|
def floor(x: float) -> int:
|
2019-11-04 07:28:51 +00:00
|
|
|
"""
|
|
|
|
Return the floor of x as an Integral.
|
|
|
|
:param x: the number
|
|
|
|
:return: the largest integer <= x.
|
|
|
|
>>> import math
|
2020-06-16 08:09:19 +00:00
|
|
|
>>> 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))
|
2019-11-04 07:28:51 +00:00
|
|
|
True
|
|
|
|
"""
|
2020-10-25 16:02:24 +00:00
|
|
|
return int(x) if x - int(x) >= 0 else int(x) - 1
|
2019-11-04 07:28:51 +00:00
|
|
|
|
|
|
|
|
2019-11-14 18:59:43 +00:00
|
|
|
if __name__ == "__main__":
|
2019-11-04 07:28:51 +00:00
|
|
|
import doctest
|
|
|
|
|
|
|
|
doctest.testmod()
|