-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsThis resolves #98285
|
@@ -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)); |
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.
Log2 throws for negative integer values, so we need to explicitly check "is negative"
if (TSelf.IsNaN(value)) | ||
{ | ||
ThrowHelper.ThrowArithmeticException(SR.Arithmetic_NaN); | ||
} |
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.
Sign is supposed to throw for NaN (unlike CopySign which does not). It's a historical behavior/contract of the API.
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/DimTests.GenericMath.cs
Outdated
Show resolved
Hide resolved
Rerunning CI before merge. |
This resolves #98285