MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / floor

Function floor

maths/floor.py:6–16  ·  view source on GitHub ↗

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

(x: float)

Source from the content-addressed store, hash-verified

4
5
6def floor(x: float) -> int:
7 """
8 Return the floor of x as an Integral.
9 :param x: the number
10 :return: the largest integer <= x.
11 >>> import math
12 >>> all(floor(n) == math.floor(n) for n
13 ... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
14 True
15 """
16 return int(x) if x - int(x) >= 0 else int(x) - 1
17
18
19if __name__ == "__main__":

Callers 5

continued_fractionFunction · 0.90
fill_graph_randomlyMethod · 0.90
fill_graph_randomlyMethod · 0.90
solutionFunction · 0.90
solutionFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected