@@ -380,16 +380,18 @@ impl f64 {
380380 /// assert!(!f.is_nan());
381381 /// ```
382382 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
383+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
383384 #[ inline]
384- pub fn is_nan ( self ) -> bool {
385+ pub const fn is_nan ( self ) -> bool {
385386 self != self
386387 }
387388
388389 // FIXME(#50145): `abs` is publicly unavailable in libcore due to
389390 // concerns about portability, so this implementation is for
390391 // private use internally.
391392 #[ inline]
392- fn abs_private ( self ) -> f64 {
393+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
394+ const fn abs_private ( self ) -> f64 {
393395 f64:: from_bits ( self . to_bits ( ) & 0x7fff_ffff_ffff_ffff )
394396 }
395397
@@ -409,8 +411,9 @@ impl f64 {
409411 /// assert!(neg_inf.is_infinite());
410412 /// ```
411413 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
414+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
412415 #[ inline]
413- pub fn is_infinite ( self ) -> bool {
416+ pub const fn is_infinite ( self ) -> bool {
414417 self . abs_private ( ) == Self :: INFINITY
415418 }
416419
@@ -429,8 +432,9 @@ impl f64 {
429432 /// assert!(!neg_inf.is_finite());
430433 /// ```
431434 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
435+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
432436 #[ inline]
433- pub fn is_finite ( self ) -> bool {
437+ pub const fn is_finite ( self ) -> bool {
434438 // There's no need to handle NaN separately: if self is NaN,
435439 // the comparison is not true, exactly as desired.
436440 self . abs_private ( ) < Self :: INFINITY
@@ -456,9 +460,10 @@ impl f64 {
456460 /// ```
457461 /// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
458462 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
463+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
459464 #[ inline]
460- pub fn is_normal ( self ) -> bool {
461- self . classify ( ) == FpCategory :: Normal
465+ pub const fn is_normal ( self ) -> bool {
466+ matches ! ( self . classify( ) , FpCategory :: Normal )
462467 }
463468
464469 /// Returns the floating point category of the number. If only one property
@@ -475,7 +480,8 @@ impl f64 {
475480 /// assert_eq!(inf.classify(), FpCategory::Infinite);
476481 /// ```
477482 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
478- pub fn classify ( self ) -> FpCategory {
483+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
484+ pub const fn classify ( self ) -> FpCategory {
479485 const EXP_MASK : u64 = 0x7ff0000000000000 ;
480486 const MAN_MASK : u64 = 0x000fffffffffffff ;
481487
@@ -500,8 +506,9 @@ impl f64 {
500506 /// assert!(!g.is_sign_positive());
501507 /// ```
502508 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
509+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
503510 #[ inline]
504- pub fn is_sign_positive ( self ) -> bool {
511+ pub const fn is_sign_positive ( self ) -> bool {
505512 !self . is_sign_negative ( )
506513 }
507514
@@ -524,8 +531,9 @@ impl f64 {
524531 /// assert!(g.is_sign_negative());
525532 /// ```
526533 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
534+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
527535 #[ inline]
528- pub fn is_sign_negative ( self ) -> bool {
536+ pub const fn is_sign_negative ( self ) -> bool {
529537 self . to_bits ( ) & 0x8000_0000_0000_0000 != 0
530538 }
531539
@@ -666,8 +674,9 @@ impl f64 {
666674 ///
667675 /// ```
668676 #[ stable( feature = "float_bits_conv" , since = "1.20.0" ) ]
677+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
669678 #[ inline]
670- pub fn to_bits ( self ) -> u64 {
679+ pub const fn to_bits ( self ) -> u64 {
671680 // SAFETY: `u64` is a plain old datatype so we can always transmute to it
672681 unsafe { mem:: transmute ( self ) }
673682 }
@@ -709,8 +718,9 @@ impl f64 {
709718 /// assert_eq!(v, 12.5);
710719 /// ```
711720 #[ stable( feature = "float_bits_conv" , since = "1.20.0" ) ]
721+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
712722 #[ inline]
713- pub fn from_bits ( v : u64 ) -> Self {
723+ pub const fn from_bits ( v : u64 ) -> Self {
714724 // SAFETY: `u64` is a plain old datatype so we can always transmute from it
715725 // It turns out the safety issues with sNaN were overblown! Hooray!
716726 unsafe { mem:: transmute ( v) }
@@ -726,8 +736,9 @@ impl f64 {
726736 /// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
727737 /// ```
728738 #[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
739+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
729740 #[ inline]
730- pub fn to_be_bytes ( self ) -> [ u8 ; 8 ] {
741+ pub const fn to_be_bytes ( self ) -> [ u8 ; 8 ] {
731742 self . to_bits ( ) . to_be_bytes ( )
732743 }
733744
@@ -741,8 +752,9 @@ impl f64 {
741752 /// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
742753 /// ```
743754 #[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
755+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
744756 #[ inline]
745- pub fn to_le_bytes ( self ) -> [ u8 ; 8 ] {
757+ pub const fn to_le_bytes ( self ) -> [ u8 ; 8 ] {
746758 self . to_bits ( ) . to_le_bytes ( )
747759 }
748760
@@ -769,8 +781,9 @@ impl f64 {
769781 /// );
770782 /// ```
771783 #[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
784+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
772785 #[ inline]
773- pub fn to_ne_bytes ( self ) -> [ u8 ; 8 ] {
786+ pub const fn to_ne_bytes ( self ) -> [ u8 ; 8 ] {
774787 self . to_bits ( ) . to_ne_bytes ( )
775788 }
776789
@@ -783,8 +796,9 @@ impl f64 {
783796 /// assert_eq!(value, 12.5);
784797 /// ```
785798 #[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
799+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
786800 #[ inline]
787- pub fn from_be_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
801+ pub const fn from_be_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
788802 Self :: from_bits ( u64:: from_be_bytes ( bytes) )
789803 }
790804
@@ -797,8 +811,9 @@ impl f64 {
797811 /// assert_eq!(value, 12.5);
798812 /// ```
799813 #[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
814+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
800815 #[ inline]
801- pub fn from_le_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
816+ pub const fn from_le_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
802817 Self :: from_bits ( u64:: from_le_bytes ( bytes) )
803818 }
804819
@@ -822,8 +837,9 @@ impl f64 {
822837 /// assert_eq!(value, 12.5);
823838 /// ```
824839 #[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
840+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
825841 #[ inline]
826- pub fn from_ne_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
842+ pub const fn from_ne_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
827843 Self :: from_bits ( u64:: from_ne_bytes ( bytes) )
828844 }
829845
0 commit comments