@@ -664,8 +664,9 @@ impl f64 {
664
664
///
665
665
/// ```
666
666
#[ stable( feature = "float_bits_conv" , since = "1.20.0" ) ]
667
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
667
668
#[ inline]
668
- pub fn to_bits ( self ) -> u64 {
669
+ pub const fn to_bits ( self ) -> u64 {
669
670
// SAFETY: `u64` is a plain old datatype so we can always transmute to it
670
671
unsafe { mem:: transmute ( self ) }
671
672
}
@@ -707,8 +708,9 @@ impl f64 {
707
708
/// assert_eq!(v, 12.5);
708
709
/// ```
709
710
#[ stable( feature = "float_bits_conv" , since = "1.20.0" ) ]
711
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
710
712
#[ inline]
711
- pub fn from_bits ( v : u64 ) -> Self {
713
+ pub const fn from_bits ( v : u64 ) -> Self {
712
714
// SAFETY: `u64` is a plain old datatype so we can always transmute from it
713
715
// It turns out the safety issues with sNaN were overblown! Hooray!
714
716
unsafe { mem:: transmute ( v) }
@@ -724,8 +726,9 @@ impl f64 {
724
726
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
725
727
/// ```
726
728
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
729
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
727
730
#[ inline]
728
- pub fn to_be_bytes ( self ) -> [ u8 ; 8 ] {
731
+ pub const fn to_be_bytes ( self ) -> [ u8 ; 8 ] {
729
732
self . to_bits ( ) . to_be_bytes ( )
730
733
}
731
734
@@ -739,8 +742,9 @@ impl f64 {
739
742
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
740
743
/// ```
741
744
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
745
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
742
746
#[ inline]
743
- pub fn to_le_bytes ( self ) -> [ u8 ; 8 ] {
747
+ pub const fn to_le_bytes ( self ) -> [ u8 ; 8 ] {
744
748
self . to_bits ( ) . to_le_bytes ( )
745
749
}
746
750
@@ -767,8 +771,9 @@ impl f64 {
767
771
/// );
768
772
/// ```
769
773
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
774
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
770
775
#[ inline]
771
- pub fn to_ne_bytes ( self ) -> [ u8 ; 8 ] {
776
+ pub const fn to_ne_bytes ( self ) -> [ u8 ; 8 ] {
772
777
self . to_bits ( ) . to_ne_bytes ( )
773
778
}
774
779
@@ -781,8 +786,9 @@ impl f64 {
781
786
/// assert_eq!(value, 12.5);
782
787
/// ```
783
788
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
789
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
784
790
#[ inline]
785
- pub fn from_be_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
791
+ pub const fn from_be_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
786
792
Self :: from_bits ( u64:: from_be_bytes ( bytes) )
787
793
}
788
794
@@ -795,8 +801,9 @@ impl f64 {
795
801
/// assert_eq!(value, 12.5);
796
802
/// ```
797
803
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
804
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
798
805
#[ inline]
799
- pub fn from_le_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
806
+ pub const fn from_le_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
800
807
Self :: from_bits ( u64:: from_le_bytes ( bytes) )
801
808
}
802
809
@@ -820,8 +827,9 @@ impl f64 {
820
827
/// assert_eq!(value, 12.5);
821
828
/// ```
822
829
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
830
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
823
831
#[ inline]
824
- pub fn from_ne_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
832
+ pub const fn from_ne_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
825
833
Self :: from_bits ( u64:: from_ne_bytes ( bytes) )
826
834
}
827
835
}
0 commit comments