-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
f32, f64 missing from_le, from_be, to_le, to_be, swap_bytes implementation #39742
Comments
Can you explain why they should have those methods? Floating point types aren't a natural choice for bit twiddling. They don't even have more fundamental bit manipulation operations such as bitwise operators or shifts/rotates. The usual way to work with the bit representation of floats is to turn them into integers with the same number of bits, and manipulate that integer. |
There is also the issue of signaling NaN's. See more discussion on this in #39271. |
I'm wrapping libsoundio and that allows audio devices to support little and big endian floating point samples. These functions would be useful for converting between those. For example I have this in a macro, which works for all the integer types, but not floating point types:
See also wikipedia. Finally I feel like they should be there just for completeness. |
This particular function would be unsafe for floats btw, arbitrary bit patterns might be signaling NaNs for floats. |
I think we could have these, though it's not clear to me that we should. They'd certainly have to be unsafe, I think. |
This seems reasonable to me. I would consider a PR to add these. |
For |
I think it would be better to not store floating points of nonnative endian in |
Just to clarify my last comment, i'm talking about the implementation of |
Triage: no change |
@steveklabnik Since this issue was created, we have created alternative methods to convert floats from/to bytes in big/little endian: #60446. |
Yeay! |
For all the integer primitives there are functions for converting the endianness:
from_le
,to_le
,from_be
,to_be
andswap_bytes
(they probably should be a trait but they aren't for whatever reason).The floating point types
f32
andf64
don't have these methods defined.The text was updated successfully, but these errors were encountered: