Skip to content

Conversation

huoyaoyuan
Copy link
Member

Closes #119874.

Contains missing API in #119874 (comment). Please confirm whether it needs reiterating through API review.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 10, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 10, 2025
@huoyaoyuan huoyaoyuan added area-System.Numerics new-api-needs-documentation and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 10, 2025
Copy link
Contributor

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

public static BFloat16 ReadBFloat16BigEndian(ReadOnlySpan<byte> source)
{
return BitConverter.IsLittleEndian ?
BitConverter.Int16BitsToBFloat16(ReverseEndianness(MemoryMarshal.Read<short>(source))) :
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
BitConverter.Int16BitsToBFloat16(ReverseEndianness(MemoryMarshal.Read<short>(source))) :
BitConverter.UInt16BitsToBFloat16(ReverseEndianness(MemoryMarshal.Read<ushort>(source))) :

Should we using UInt16 everywhere to match the field type?

Copy link
Contributor

Choose a reason for hiding this comment

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

The current changes are at least consistent with ReadHalfLittleEndian, which is implemented with Int16 even though it's field is UInt16.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I just duplicated everything from Half.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Numerics community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Bit manipulation method for BFloat16

2 participants