Title: Math.Min overload resolution narrows Int64/UInt64 to Int32 depending on argument order · Issue #28377 · PowerShell/PowerShell · GitHub
Open Graph Title: Math.Min overload resolution narrows Int64/UInt64 to Int32 depending on argument order · Issue #28377 · PowerShell/PowerShell
X Title: Math.Min overload resolution narrows Int64/UInt64 to Int32 depending on argument order · Issue #28377 · PowerShell/PowerShell
Description: AI disclosure: GPT 6.1 Sol detected and reproduced this behavior and prepared this report with the user's authorization. If maintainers consider this report AI slop, please feel free to close or delete this issue. Prerequisites Write a d...
Open Graph Description: AI disclosure: GPT 6.1 Sol detected and reproduced this behavior and prepared this report with the user's authorization. If maintainers consider this report AI slop, please feel free to close or de...
X Description: AI disclosure: GPT 6.1 Sol detected and reproduced this behavior and prepared this report with the user's authorization. If maintainers consider this report AI slop, please feel free to close o...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/28377
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Math.Min overload resolution narrows Int64/UInt64 to Int32 depending on argument order","articleBody":"> **AI disclosure:** GPT 6.1 Sol detected and reproduced this behavior and prepared this report with the user's authorization. If maintainers consider this report AI slop, please feel free to close or delete this issue.\n\n### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nReproduced on the latest stable release, PowerShell 7.6.9, using the official Windows x64 portable archive with `-NoProfile -NonInteractive` (.NET 10.0.14). This first appeared in a bounded-buffer calculation with a 64-bit remaining byte count, but the reproducer performs only numeric operations.\n\nEvaluate each expression independently:\n\n```powershell\n# Both of these attempt to convert the second operand to Int32 and fail:\n[Math]::Min([int]4194304, [long]30784094208)\n[Math]::Min([int]4194304, [UInt64]30784094208)\n\n# Reversing the operands succeeds:\n[Math]::Min([long]30784094208, [int]4194304)\n[Math]::Min([UInt64]30784094208, [int]4194304)\n\n# Explicitly matching operand types also succeeds:\n[Math]::Min([long]4194304, [long]30784094208)\n[Math]::Min([UInt64]4194304, [UInt64]30784094208)\n\n# Boundary: the first succeeds; the second fails although both minima are 4194304:\n[Math]::Min([int]4194304, [UInt64]2147483647)\n[Math]::Min([int]4194304, [UInt64]2147483648)\n```\n\nThe signed Int32/Int64 case has a lossless Int64 overload available for both operands. The report concerns PowerShell's method overload selection, not the calculation within .NET Math.Min.\n\nI am not claiming a new regression or proposing an unreviewed breaking change to numeric conversion rules. If this is intentional binding precedence, please classify accordingly and clarify whether an enhancement or more specific documentation is appropriate. I have read the existing guidance recommending exact argument types. A similar historical downstream report is [MVKozlov/GMGoogleDrive#1](https://github.com/MVKozlov/GMGoogleDrive/issues/1).\n\n### Expected behavior\n\n```console\nEach mixed-type call should return 4194304 using a suitable 64-bit overload, or consistently report ambiguity. In particular, the Int32/Int64 pair has a lossless common Int64 overload. Reversing the operands should not turn a successful minimum calculation into an overflow.\n```\n\n### Actual behavior\n\n```console\nPowerShell 7.6.9 results:\n\nInt32, Int64 -> MethodArgumentConversionInvalidCastArgument (val2 -> System.Int32)\nInt64, Int32 -> 4194304 (System.Int64)\nInt32, UInt64 -> MethodArgumentConversionInvalidCastArgument (val2 -> System.Int32)\nUInt64, Int32 -> 4194304 (System.UInt64)\nInt64, Int64 -> 4194304 (System.Int64)\nUInt64, UInt64 -> 4194304 (System.UInt64)\nInt32, UInt64(Int32.MaxValue) -> 4194304 (System.Int32)\nInt32, UInt64(Int32.MaxValue + 1) -> MethodArgumentConversionInvalidCastArgument\n\nError message:\nCannot convert argument \"val2\", with value: \"30784094208\", for \"Min\" to type \"System.Int32\": \"Cannot convert value \"30784094208\" to type \"System.Int32\". Error: \"Value was either too large or too small for an Int32.\"\"\n```\n\n### Error details\n\n```console\nExcerpt from Get-Error for [math]::Min([int]4194304, [UInt64]30784094208):\n\nType : System.Management.Automation.MethodException\nFullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument\nInnerException : System.Management.Automation.PSInvalidCastException\nInnerException : System.OverflowException\nMessage : Value was either too large or too small for an Int32.\n\nStackTrace :\n at System.Convert.ThrowInt32OverflowException()\n at System.Convert.ToInt32(UInt64 value)\n at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)\n at System.Management.Automation.LanguagePrimitives.ConvertNumeric(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)\n at CallSite.Target(Closure, CallSite, Type, Int32, UInt64)\n```\n\n### Environment data\n\n```powershell\nName Value\n---- -----\nPSVersion 7.6.9\nPSEdition Core\nGitCommitId 7.6.9\nOS Microsoft Windows 10.0.26300\nPlatform Win32NT\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\nPSRemotingProtocolVersion 2.4\nSerializationVersion 1.1.0.1\nWSManStackVersion 3.0\n```\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/Yihang-Chen-math","@type":"Person","name":"Yihang-Chen-math"},"datePublished":"2026-11-07T08:09:52Z","url":"https://github.com/PowerShell/PowerShell/issues/28377"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:587a213b-dae2-ea21-5866-8b6e06b95aad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99FC:2CFBF7:223E987:2FBF8FA:6AFD3205 |
| html-safe-nonce | 9093d93489f7ae3ec10ba03cfc763b4541c4e6a59be69946758ba16a9cded94d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUZDOjJDRkJGNzoyMjNFOTg3OjJGQkY4RkE6NkFGRDMyMDUiLCJ2aXNpdG9yX2lkIjoiMTQzNjg5NjE1ODM3MzcyMDU4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 08366f146fa5e886d59a4f1dc44b87dc3785087eb5344c5a55f0e765684fb324 |
| hovercard-subject-tag | issue:6256804897 |
| 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/PowerShell/PowerShell/28377/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd777d43d847e984f32ce24ec3bb92682134b89d91e0d70b1688cdd30a8a2e08/PowerShell/PowerShell/issues/28377 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd777d43d847e984f32ce24ec3bb92682134b89d91e0d70b1688cdd30a8a2e08/PowerShell/PowerShell/issues/28377 |
| og:image:alt | AI disclosure: GPT 6.1 Sol detected and reproduced this behavior and prepared this report with the user's authorization. If maintainers consider this report AI slop, please feel free to close or de... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Yihang-Chen-math |
| hostname | github.com |
| expected-hostname | github.com |
| None | 065128366c233a9d57ff68ab6c96e25b99dd1b0ab70d23b70873d3dd6b5e4f19 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| 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 | 941021edf0c2ec58298f4a2c8f27ae507d129c92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width