Skip to content

Commit 81b82be

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Update ceil and floor function (TheAlgorithms#3710)
* Update ceil and floor function * add end line * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 1b5c1b8 commit 81b82be

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

DIRECTORY.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@
340340
* [Astar](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/astar.py)
341341
* [Data Transformations](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/data_transformations.py)
342342
* [Decision Tree](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/decision_tree.py)
343+
* Forecasting
344+
* [Run](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/forecasting/run.py)
343345
* [Gaussian Naive Bayes](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gaussian_naive_bayes.py)
344346
* [Gradient Boosting Regressor](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gradient_boosting_regressor.py)
345347
* [Gradient Descent](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gradient_descent.py)
@@ -630,6 +632,8 @@
630632
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_036/sol1.py)
631633
* Problem 037
632634
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_037/sol1.py)
635+
* Problem 038
636+
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_038/sol1.py)
633637
* Problem 039
634638
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_039/sol1.py)
635639
* Problem 040
@@ -716,7 +720,6 @@
716720
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_234/sol1.py)
717721
* Problem 551
718722
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_551/sol1.py)
719-
* [Validate Solutions](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py)
720723

721724
## Quantum
722725
* [Deutsch Jozsa](https://github.com/TheAlgorithms/Python/blob/master/quantum/deutsch_jozsa.py)

maths/ceil.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
3+
"""
4+
5+
16
def ceil(x) -> int:
27
"""
38
Return the ceiling of x as an Integral.
@@ -10,9 +15,7 @@ def ceil(x) -> int:
1015
... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
1116
True
1217
"""
13-
return (
14-
x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
15-
)
18+
return int(x) if x - int(x) <= 0 else int(x) + 1
1619

1720

1821
if __name__ == "__main__":

maths/floor.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
"""
2+
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
3+
"""
4+
5+
16
def floor(x) -> int:
27
"""
38
Return the floor of x as an Integral.
4-
59
:param x: the number
610
:return: the largest integer <= x.
7-
811
>>> import math
912
>>> all(floor(n) == math.floor(n) for n
1013
... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
1114
True
1215
"""
13-
return (
14-
x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
15-
)
16+
return int(x) if x - int(x) >= 0 else int(x) - 1
1617

1718

1819
if __name__ == "__main__":

0 commit comments

Comments
 (0)