Handle complex calculator results#47506
Open
MardSilva wants to merge 1 commit into
Open
Conversation
Return a friendly calculator error when Mages evaluates an expression to a complex number instead of letting decimal conversion throw. Fixes microsoft#43937
Contributor
|
Same here @MardSilva. Can you confirm a build/test? |
Author
|
I updated my local dev environment according to the dev docs and validated this PR locally. Validation passed:
|
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
daverayment
suggested changes
May 8, 2026
Collaborator
daverayment
left a comment
There was a problem hiding this comment.
The fix looks sound, but there's only a single test case at the moment. Although it tests the specific case referred to in the original issue, it would be useful to expand coverage to handle other cases and representations like sqrt(-4), (-1)^0.5 and log(-1).
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 of the Pull Request
Return a friendly calculator error when Mages evaluates an expression to a complex number instead of letting decimal conversion throw.
This fixes the PowerToys Run Calculator result for expressions such as
sqrt(-1)by detectingSystem.Numerics.Complexresults before decimal conversion and showing a localized error message instead.Fixes #43937
PR Checklist
Detailed Description of the Pull Request / Additional comments
The Calculator plugin previously passed complex results from Mages into
Convert.ToDecimal, which caused an exception for expressions likesqrt(-1).This PR updates the calculator result transformation logic to detect
System.Numerics.Complexand return a localized user-facing error message:Complex numbers are not supported.It also updates calculator query tests to cover both direct keyword and global query behavior.
Validation Steps Performed
=sqrt(-1)returningComplex numbers are not supported.sqrt(-1)returning no result instead of surfacing an unhandled exception.git diff --check.PlatformToolsetVersionresolves to an empty value during restore/build.