Skip to content

Conversation

@AliAlimohammadi
Copy link
Contributor

Description

This PR adds an implementation to find the largest power of two less than or equal to a given number.

Type of change

  • New algorithm implementation

Changes

  • Added find_previous_power_of_two.rs with comprehensive documentation
  • Includes 10 test functions with multiple test cases
  • Uses efficient bit-shifting algorithm
  • Follows Rust best practices and TheAlgorithms conventions

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional context

The algorithm uses bit shifting for $O(log n)$ time complexity.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.68%. Comparing base (e5bceac) to head (a2225d0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #969      +/-   ##
==========================================
+ Coverage   95.67%   95.68%   +0.01%     
==========================================
  Files         342      343       +1     
  Lines       22330    22412      +82     
==========================================
+ Hits        21364    21445      +81     
- Misses        966      967       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AliAlimohammadi
Copy link
Contributor Author

@siriak, this is ready to be merged.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak merged commit ebc3767 into TheAlgorithms:master Dec 16, 2025
7 checks passed
@AliAlimohammadi AliAlimohammadi deleted the add-previous-power-of-two branch December 16, 2025 09:05
@siriak siriak mentioned this pull request Dec 16, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants