@@ -489,6 +489,15 @@ impl f64 {
489489 #[ stable( feature = "assoc_int_consts" , since = "1.43.0" ) ]
490490 pub const NEG_INFINITY : f64 = -1.0_f64 / 0.0_f64 ;
491491
492+ /// Sign bit
493+ pub ( crate ) const SIGN_MASK : u64 = 0x8000_0000_0000_0000 ;
494+
495+ /// Exponent mask
496+ pub ( crate ) const EXP_MASK : u64 = 0x7ff0_0000_0000_0000 ;
497+
498+ /// Mantissa mask
499+ pub ( crate ) const MAN_MASK : u64 = 0x000f_ffff_ffff_ffff ;
500+
492501 /// Returns `true` if this value is NaN.
493502 ///
494503 /// ```
@@ -514,9 +523,7 @@ impl f64 {
514523 #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
515524 pub ( crate ) const fn abs_private ( self ) -> f64 {
516525 // SAFETY: This transmutation is fine. Probably. For the reasons std is using it.
517- unsafe {
518- mem:: transmute :: < u64 , f64 > ( mem:: transmute :: < f64 , u64 > ( self ) & 0x7fff_ffff_ffff_ffff )
519- }
526+ unsafe { mem:: transmute :: < u64 , f64 > ( mem:: transmute :: < f64 , u64 > ( self ) & !Self :: SIGN_MASK ) }
520527 }
521528
522529 /// Returns `true` if this value is positive infinity or negative infinity, and
@@ -673,13 +680,10 @@ impl f64 {
673680 // and some normal floating point numbers truncated from an x87 FPU.
674681 #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
675682 const unsafe fn partial_classify ( self ) -> FpCategory {
676- const EXP_MASK : u64 = 0x7ff0000000000000 ;
677- const MAN_MASK : u64 = 0x000fffffffffffff ;
678-
679683 // SAFETY: The caller is not asking questions for which this will tell lies.
680684 let b = unsafe { mem:: transmute :: < f64 , u64 > ( self ) } ;
681- match ( b & MAN_MASK , b & EXP_MASK ) {
682- ( 0 , EXP_MASK ) => FpCategory :: Infinite ,
685+ match ( b & Self :: MAN_MASK , b & Self :: EXP_MASK ) {
686+ ( 0 , Self :: EXP_MASK ) => FpCategory :: Infinite ,
683687 ( 0 , 0 ) => FpCategory :: Zero ,
684688 ( _, 0 ) => FpCategory :: Subnormal ,
685689 _ => FpCategory :: Normal ,
@@ -691,12 +695,9 @@ impl f64 {
691695 // plus a transmute. We do not live in a just world, but we can make it more so.
692696 #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
693697 const fn classify_bits ( b : u64 ) -> FpCategory {
694- const EXP_MASK : u64 = 0x7ff0000000000000 ;
695- const MAN_MASK : u64 = 0x000fffffffffffff ;
696-
697- match ( b & MAN_MASK , b & EXP_MASK ) {
698- ( 0 , EXP_MASK ) => FpCategory :: Infinite ,
699- ( _, EXP_MASK ) => FpCategory :: Nan ,
698+ match ( b & Self :: MAN_MASK , b & Self :: EXP_MASK ) {
699+ ( 0 , Self :: EXP_MASK ) => FpCategory :: Infinite ,
700+ ( _, Self :: EXP_MASK ) => FpCategory :: Nan ,
700701 ( 0 , 0 ) => FpCategory :: Zero ,
701702 ( _, 0 ) => FpCategory :: Subnormal ,
702703 _ => FpCategory :: Normal ,
@@ -756,7 +757,7 @@ impl f64 {
756757 // IEEE754 says: isSignMinus(x) is true if and only if x has negative sign. isSignMinus
757758 // applies to zeros and NaNs as well.
758759 // SAFETY: This is just transmuting to get the sign bit, it's fine.
759- unsafe { mem:: transmute :: < f64 , u64 > ( self ) & 0x8000_0000_0000_0000 != 0 }
760+ unsafe { mem:: transmute :: < f64 , u64 > ( self ) & Self :: SIGN_MASK != 0 }
760761 }
761762
762763 #[ must_use]
@@ -800,14 +801,13 @@ impl f64 {
800801 // We must use strictly integer arithmetic to prevent denormals from
801802 // flushing to zero after an arithmetic operation on some platforms.
802803 const TINY_BITS : u64 = 0x1 ; // Smallest positive f64.
803- const CLEAR_SIGN_MASK : u64 = 0x7fff_ffff_ffff_ffff ;
804804
805805 let bits = self . to_bits ( ) ;
806806 if self . is_nan ( ) || bits == Self :: INFINITY . to_bits ( ) {
807807 return self ;
808808 }
809809
810- let abs = bits & CLEAR_SIGN_MASK ;
810+ let abs = bits & ! Self :: SIGN_MASK ;
811811 let next_bits = if abs == 0 {
812812 TINY_BITS
813813 } else if bits == abs {
@@ -850,14 +850,13 @@ impl f64 {
850850 // We must use strictly integer arithmetic to prevent denormals from
851851 // flushing to zero after an arithmetic operation on some platforms.
852852 const NEG_TINY_BITS : u64 = 0x8000_0000_0000_0001 ; // Smallest (in magnitude) negative f64.
853- const CLEAR_SIGN_MASK : u64 = 0x7fff_ffff_ffff_ffff ;
854853
855854 let bits = self . to_bits ( ) ;
856855 if self . is_nan ( ) || bits == Self :: NEG_INFINITY . to_bits ( ) {
857856 return self ;
858857 }
859858
860- let abs = bits & CLEAR_SIGN_MASK ;
859+ let abs = bits & ! Self :: SIGN_MASK ;
861860 let next_bits = if abs == 0 {
862861 NEG_TINY_BITS
863862 } else if bits == abs {
0 commit comments