Skip to content

Fixes #9347 #9706

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

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Fixes #9347
Name : Sharnabh Banerjee

"""


def add_largest(num: int) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename the file to be less wordy.
This function doesn't accomplish what the issue is referencing.

"""
Add Largest Power of 2 less then or equal to a given number
>>> add_largest(5.3)
Traceback (most recent call last):
...
TypeError: num must be an integer !!
>>> add_largest(5)
9
>>> add_largest(10)
18
>>> add_largest(99)
163
>>> add_largest(-10)
0
>>> add_largest(999)
1511

"""

# Checks if Float or not
if isinstance(num, float):
raise TypeError("num must be an integer !!")
# Checks if negative or Zero
if num <= 0:
return 0
res = 1
# Left Bit Shift till it res is less than or equal to the given number
while (res << 1) <= num:
res <<= 1
return res + num


if __name__ == "__main__":
import doctest

doctest.testmod()