Skip to content
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

Fix some generic math DIMs to have the correct behavior #98510

Merged
merged 8 commits into from
Mar 19, 2024

Conversation

tannergooding
Copy link
Member

This resolves #98285

@ghost
Copy link

ghost commented Feb 15, 2024

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

This resolves #98285

Author: tannergooding
Assignees: tannergooding
Labels:

area-System.Numerics

Milestone: -

@@ -37,7 +37,7 @@ static virtual TSelf LeadingZeroCount(TSelf value)
return TSelf.CreateChecked(bitCount);
}

return (bitCount - TSelf.One) ^ TSelf.Log2(value);
return TSelf.IsNegative(value) ? TSelf.Zero : ((bitCount - TSelf.One) ^ TSelf.Log2(value));
Copy link
Member Author

Choose a reason for hiding this comment

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

Log2 throws for negative integer values, so we need to explicitly check "is negative"

Comment on lines +168 to +171
if (TSelf.IsNaN(value))
{
ThrowHelper.ThrowArithmeticException(SR.Arithmetic_NaN);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Sign is supposed to throw for NaN (unlike CopySign which does not). It's a historical behavior/contract of the API.

@tannergooding
Copy link
Member Author

Rerunning CI before merge.

@tannergooding
Copy link
Member Author

Logged #99942 to track the seemingly untracked issue. It's failing in other unrelated PRs like #98293. The other failures look to be tracked.

@tannergooding tannergooding merged commit 6f31582 into dotnet:main Mar 19, 2024
146 of 150 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

INumber.Min(+QNaN, 1) returns 1
3 participants