Skip to content

Use Math.multiplyExact for safe multiplication in pow method - #7755

Open
dlucas489 wants to merge 1 commit into
TheAlgorithms:masterfrom
dlucas489:dlucas489/fix-pow-overflow-err
Open

dlucas489 wants to merge 1 commit into
TheAlgorithms:masterfrom
dlucas489:dlucas489/fix-pow-overflow-err

Conversation

@dlucas489

Copy link
Copy Markdown

Overview


Silent overflow in Pow.pow fixed. Prior to this, Pow.pow(2, 63) returned Long.MIN_VALUE, and Pow.pow(2, 64) returned 0.

The updated method uses Math.multiplyExact to throw ArithmeticException when the result is exceeded by the long range.

Related issue: #7751

This PR is for a CS440 assignment and targets my own fork.

The full test suite is passing with mvn test. CONTRIBUTING.md was followed, variables follow Java naming conventions and code is formatted using clang-format.

Replaced multiplication with Math.multiplyExact for overflow checks.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.40%. Comparing base (2f04e81) to head (2b5653b).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7755   +/-   ##
=========================================
  Coverage     82.40%   82.40%           
- Complexity     8476     8477    +1     
=========================================
  Files           845      845           
  Lines         26225    26225           
  Branches       5122     5122           
=========================================
  Hits          21610    21610           
  Misses         3828     3828           
  Partials        787      787           

☔ View full report in Codecov by Harness.
📢 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.

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.

2 participants