-
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
Consider adding HalfToInt16Bits and Int16BitsToHalf to BitConverter #38288
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @tannergooding |
This isn't critical for .NET 5 so marking as future. This just provides parity with the equivalents exposed for Single/Double. |
For CBOR requirements we'd probably also need to add the following methods to the public static class BinaryPrimitives
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Half ReadHalfLittleEndian(ReadOnlySpan<byte> source);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Half ReadHalfBigEndian(ReadOnlySpan<byte> source);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryReadHalfLittleEndian(ReadOnlySpan<byte> source, out Half);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryReadHalfBigEndian(ReadOnlySpan<byte> source, out Half);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteHalfLittleEndian(Span<byte> destination, Half value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteHalfBigEndian(Span<byte> destination, Half value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteHalfLittleEndian(Span<byte> destination, Half value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteHalfBigEndian(Span<byte> destination, Half value);
} I feel that we could include these to the existing API proposal. If not I can file a separate issue. |
Given its a separate class, it would likely be good to have in a separate API proposal. The CBOR implementation wouldn't be blocked on these APIs being public, correct? That is, it can be implemented as an internal API until API review can happen, correct? |
That's correct |
Looks good namespace System
{
public sealed class BitConverter
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static short HalfToInt16Bits(Half value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Half Int16BitsToHalf(short value);
}
} |
For consistency, there are 4 more overloads for public static Half ToHalf(byte[] value, int startIndex);
public static Half ToHalf(ReadOnlySpan<byte> value);
public static byte[] GetBytes(Half value);
public static bool TryWriteBytes(Span<byte> destination, Half value); Do I need to create a new API proposal because this one is already approved? |
#37630 adds
HalfToInt16Bits
andInt16BitsToHalf
as internal methods to BitConverter. We should consider exposing them as public.Proposed API
cc: @tannergooding
The text was updated successfully, but these errors were encountered: