You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The behavior when utilizing generic math to perform a shift on a T could differ based on the type. In some case it would appropriately mask the shift amount by sizeof(T) - 1 and in other cases it would do no masking. This meant that "overshifting" (such as shifting a byte by 8) could result in different answers being produced than expected.
New Behavior
The implementations were updated to mask the shift amount, as appropriate, to ensure consistent behavior across all built-in integer types and with the behavior documented by the IShiftOperators interface.
Reason for change
The behavior differed from the designed behavior due to a difference in how masking works for small integer types in C#.
Feature Area
Numerics
Affected APIs
operator <<, operator >>, and operator >>> for byte, char, sbyte, short, and ushort when used via Generic Math, which requires a T constrained to where T : IShiftOperators<T, int, T> or a similar interface.
The text was updated successfully, but these errors were encountered:
Description
Introduced with dotnet/runtime#103900
Version
.NET 10 Preview 1
Previous Behavior
The behavior when utilizing generic math to perform a shift on a
T
could differ based on the type. In some case it would appropriately mask the shift amount bysizeof(T) - 1
and in other cases it would do no masking. This meant that "overshifting" (such as shifting abyte
by 8) could result in different answers being produced than expected.New Behavior
The implementations were updated to mask the shift amount, as appropriate, to ensure consistent behavior across all built-in integer types and with the behavior documented by the
IShiftOperators
interface.Reason for change
The behavior differed from the designed behavior due to a difference in how masking works for small integer types in C#.
Feature Area
Numerics
Affected APIs
operator <<
,operator >>
, andoperator >>>
forbyte
,char
,sbyte
,short
, andushort
when used viaGeneric Math
, which requires aT
constrained towhere T : IShiftOperators<T, int, T>
or a similar interface.The text was updated successfully, but these errors were encountered: