mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
9316e7c014
* flake8 --max-line-length=88 * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
22 lines
464 B
Python
22 lines
464 B
Python
def floor(x) -> 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
|
|
"""
|
|
return (
|
|
x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import doctest
|
|
|
|
doctest.testmod()
|