Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upf32, f64 missing from_le, from_be, to_le, to_be, swap_bytes implementation #39742
Comments
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
There is also the issue of signaling NaN's. See more discussion on this in #39271. |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
This particular function would be unsafe for floats btw, arbitrary bit patterns might be signaling NaNs for floats. |
This comment has been minimized.
This comment has been minimized.
|
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. |
Mark-Simulacrum
added
the
T-libs
label
May 27, 2017
Mark-Simulacrum
added
the
C-feature-request
label
Jul 27, 2017
dtolnay
added
C-feature-accepted
and removed
C-feature-request
labels
Nov 18, 2017
This comment has been minimized.
This comment has been minimized.
|
This seems reasonable to me. I would consider a PR to add these. |
This comment has been minimized.
This comment has been minimized.
|
For |
This comment has been minimized.
This comment has been minimized.
|
I think it would be better to not store floating points of nonnative endian in |
This comment has been minimized.
This comment has been minimized.
|
Just to clarify my last comment, i'm talking about the implementation of |
Timmmm commentedFeb 11, 2017
For all the integer primitives there are functions for converting the endianness:
from_le,to_le,from_be,to_beandswap_bytes(they probably should be a trait but they aren't for whatever reason).The floating point types
f32andf64don't have these methods defined.