Skip to content

Commit 3cd450e

Browse files
Add #![feature(const_float_bits_conv)] for f64::to_bits and friends
1 parent 527a685 commit 3cd450e

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#![feature(const_discriminant)]
7474
#![feature(const_checked_int_methods)]
7575
#![feature(const_euclidean_int_methods)]
76+
#![feature(const_float_bits_conv)]
7677
#![feature(const_overflowing_int_methods)]
7778
#![feature(const_int_unchecked_arith)]
7879
#![feature(const_int_pow)]

library/core/src/num/f32.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,9 @@ impl f32 {
652652
///
653653
/// ```
654654
#[stable(feature = "float_bits_conv", since = "1.20.0")]
655+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
655656
#[inline]
656-
pub fn to_bits(self) -> u32 {
657+
pub const fn to_bits(self) -> u32 {
657658
// SAFETY: `u32` is a plain old datatype so we can always transmute to it
658659
unsafe { mem::transmute(self) }
659660
}
@@ -695,8 +696,9 @@ impl f32 {
695696
/// assert_eq!(v, 12.5);
696697
/// ```
697698
#[stable(feature = "float_bits_conv", since = "1.20.0")]
699+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
698700
#[inline]
699-
pub fn from_bits(v: u32) -> Self {
701+
pub const fn from_bits(v: u32) -> Self {
700702
// SAFETY: `u32` is a plain old datatype so we can always transmute from it
701703
// It turns out the safety issues with sNaN were overblown! Hooray!
702704
unsafe { mem::transmute(v) }
@@ -712,8 +714,9 @@ impl f32 {
712714
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
713715
/// ```
714716
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
717+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
715718
#[inline]
716-
pub fn to_be_bytes(self) -> [u8; 4] {
719+
pub const fn to_be_bytes(self) -> [u8; 4] {
717720
self.to_bits().to_be_bytes()
718721
}
719722

@@ -727,8 +730,9 @@ impl f32 {
727730
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
728731
/// ```
729732
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
733+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
730734
#[inline]
731-
pub fn to_le_bytes(self) -> [u8; 4] {
735+
pub const fn to_le_bytes(self) -> [u8; 4] {
732736
self.to_bits().to_le_bytes()
733737
}
734738

@@ -755,8 +759,9 @@ impl f32 {
755759
/// );
756760
/// ```
757761
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
762+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
758763
#[inline]
759-
pub fn to_ne_bytes(self) -> [u8; 4] {
764+
pub const fn to_ne_bytes(self) -> [u8; 4] {
760765
self.to_bits().to_ne_bytes()
761766
}
762767

@@ -769,8 +774,9 @@ impl f32 {
769774
/// assert_eq!(value, 12.5);
770775
/// ```
771776
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
777+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
772778
#[inline]
773-
pub fn from_be_bytes(bytes: [u8; 4]) -> Self {
779+
pub const fn from_be_bytes(bytes: [u8; 4]) -> Self {
774780
Self::from_bits(u32::from_be_bytes(bytes))
775781
}
776782

@@ -783,8 +789,9 @@ impl f32 {
783789
/// assert_eq!(value, 12.5);
784790
/// ```
785791
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
792+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
786793
#[inline]
787-
pub fn from_le_bytes(bytes: [u8; 4]) -> Self {
794+
pub const fn from_le_bytes(bytes: [u8; 4]) -> Self {
788795
Self::from_bits(u32::from_le_bytes(bytes))
789796
}
790797

@@ -808,8 +815,9 @@ impl f32 {
808815
/// assert_eq!(value, 12.5);
809816
/// ```
810817
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
818+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
811819
#[inline]
812-
pub fn from_ne_bytes(bytes: [u8; 4]) -> Self {
820+
pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self {
813821
Self::from_bits(u32::from_ne_bytes(bytes))
814822
}
815823

library/core/src/num/f64.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,9 @@ impl f64 {
666666
///
667667
/// ```
668668
#[stable(feature = "float_bits_conv", since = "1.20.0")]
669+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
669670
#[inline]
670-
pub fn to_bits(self) -> u64 {
671+
pub const fn to_bits(self) -> u64 {
671672
// SAFETY: `u64` is a plain old datatype so we can always transmute to it
672673
unsafe { mem::transmute(self) }
673674
}
@@ -709,8 +710,9 @@ impl f64 {
709710
/// assert_eq!(v, 12.5);
710711
/// ```
711712
#[stable(feature = "float_bits_conv", since = "1.20.0")]
713+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
712714
#[inline]
713-
pub fn from_bits(v: u64) -> Self {
715+
pub const fn from_bits(v: u64) -> Self {
714716
// SAFETY: `u64` is a plain old datatype so we can always transmute from it
715717
// It turns out the safety issues with sNaN were overblown! Hooray!
716718
unsafe { mem::transmute(v) }
@@ -726,8 +728,9 @@ impl f64 {
726728
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
727729
/// ```
728730
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
731+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
729732
#[inline]
730-
pub fn to_be_bytes(self) -> [u8; 8] {
733+
pub const fn to_be_bytes(self) -> [u8; 8] {
731734
self.to_bits().to_be_bytes()
732735
}
733736

@@ -741,8 +744,9 @@ impl f64 {
741744
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
742745
/// ```
743746
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
747+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
744748
#[inline]
745-
pub fn to_le_bytes(self) -> [u8; 8] {
749+
pub const fn to_le_bytes(self) -> [u8; 8] {
746750
self.to_bits().to_le_bytes()
747751
}
748752

@@ -769,8 +773,9 @@ impl f64 {
769773
/// );
770774
/// ```
771775
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
776+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
772777
#[inline]
773-
pub fn to_ne_bytes(self) -> [u8; 8] {
778+
pub const fn to_ne_bytes(self) -> [u8; 8] {
774779
self.to_bits().to_ne_bytes()
775780
}
776781

@@ -783,8 +788,9 @@ impl f64 {
783788
/// assert_eq!(value, 12.5);
784789
/// ```
785790
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
791+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
786792
#[inline]
787-
pub fn from_be_bytes(bytes: [u8; 8]) -> Self {
793+
pub const fn from_be_bytes(bytes: [u8; 8]) -> Self {
788794
Self::from_bits(u64::from_be_bytes(bytes))
789795
}
790796

@@ -797,8 +803,9 @@ impl f64 {
797803
/// assert_eq!(value, 12.5);
798804
/// ```
799805
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
806+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
800807
#[inline]
801-
pub fn from_le_bytes(bytes: [u8; 8]) -> Self {
808+
pub const fn from_le_bytes(bytes: [u8; 8]) -> Self {
802809
Self::from_bits(u64::from_le_bytes(bytes))
803810
}
804811

@@ -822,8 +829,9 @@ impl f64 {
822829
/// assert_eq!(value, 12.5);
823830
/// ```
824831
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
832+
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
825833
#[inline]
826-
pub fn from_ne_bytes(bytes: [u8; 8]) -> Self {
834+
pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self {
827835
Self::from_bits(u64::from_ne_bytes(bytes))
828836
}
829837

0 commit comments

Comments
 (0)