Skip to content

Support Int128, UInt128, and Half conversions#27700

Open
infisble wants to merge 2 commits into
PowerShell:masterfrom
infisble:agent/add-int128-conversions
Open

Support Int128, UInt128, and Half conversions#27700
infisble wants to merge 2 commits into
PowerShell:masterfrom
infisble:agent/add-int128-conversions

Conversation

@infisble

@infisble infisble commented Jul 17, 2026

Copy link
Copy Markdown

PR Summary

PowerShell users can now use System.Int128, System.UInt128, and System.Half in the standard numeric conversion paths.

This change:

  • registers the three types in the numeric conversion cache;
  • uses checked numeric operators when a type does not implement IConvertible;
  • preserves PowerShell's midpoint rounding behavior for real-to-integer conversions;
  • supports invariant string parsing, including thousands separators;
  • handles string, numeric, boolean, null, character, and formatting conversions consistently.

PR Context

Int128, UInt128, and Half do not implement IConvertible, so adding them to the existing type arrays alone would still leave Convert.ChangeType paths failing. The operator-based converter handles those types while keeping overflow checks and the existing conversion ranks.

Fix #25372

Validation:

  • Start-PSBuild -Clean -PSModuleRestore -UseNuGetOrg
  • Targeted Pester run for LanguagePrimitive.Tests.ps1 and Conversions.Tests.ps1: 133 passed, 0 failed

PR Checklist

Add Int128, UInt128, and Half to the built-in numeric conversion cache. Use checked numeric operators for types that do not implement IConvertible and keep PowerShell's rounding behavior for real-to-integer conversions.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@infisble
infisble marked this pull request as ready for review July 17, 2026 23:40
@infisble
infisble requested a review from a team as a code owner July 17, 2026 23:40
Copilot AI review requested due to automatic review settings July 17, 2026 23:40
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends PowerShell’s numeric conversion infrastructure to support System.Int128, System.UInt128, and System.Half across standard conversion paths (including invariant-culture parsing and rounding semantics), addressing #25372.

Changes:

  • Registers Int128, UInt128, and Half in the numeric type caches and conversion rank logic.
  • Adds operator-based numeric conversion paths (favoring checked operators) for types that don’t implement IConvertible, while preserving midpoint rounding behavior for real→integer conversions.
  • Adds/extends Pester coverage for boolean/null conversions and invariant string parsing (including thousands separators) for the new numeric types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/System.Management.Automation/engine/LanguagePrimitives.cs Adds the new numeric types to conversion caches and implements operator-based numeric conversions with rounding/invariant parsing support.
test/powershell/Language/Parser/Conversions.Tests.ps1 Extends casting tests for bool/null and adds numeric→bool cases for Int128, UInt128, and Half.
test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 Adds API-level tests for invariant string parsing and conversion behavior/overflow for Int128, UInt128, and Half.

Comment thread src/System.Management.Automation/engine/LanguagePrimitives.cs
@infisble

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Fall back to the existing Convert.ChangeType-based numeric converter when no checked or regular conversion operator is available. Add a regression test for the fallback selection.
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.

Add [int128] and [uint128] to the list of types PowerShell recognizes as integer types, so as to support the usual from-string conversions

2 participants