1 parent 0e3357a commit 8c443ccCopy full SHA for 8c443cc
2 files changed
maths/ceil.py
@@ -0,0 +1,18 @@
1
+def ceil(x) -> int:
2
+ """
3
+ Return the ceiling of x as an Integral.
4
+
5
+ :param x: the number
6
+ :return: the smallest integer >= x.
7
8
+ >>> import math
9
+ >>> 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))
10
+ True
11
12
+ return x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
13
14
15
+if __name__ == '__main__':
16
+ import doctest
17
18
+ doctest.testmod()
maths/floor.py
+def floor(x) -> int:
+ Return the floor of x as an Integral.
+ :return: the largest integer <= x.
+ >>> 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))
+ return x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
0 commit comments