Is the feature request related to a problem
Code targeting older frameworks such as netstandard2.0 cannot use System.Numerics.BitOperations.IsPow2. For example:
var indexMask = BitOperations.IsPow2((uint)capacity)
? capacity - 1
: -1;
The current Polyfill API list does not include BitOperations or IsPow2.
Microsoft documents these overloads:
bool IsPow2(int value)
bool IsPow2(uint value)
bool IsPow2(long value)
bool IsPow2(ulong value)
bool IsPow2(nint value)
bool IsPow2(nuint value)
https://learn.microsoft.com/dotnet/api/system.numerics.bitoperations.ispow2
Describe the solution
Add a conditionally compiled System.Numerics.BitOperations polyfill on targets where the type/API is absent, with matching overloads.
The implementation is self-contained bit arithmetic. Zero and negative signed values return false; positive values use the standard (value & (value - 1)) == 0 test.
Describe alternatives considered
Consumers can add a private helper, but then cross-target source cannot retain the BCL call shape.
A static extension member could preserve the call shape where BitOperations exists but lacks an overload. On targets such as netstandard2.0, the type itself appears absent, so defining the conditional static class may be necessary.
Additional context
This surfaced while evaluating a source-only library for netstandard2.0. The API has no runtime-state dependency and should be fully polyfillable.
Is the feature request related to a problem
Code targeting older frameworks such as
netstandard2.0cannot useSystem.Numerics.BitOperations.IsPow2. For example:The current Polyfill API list does not include
BitOperationsorIsPow2.Microsoft documents these overloads:
bool IsPow2(int value)bool IsPow2(uint value)bool IsPow2(long value)bool IsPow2(ulong value)bool IsPow2(nint value)bool IsPow2(nuint value)https://learn.microsoft.com/dotnet/api/system.numerics.bitoperations.ispow2
Describe the solution
Add a conditionally compiled
System.Numerics.BitOperationspolyfill on targets where the type/API is absent, with matching overloads.The implementation is self-contained bit arithmetic. Zero and negative signed values return
false; positive values use the standard(value & (value - 1)) == 0test.Describe alternatives considered
Consumers can add a private helper, but then cross-target source cannot retain the BCL call shape.
A static extension member could preserve the call shape where
BitOperationsexists but lacks an overload. On targets such asnetstandard2.0, the type itself appears absent, so defining the conditional static class may be necessary.Additional context
This surfaced while evaluating a source-only library for
netstandard2.0. The API has no runtime-state dependency and should be fully polyfillable.