Promote Int128/UInt128 arithmetic overflow to Double#27602
Open
KirtiRamchandani wants to merge 1 commit into
Open
Promote Int128/UInt128 arithmetic overflow to Double#27602KirtiRamchandani wants to merge 1 commit into
KirtiRamchandani wants to merge 1 commit into
Conversation
Route Int128 and UInt128 through the numeric operations pipeline with dedicated overflow handling, matching Int64 behavior instead of relying on native wrapping operators. Fixes PowerShell#26677
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Int128/UInt128 support to PowerShell numeric type handling and binary operator binding, including overflow behavior (promotion to Double) and targeted tests.
Changes:
- Introduces
Int128Ops/UInt128Opsimplementations for arithmetic and comparisons. - Updates numeric type classification/helpers and type lists to include
Int128/UInt128. - Adds Pester tests validating overflow promotion to
Double(and non-overflow preservation forInt128).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| test/powershell/Language/Operators/ArithmeticOperators.Tests.ps1 | Adds tests for overflow promotion behavior for 64/128-bit integer arithmetic. |
| src/System.Management.Automation/utils/ExtensionMethods.cs | Extends numeric-type helpers to treat Int128/UInt128 as numeric/integer. |
| src/System.Management.Automation/engine/runtime/Operations/NumericOps.cs | Adds operator implementations for Int128 and UInt128. |
| src/System.Management.Automation/engine/runtime/Binding/Binders.cs | Routes binary numeric ops to the new 128-bit operator implementations. |
| src/System.Management.Automation/engine/LanguagePrimitives.cs | Includes Int128/UInt128 in numeric/integer type arrays used in conversions. |
Comment on lines
+2447
to
+2456
| else if (target.LimitType.IsInt128Type() || arg.LimitType.IsInt128Type()) | ||
| { | ||
| opImplType = typeof(Int128Ops); | ||
| argType = typeof(Int128); | ||
| } | ||
| else if (target.LimitType.IsUInt128Type() || arg.LimitType.IsUInt128Type()) | ||
| { | ||
| opImplType = typeof(UInt128Ops); | ||
| argType = typeof(UInt128); | ||
| } |
Comment on lines
+399
to
+408
| internal static object Add(Int128 lhs, Int128 rhs) | ||
| { | ||
| System.Numerics.BigInteger biResult = (System.Numerics.BigInteger)lhs + (System.Numerics.BigInteger)rhs; | ||
| if (biResult >= Int128.MinValue && biResult <= Int128.MaxValue) | ||
| { | ||
| return (Int128)biResult; | ||
| } | ||
|
|
||
| return (double)biResult; | ||
| } |
Comment on lines
+397
to
+400
| internal static class Int128Ops | ||
| { | ||
| internal static object Add(Int128 lhs, Int128 rhs) | ||
| { |
| return (double)biResult; | ||
| } | ||
|
|
||
| internal static object Sub(Int128 lhs, Int128 rhs) |
| return (double)biResult; | ||
| } | ||
|
|
||
| internal static object Multiply(Int128 lhs, Int128 rhs) |
| return (double)biResult; | ||
| } | ||
|
|
||
| internal static object Divide(Int128 lhs, Int128 rhs) |
| return (double)lhs / (double)rhs; | ||
| } | ||
|
|
||
| internal static object Remainder(Int128 lhs, Int128 rhs) |
| return lhs % rhs; | ||
| } | ||
|
|
||
| internal static object CompareEq(Int128 lhs, Int128 rhs) { return (lhs == rhs) ? Boxed.True : Boxed.False; } |
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Describe "Arithmetic overflow promotion" -Tags "CI","RequireAdminOnWindows" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
[Int128]and[UInt128]arithmetic overflow silently wrapping instead of promoting to[double]like[Int64].Problem
Fix
Int128/UInt128as numeric typesInt128Ops/UInt128Opswith BigInteger overflow detectionArithmeticOperators.Tests.ps1Fixes #26677