-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for #![feature(const_float_bits_conv)]
#72447
Comments
… r=RalfJung,oli-obk Const floating point bitcasts and classification Makes the `f32` and `f64` methods described in rust-lang#72447 and rust-lang#72505 unstably const. r? @RalfJung
…=RalfJung Const floating point bitcasts and classification Makes the `f32` and `f64` methods described in rust-lang#72447 and rust-lang#72505 unstably const. r? @RalfJung
Is there anyway to hard-code this without nightly? |
|
pub const NA_REAL: f64 = unsafe {
std::mem::transmute(u64::from_le_bytes([
0xa2, 0x07, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f,
]))
}; This works for me now. |
Does that issue need to be a blocker for this? The functions in question aren't doing arithmetic on floats, they're just casting bit representations. AIUI while float arithmetic might be nonportable, bit representations are well-specified, yes? |
Actually, I take that back after looking at #73288 . |
Is there any reason It might not seem useful to provide just
The 2nd is what I was poking around with, when I realized that I can't actually turn the result into a user-friendly |
per @burrbull in #57241 (comment) This allows routing around these using |
With rust-lang/rfcs#3514 having been accepted, I think this is unblocked. I am working on stabilizing |
Rollup merge of rust-lang#129555 - RalfJung:const_float_bits_conv, r=dtolnay stabilize const_float_bits_conv This stabilizes `const_float_bits_conv`, and thus fixes rust-lang#72447. With rust-lang#128596 having landed, this is entirely a libs-only question now. ```rust impl f32 { pub const fn to_bits(self) -> u32; pub const fn from_bits(v: u32) -> Self; pub const fn to_be_bytes(self) -> [u8; 4]; pub const fn to_le_bytes(self) -> [u8; 4] pub const fn to_ne_bytes(self) -> [u8; 4]; pub const fn from_be_bytes(bytes: [u8; 4]) -> Self; pub const fn from_le_bytes(bytes: [u8; 4]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self; } impl f64 { pub const fn to_bits(self) -> u64; pub const fn from_bits(v: u64) -> Self; pub const fn to_be_bytes(self) -> [u8; 8]; pub const fn to_le_bytes(self) -> [u8; 8] pub const fn to_ne_bytes(self) -> [u8; 8]; pub const fn from_be_bytes(bytes: [u8; 8]) -> Self; pub const fn from_le_bytes(bytes: [u8; 8]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self; } ```` Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
stabilize const_float_bits_conv This stabilizes `const_float_bits_conv`, and thus fixes rust-lang/rust#72447. With rust-lang/rust#128596 having landed, this is entirely a libs-only question now. ```rust impl f32 { pub const fn to_bits(self) -> u32; pub const fn from_bits(v: u32) -> Self; pub const fn to_be_bytes(self) -> [u8; 4]; pub const fn to_le_bytes(self) -> [u8; 4] pub const fn to_ne_bytes(self) -> [u8; 4]; pub const fn from_be_bytes(bytes: [u8; 4]) -> Self; pub const fn from_le_bytes(bytes: [u8; 4]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self; } impl f64 { pub const fn to_bits(self) -> u64; pub const fn from_bits(v: u64) -> Self; pub const fn to_be_bytes(self) -> [u8; 8]; pub const fn to_le_bytes(self) -> [u8; 8] pub const fn to_ne_bytes(self) -> [u8; 8]; pub const fn from_be_bytes(bytes: [u8; 8]) -> Self; pub const fn from_le_bytes(bytes: [u8; 8]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self; } ```` Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
stabilize const_float_bits_conv This stabilizes `const_float_bits_conv`, and thus fixes rust-lang/rust#72447. With rust-lang/rust#128596 having landed, this is entirely a libs-only question now. ```rust impl f32 { pub const fn to_bits(self) -> u32; pub const fn from_bits(v: u32) -> Self; pub const fn to_be_bytes(self) -> [u8; 4]; pub const fn to_le_bytes(self) -> [u8; 4] pub const fn to_ne_bytes(self) -> [u8; 4]; pub const fn from_be_bytes(bytes: [u8; 4]) -> Self; pub const fn from_le_bytes(bytes: [u8; 4]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self; } impl f64 { pub const fn to_bits(self) -> u64; pub const fn from_bits(v: u64) -> Self; pub const fn to_be_bytes(self) -> [u8; 8]; pub const fn to_le_bytes(self) -> [u8; 8] pub const fn to_ne_bytes(self) -> [u8; 8]; pub const fn from_be_bytes(bytes: [u8; 8]) -> Self; pub const fn from_le_bytes(bytes: [u8; 8]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self; } ```` Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
stabilize const_float_bits_conv This stabilizes `const_float_bits_conv`, and thus fixes rust-lang/rust#72447. With rust-lang/rust#128596 having landed, this is entirely a libs-only question now. ```rust impl f32 { pub const fn to_bits(self) -> u32; pub const fn from_bits(v: u32) -> Self; pub const fn to_be_bytes(self) -> [u8; 4]; pub const fn to_le_bytes(self) -> [u8; 4] pub const fn to_ne_bytes(self) -> [u8; 4]; pub const fn from_be_bytes(bytes: [u8; 4]) -> Self; pub const fn from_le_bytes(bytes: [u8; 4]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self; } impl f64 { pub const fn to_bits(self) -> u64; pub const fn from_bits(v: u64) -> Self; pub const fn to_be_bytes(self) -> [u8; 8]; pub const fn to_le_bytes(self) -> [u8; 8] pub const fn to_ne_bytes(self) -> [u8; 8]; pub const fn from_be_bytes(bytes: [u8; 8]) -> Self; pub const fn from_le_bytes(bytes: [u8; 8]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self; } ```` Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
Tracking issue for the
#![feature(const_float_bits_conv)]
feature gate, which makes the following methods onf32
andf64
const fn
:#![feature(float_bits_conv)]
to_bits
from_bits
#![feature(float_to_from_bytes)]
to_bytes_be
to_bytes_le
to_bytes_ne
from_bytes_be
from_bytes_le
from_bytes_ne
These require
transmute
within aconst fn
to stabilize, and–unlike the recently stabilized#![feature(const_int_conversion)]
–do not have a const-stable alternate implementation. Nevertheless, these may be useful for nightly users.Stabilization is blocked on #57241.
The text was updated successfully, but these errors were encountered: