-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b711ee6
commit d48461a
Showing
2 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
def check_isinstance(x, instance: type): | ||
if not isinstance(x, instance): | ||
raise TypeError(f"{type(x).__name__} is not a {instance.__name__}.") | ||
|
||
|
||
def rint(x: float) -> int: | ||
""" Rounds to the nearest int and returns the value as int. | ||
""" | ||
return int(round(x)) | ||
|
||
|
||
def clip(x: int, min_x: int, max_x: int) -> int: | ||
""" Clips x to [min, max] interval. | ||
""" | ||
if x < min_x: | ||
return min_x | ||
if x > max_x: | ||
return max_x | ||
return x |