Skip to content

Add signum function #7526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update signum.py
  • Loading branch information
cclauss authored Oct 23, 2022
commit 3001f6a7138e413425bafcbf34900dcf52add214
9 changes: 4 additions & 5 deletions maths/signum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Signum function"""
"""
Signum function -- https://en.wikipedia.org/wiki/Sign_function
"""


def signum(num: float) -> int:
Expand All @@ -14,10 +16,7 @@ def signum(num: float) -> int:
"""
if num < 0:
return -1
elif num > 0:
return 1
else:
return 0
return 1 if num else 0


def test_signum() -> None:
Expand Down