-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix Complex number custom formatting for negative imaginary parts #46897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
…matting issue Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot finished work on behalf of
gewarren
June 19, 2025 16:41
gewarren
approved these changes
Jun 19, 2025
...ndamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/Project.csproj
Outdated
Show resolved
Hide resolved
...undamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/customfmt1.cs
Outdated
Show resolved
Hide resolved
…rget framework Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot finished work on behalf of
gewarren
June 19, 2025 17:55
gewarren
reviewed
Jun 19, 2025
docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/Project.vbproj
Outdated
Show resolved
Hide resolved
...ndamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/Project.csproj
Outdated
Show resolved
Hide resolved
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
BillWagner
approved these changes
Jun 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM @gewarren
Let's
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.
The
ComplexFormatter
examples in the documentation were producing incorrect output when formatting complex numbers with negative imaginary parts. Instead of displaying12 - 15i
, they would show12 + -15i
.Problem
The custom formatter always used a hardcoded
" + "
operator between the real and imaginary parts:When
c1.Imaginary
was negative,ToString()
would include the negative sign, resulting in output like"12 + -15i"
instead of the expected"12 - 15i"
.Solution
Updated both C# and VB.NET versions to:
Math.Abs()
to get the absolute value of the imaginary partTest Results
12 + 15i
✅ (unchanged)12 - 15i
✅ (fixed from12 + -15i
)12 + 0i
✅ (unchanged)The fix applies to both 'I' and 'J' formatting cases and maintains backward compatibility for positive and zero imaginary parts.
Fixes #46422.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.