mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Update ceil and floor function (#3710)
* Update ceil and floor function * add end line * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
1b5c1b8344
commit
81b82bea47
@ -340,6 +340,8 @@
|
|||||||
* [Astar](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/astar.py)
|
* [Astar](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/astar.py)
|
||||||
* [Data Transformations](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/data_transformations.py)
|
* [Data Transformations](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/data_transformations.py)
|
||||||
* [Decision Tree](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/decision_tree.py)
|
* [Decision Tree](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/decision_tree.py)
|
||||||
|
* Forecasting
|
||||||
|
* [Run](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/forecasting/run.py)
|
||||||
* [Gaussian Naive Bayes](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gaussian_naive_bayes.py)
|
* [Gaussian Naive Bayes](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gaussian_naive_bayes.py)
|
||||||
* [Gradient Boosting Regressor](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gradient_boosting_regressor.py)
|
* [Gradient Boosting Regressor](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gradient_boosting_regressor.py)
|
||||||
* [Gradient Descent](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gradient_descent.py)
|
* [Gradient Descent](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/gradient_descent.py)
|
||||||
@ -630,6 +632,8 @@
|
|||||||
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_036/sol1.py)
|
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_036/sol1.py)
|
||||||
* Problem 037
|
* Problem 037
|
||||||
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_037/sol1.py)
|
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_037/sol1.py)
|
||||||
|
* Problem 038
|
||||||
|
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_038/sol1.py)
|
||||||
* Problem 039
|
* Problem 039
|
||||||
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_039/sol1.py)
|
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_039/sol1.py)
|
||||||
* Problem 040
|
* Problem 040
|
||||||
@ -716,7 +720,6 @@
|
|||||||
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_234/sol1.py)
|
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_234/sol1.py)
|
||||||
* Problem 551
|
* Problem 551
|
||||||
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_551/sol1.py)
|
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_551/sol1.py)
|
||||||
* [Validate Solutions](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py)
|
|
||||||
|
|
||||||
## Quantum
|
## Quantum
|
||||||
* [Deutsch Jozsa](https://github.com/TheAlgorithms/Python/blob/master/quantum/deutsch_jozsa.py)
|
* [Deutsch Jozsa](https://github.com/TheAlgorithms/Python/blob/master/quantum/deutsch_jozsa.py)
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
"""
|
||||||
|
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def ceil(x) -> int:
|
def ceil(x) -> int:
|
||||||
"""
|
"""
|
||||||
Return the ceiling of x as an Integral.
|
Return the ceiling of x as an Integral.
|
||||||
@ -10,9 +15,7 @@ def ceil(x) -> int:
|
|||||||
... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
|
... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
return (
|
return int(x) if x - int(x) <= 0 else int(x) + 1
|
||||||
x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
|
"""
|
||||||
|
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def floor(x) -> int:
|
def floor(x) -> int:
|
||||||
"""
|
"""
|
||||||
Return the floor of x as an Integral.
|
Return the floor of x as an Integral.
|
||||||
|
|
||||||
:param x: the number
|
:param x: the number
|
||||||
:return: the largest integer <= x.
|
:return: the largest integer <= x.
|
||||||
|
|
||||||
>>> import math
|
>>> import math
|
||||||
>>> all(floor(n) == math.floor(n) for n
|
>>> 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))
|
... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
return (
|
return int(x) if x - int(x) >= 0 else int(x) - 1
|
||||||
x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user