Title: [BUG] Pow.pow silently wraps when the result exceeds long range · Issue #7751 · TheAlgorithms/Java · GitHub
Open Graph Title: [BUG] Pow.pow silently wraps when the result exceeds long range · Issue #7751 · TheAlgorithms/Java
X Title: [BUG] Pow.pow silently wraps when the result exceeds long range · Issue #7751 · TheAlgorithms/Java
Description: Description com.thealgorithms.maths.Pow.pow(int a, int b) multiplies into a long without checking whether the result is representable. For example, Pow.pow(2, 63) mathematically equals 9223372036854775808, which is greater than Long.MAX_...
Open Graph Description: Description com.thealgorithms.maths.Pow.pow(int a, int b) multiplies into a long without checking whether the result is representable. For example, Pow.pow(2, 63) mathematically equals 922337203685...
X Description: Description com.thealgorithms.maths.Pow.pow(int a, int b) multiplies into a long without checking whether the result is representable. For example, Pow.pow(2, 63) mathematically equals 922337203685...
Opengraph URL: https://github.com/TheAlgorithms/Java/issues/7751
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG] Pow.pow silently wraps when the result exceeds long range","articleBody":"### Description\n\n`com.thealgorithms.maths.Pow.pow(int a, int b)` multiplies into a `long` without checking whether the result is representable. For example, `Pow.pow(2, 63)` mathematically equals 9223372036854775808, which is greater than `Long.MAX_VALUE`, but Java long overflow causes the method to return `Long.MIN_VALUE`. That is a plausible-looking but incorrect result for a utility documented as computing a power and returning a long.\n\n### Steps to reproduce\n\n1. Call `Pow.pow(2, 63)` (or `Pow.pow(2, 64)`).\n2. Observe the returned value: `Long.MIN_VALUE` for the first call, and `0` for the second, due to overflow wrapping.\n\n### Excepted behavior\n\nWhen the exact result cannot fit in a `long`, the method should detect overflow and report it (for example, by throwing `ArithmeticException`), or explicitly document wraparound as its intended behavior.\n\n### Screenshots\n\n_No response_\n\n### Additional context\n\n_No response_","author":{"url":"https://github.com/Prasad-Pitke","@type":"Person","name":"Prasad-Pitke"},"datePublished":"2026-11-12T03:33:31Z","url":"https://github.com/TheAlgorithms/Java/issues/7751"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:786ec493-4dbd-01fa-affa-4dcc6732aeb5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D820:2F9412:30379F:41111D:6AFA8A24 |
| html-safe-nonce | 2efff04bb541ed194eab048edc5702444e199826cc42049b088c713d792147b7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODIwOjJGOTQxMjozMDM3OUY6NDExMTFEOjZBRkE4QTI0IiwidmlzaXRvcl9pZCI6IjQ0ODc2MTU5MzQxNDMwNDAwMzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0fd9ac23eaea159783e14a1477f0b696bf99f31be96b0604b393efcb1f96a570 |
| hovercard-subject-tag | issue:6342160347 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TheAlgorithms/Java/7751/issue_layout |
| twitter:image | https://opengraph.githubassets.com/93aefae59004397e8eb6fafc5a8785629f9972fab180167ba0fd0dbd22d56ae1/TheAlgorithms/Java/issues/7751 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/93aefae59004397e8eb6fafc5a8785629f9972fab180167ba0fd0dbd22d56ae1/TheAlgorithms/Java/issues/7751 |
| og:image:alt | Description com.thealgorithms.maths.Pow.pow(int a, int b) multiplies into a long without checking whether the result is representable. For example, Pow.pow(2, 63) mathematically equals 922337203685... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Prasad-Pitke |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-preview |
| go-import | github.com/TheAlgorithms/Java git https://github.com/TheAlgorithms/Java.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 63477660 |
| octolytics-dimension-repository_nwo | TheAlgorithms/Java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63477660 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/Java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width